作为terraform和Jenkins的新手,我正在尝试在jenkins上运行terraform脚本,但面对这个奇怪的问题,如下所示:
查看修订版59b7e707924169b66e3043a381ab63f6ccd0e2ae (参考文献/遥控器/来源/主)
git config core.sparsecheckout #timeout = 10 git checkout -f 59b7e707924169b66e3043a381ab63f6ccd0e2ae git rev-list 14cca48b44d7820f3f6ea8ed6d2a0728bc5e2176 #timetime = 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 | STRING |分配| LBRACE得到了: LBRACK [0m [0m致命:java.lang.Exception:Terraform Get failed:1 at 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)at at hudson.model.AbstractBuild $ AbstractBuildExecution.run(AbstractBuild.java:534) 在hudson.model.Run.execute(Run.java:1720)at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)at at 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中提到了实际的资源变量:
答案 0 :(得分:2)
对于第二个问题,似乎变量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:预期: IDENT | STRING |分配| LBRACE得到了:LBRACK