【问题标题】:expected: IDENT | STRING | ASSIGN | LBRACE got: LBRACK[0m[0m in terraform预期:标识 |字符串 |分配 | LBRACE 得到:LBRACK[0m[0m in terraform
【发布时间】:2018-03-16 20:59:30
【问题描述】:

作为 terraform 和 Jenkins 的新手,我正在尝试在 jenkins 上运行 terraform 脚本,但遇到了如下所示的奇怪问题:

查看修订版 59b7e707924169b66e3043a381ab63f6ccd0e2ae (refs/remotes/origin/master)

git config core.sparsecheckout # timeout=10 git checkout -f 59b7e707924169b66e3043a381ab63f6ccd0e2ae git rev-list 14cca48b44d7820f3f6ea8ed6d2a0728bc5e2176 # timeout=10 [FT_packer] $ /opt/software/terraform/0.9.5/terraform get [31mError 加载配置:解析错误 /opt/repository/jenkins/workspace/crspng-CCPDev-ccp-ft-tf/farm_vpc_02/FT_packer/vars.tf: 16:35:预计:IDENT |字符串 |分配 | LBRACE 得到: LBRACK [0m [0m FATAL:java.lang.Exception:Terraform Get failed:1 at org.jenkinsci.plugins.terraform.TerraformBuildWrapper.executeGet(TerraformBuildWrapper.java:224) 在 org.jenkinsci.plugins.terraform.TerraformBuildWrapper.setUp(TerraformBuildWrapper.java:256) 在 hudson.model.Build$BuildExecution.doRun(Build.java:156) 在 hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:534) 在 hudson.model.Run.execute(Run.java:1720) 在 hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43) 在 hudson.model.ResourceController.execute(ResourceController.java:98) 在 hudson.model.Executor.run(Executor.java:401)

已完成:失败

Main.tf 看起来像这样:

resource "aws_instance" "FT-packer-node" {
  ami                           = "${var.aws-region}"
  instance_type                 = "${var.instance-type}"
  vpc_security_group_ids        = "${var.vpc-security-group-ids}"
  key_name                      = "${var.key-name}"
  subnet_id                     = "${var.subnet-id}"
  associate_public_ip_address   = "${var.associate-public-ip-address}"
  availability_zone             = "eu-central-1a"
  private_ip                    = "${var.machine-private-ip}"
  tags {
    Name                        = "${var.machine-name-node}"
    Owner                       = "${var.team-name}"
  }

  timeouts {
    create                      = "${var.create-timeout}"
    delete                      = "${var.update-timeout}"
  }
}

在 vars.ft 中声明所有变量,如下所示:

variable "access_key" {}

variable "secret_key" {}

# ------------- MACHINE RELATED CONFIGS ------------- 

variable "vpc-name" {}

# Key file(pep/ppk) to be associated
variable "key-name" {}

# EC2 instance size
variable "instance-type" {}

# VPC Security group id to launch machine in
variable "vpc-security-group-ids" []

# Subnet of the VPC
variable "subnet-id" {}

variable "elb-name" {}
# --------------------------ENDS-----------------------------------------


# ------------------------ Optionals ----------------------------------------
# Below configs can be left unchanged. Change on need basis only.
# Team name
variable "team-name" {}

variable "machine-name-node" {}

variable "machine-private-ip" {}

variable "create-timeout" {}

variable "update-timeout" {}

variable "availability-zones" {}

variable "elb-access-log-bucket-name" {}

variable "elb-access-log-dir-name" {}


variable "is-internal-lb" {}

# Need a public IP ?
variable "associate-public-ip-address" {}

# Region
variable "aws-region" {}

上面文件第16行显示错误,即

变量“vpc-security-group-ids”[]

jenkins 中提到的实际资源变量是这样的:

【问题讨论】:

  • variable "vpc-security-group-ids" [] 应该是 variable "vpc-security-group-ids" {}。此外,您应该删除这些屏幕截图并将相关文本粘贴到代码块中,以便人们可以更轻松地解析和查看内容。
  • @ydaetskcoR ... 通过这个variable "vpc-security-group-ids" {} 更改我收到variable vpc-security-group-ids should be type string, got list 这个错误。我已将错误截图更新为错误文本。

标签: parsing jenkins continuous-integration terraform


【解决方案1】:

对于您的第二个问题,变量vpc_security_group_ids 的值似乎是一个列表。 (是的,我现在可以从屏幕截图中确认)

在下面进行更改

variable "vpc-security-group-ids" {
  type = "list"
}

resource "aws_instance" "FT-packer-node" {

  vpc_security_group_ids        = "${var.vpc-security-group-ids}"

}

在你运行terraform plan/apply之前,你应该先做一个验证

terraform validate -check-variables=false

这将有助于解决您的第一个问题

加载配置时出错:解析/opt/repository/jenkins/workspace/crspng-CCPDev-ccp-ft-tf/farm_vpc_02/FT_packer/vars.tf时出错:16:35:预计:标识 |字符串 |分配 | LBRACE 得到:LBRACK

【讨论】:

  • 按照您所说的vpc_security_group_ids = "${var.vpc-security-group-ids}" 进行更改。我遇到了与* variable vpc-security-group-ids should be type string, got list[0m[0m 相同的错误。也在本地运行 terraform validate 没有显示任何错误。
  • 如何输入${var.vpc-security-group-ids}的值
  • 我在詹金斯的Resource Variables (Optional)喂食。如上图所示。
  • 更新了答案,让我知道这是否解决了您的问题。
  • 解决了 Timeout Key 问题,将其从变量中删除,因为它不是必需的。 variable "vpc-security-group-ids" { type = "list" } 这帮助我摆脱了错误。谢谢!
猜你喜欢
  • 2021-03-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多