我正在尝试在 jenkins 管道中运行 terraform 脚本。"地形规划"命令显示错误
1m要求用户输入的错误:发生 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}'"
}
}
}
地形初始化工作正常,但地形计划出错。
+ 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
此脚本在没有詹金斯的 Vagrant VM 中工作正常
你使用的是哪个Terraform版本?
您是否尝试过这些参数:
- 地形初始化 -输入=假
- 地形图 -输入=假
- 地形应用 -输入=假 -自动批准