Terraform计划在詹金斯管道中出错

时间:2018-10-01 12:43:11

标签: jenkins terraform-provider-aws

我正在尝试在jenkins管道中运行Terraform脚本。 “ terraform plan”命令显示错误

  

1mError要求用户输入:发生1个错误:

     
      
  • provider.aws:插件在我们可以连接之前退出
  •   

terraform脚本包含vars.tf和iam.tf

iam.tf

provider "aws" {
access_key = "${var.access_key}"
secret_key = "${var.secret_key}"
region = "us-east-1"

}
resource "aws_iam_role" "replication" {
name = "tf-iam-role-replication-12349995"

assume_role_policy = <<POLICY
{
"Version": "2012-10-17",
"Statement": [
 {
 "Action": "sts:AssumeRole",
 "Principal": {
 "Service": "s3.amazonaws.com"
 },
 "Effect": "Allow",
 "Sid": ""
 }
 ]
 }
 POLICY
 }

vars.tf

variable "access_key" {}
variable "secret_key" {}

正在运行

steps {
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', 
accessKeyVariable: 'AWS_ACCESS_KEY_ID',
credentialsId: 'Source', 
secretKeyVariable: 'AWS_SECRET_ACCESS_KEY']]) {

sh "  sudo terraform init ; sudo terraform plan -var 'access_key=${AWS_ACCESS_KEY_ID}'  -var 'secret_key=${AWS_SECRET_ACCESS_KEY}'"
}
}
}

Terraform初始化工作正常,但是terraform计划给出了错误。

+ sudo terraform plan -var access_key=**** -var secret_key=****
[31m
[1m[31mError: [0m[0m[1mError asking for user input: 1 error(s) occurred:

* provider.aws: plugin exited before we could connect

该脚本在没有jenkins的Vagrant VM中运行正常

1 个答案:

答案 0 :(得分:0)

您正在使用哪个Terraform版本?

您是否尝试过这些参数:

  • terrain init -input = false
  • 地形计划-input = false
  • terraform apply -input = false -auto-approve