gruntwork-io / terragrunt

Terragrunt is a flexible orchestration tool that allows Infrastructure as Code written in OpenTofu/Terraform to scale.
https://terragrunt.gruntwork.io/
MIT License
8.06k stars 980 forks source link

terragrunt-non-interactive not answering yes to all prompts in Jenkins pipeline #3528

Open jlomba09 opened 5 hours ago

jlomba09 commented 5 hours ago

Describe the bug

When running terragrunt init --terragrunt-non-interactive in a Jenkins pipeline, Terragrunt still asks for a yes/no confirmation:

"Do you want to copy existing state to the new backend?" Pre-existing state was found while migrating the previous local backend to newly configured "s3" backend. No existing state was found in the newly configured "s3" backend. Do you want to copy this state to the new "s3" backend? Enter "yes" to copy and "no" to start with an empty state.

Steps To Reproduce

Create a Jenkins pipeline with the following stage: stage("Initialize terraform") { steps { script { dir("terraform") { sh "terragrunt init --terragrunt-non-interactive" } } }

// paste code snippets here

remote_state { backend = "s3" generate = { path = "backend.tf" if_exists = "overwrite" } config = { bucket = "jenkins-ansible-demo-tf-state" key = "ansible/terraform.tfstate" region = "us-east-1" encrypt = true dynamodb_table = "jenkins-ansible-demo-lock-table" } }

Expected behavior

The terragrunt init --terragrunt-non-interactive command should answer yes to all prompts.

Nice to haves

image

Versions

Additional context

Add any other context about the problem here.

denis256 commented 4 hours ago

Hi, based on the log message, it looks like it is a message from terrafrom executable, can you confirm that are set env variables to flag that terraform is executed in automation:

TF_INPUT = "0"
TF_IN_AUTOMATION = "1"

# somewhere in Jenkins file
environment {
    TF_INPUT = "0"
    TF_IN_AUTOMATION = "1"
}
jlomba09 commented 4 hours ago

Hi @denis256 - thanks for the quick reply. Those environment variables are not set in the pipeline. I was able to work around this by using:

sh "echo 'yes' | terragrunt --terragrunt-non-interactive init"

image

It proceeds with the S3/DynamoDB creation but would be nice if the flag answers yes to all prompts as it's supposed to do.