Я пытаюсь создать конвейер Jenkins для развертывания Terraform в моем AWS env. Это мой Jenkinsfile в Bitbucket:
pipeline {
agent any
parameters {
string(name: 'WORKSPACE', defaultValue: 'dev', description:'workspace for terraform')
string(name: 'ACCESS_KEY', defaultValue: 'dummy-value', description:'AWS Access Key')
string(name: 'SECRET_KEY', defaultValue: 'dummy-value', description:'AWS Secret Key')
}
stages
{
stage('TerraformInit'){
steps {
sh "terraform init -input=false"
}
}
stage('Terraform workspace') {
steps {
script {
try {
sh "terraform workspace new ${params.WORKSPACE}"
} catch (err) {
sh "terraform workspace select ${params.WORKSPACE}"
}
}
}
stage('TerraformPlan'){
steps {
script {
sh "terraform plan -var 'access_key=${params.ACCESS_KEY}' -var 'secret_key=${params.SECRET_KEY}' -out terraform.tfplan;echo \$? > status"
stash name: "terraform-plan", includes: "terraform.tfplan"
}
}
}
stage('TerraformApply'){
steps {
script{
unstash "terraform-plan"
sh 'terraform apply terraform.tfplan'
}
}
}
}
post {
always {
cleanWs()
}
}
}
Это мой main.tf:
terraform {
required_version = ">= 0.12"
backend "consul" {
address = "consul.corp.dom:8500"
path = "aws/project/error-jenkins"
}
}
provider "aws" {
region = var.environment_values[local.environment]["region"]
}
locals {
environment = terraform.workspace
}
resource "aws_sns_topic" "Error-SNS" {
name = "Error-SNS"
}
, а это моя переменная. Tf:
variable "environment_values" {
default = {
dev= {
region="us-west-1"
}
test= {
region="us-west-1"
}
prod= {
region="us-west-1"
}
}
}
Все находятся в том же месте в BituBucket. Но когда я запускаю работу Дженкинса, получаю эту ошибку на этапе «terraform plan»:
terraform plan -var access_key=dummyalue -var secret_key=dummyalue -out terraform.tfplan
Error: Value for undeclared variable
A variable named "access_key" was assigned on the command line, but the root
module does not declare a variable of that name. To use this value, add a
"variable" block to the configuration.
Error: Value for undeclared variable
A variable named "secret_key" was assigned on the command line, but the root
module does not declare a variable of that name. To use this value, add a
"variable" block to the configuration.
script returned exit code 1
Кто-то, пожалуйста, направьте меня.