Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jlomba09 opened this issue Nov 1, 2024 · 3 comments
Assignees
Labels
awaiting response Waiting for a response or more data from issue reporter bug Something isn't working

Comments

@jlomba09
Copy link

jlomba09 commented Nov 1, 2024

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

  • Terragrunt version: v0.68.7
  • OpenTofu/Terraform version: Terraform 1.9.8
  • Environment details (Ubuntu 20.04, Windows 10, etc.): Ubuntu 20.04

Additional context

Add any other context about the problem here.

@jlomba09 jlomba09 added the bug Something isn't working label Nov 1, 2024
@jlomba09 jlomba09 changed the title terragrunt-non-interactive not anse terragrunt-non-interactive not answering yes to all prompts in Jenkins pipeline Nov 1, 2024
@denis256
Copy link
Member

denis256 commented Nov 1, 2024

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"
}

@denis256 denis256 added the awaiting response Waiting for a response or more data from issue reporter label Nov 1, 2024
@denis256 denis256 self-assigned this Nov 1, 2024
@jlomba09
Copy link
Author

jlomba09 commented Nov 1, 2024

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.

@yhakbar
Copy link
Collaborator

yhakbar commented Nov 22, 2024

Hey @jlomba09 ,

The flag as designed right now answers "yes" to all Terragrunt prompts. There's debate as to whether it should also answer "yes" to all OpenTofu/Terraform prompts.

We added this to our agenda for Office Hours next Wednesday. Feel free to attend if you'd like to join the discussion!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting response Waiting for a response or more data from issue reporter bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants