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

set TF_IN_AUTOMATION env var for terraform commands #516

Merged
merged 2 commits into from
Jan 18, 2024

Conversation

mcalhoun
Copy link
Member

what

Set the TF_IN_AUTOMATION env var

why

If set, Terraform adjusts its output to avoid suggesting specific commands to run next. This can make the output more consistent and less confusing in workflows where users don't directly execute Terraform commands, like in CI systems or other wrapping applications such as atmos.

references

https://developer.hashicorp.com/terraform/cli/config/environment-variables#tf_in_automation

@mcalhoun mcalhoun requested review from a team as code owners January 17, 2024 23:16
Copy link
Member

@osterman osterman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We deliberately didn't do this because it drops all color formatting. IMO the CI flags are a bit dated because all modern CI systems work with full terminal support (e.g. ansi color)

@osterman
Copy link
Member

osterman commented Jan 18, 2024

If we do this, we should do it only when output is not needed by the end user.

@osterman osterman requested review from aknysh and a team and removed request for dotCipher and joe-niland January 18, 2024 02:05
@mcalhoun
Copy link
Member Author

mcalhoun commented Jan 18, 2024

@osterman I think you have misunderstood this flag, the color formatting still happens, it just drops the verbose instructions.

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.

In both cases below, color output is displayed, the only difference is the verbose instructions, which the docs also indicate:

If TF_IN_AUTOMATION is set to any non-empty value, Terraform adjusts its output to avoid suggesting specific commands to run next. This can make the output more consistent and less confusing in workflows where users don't directly execute Terraform commands, like in CI systems or other wrapping applications.

$ TF_IN_AUTOMATION=true atmos terraform plan terraform-no-error -s test-test-test

Initializing the backend...

Initializing provider plugins...

Terraform has been successfully initialized!

Changes to Outputs:

  • test = "Hello, World"

You can apply this plan to save these new output values to the Terraform state, without changing any real infrastructure.

$ atmos terraform plan terraform-no-error -s test-test-test

Initializing the backend...

Initializing provider plugins...

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.

Changes to Outputs:

  • test = "Hello, World"

You can apply this plan to save these new output values to the Terraform state, without changing any real infrastructure.

@osterman osterman merged commit 20c08c3 into master Jan 18, 2024
6 checks passed
@osterman osterman deleted the feature/set-TF_IN_AUTOMATION branch January 18, 2024 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants