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

terraform plan -refresh-only -detailed-exitcode gives incorrect exit code 2 even if the console output says no changes detected #35117

Open
shaik262 opened this issue May 6, 2024 · 5 comments
Labels
bug new new issue not yet triaged waiting for reproduction unable to reproduce issue without further information waiting-response An issue/pull request is waiting for a response from the community

Comments

@shaik262
Copy link

shaik262 commented May 6, 2024

Terraform Version

v1.8.1

Terraform Configuration Files

...terraform config...

Debug Output

I tried to get the exit code displayed on console it gives 2 even if there are no changes detected as per terraform

Expected Behavior

It should return 0 as there are no changes present as per the console

Actual Behavior

terraform plan -refresh-only -detailed-exitcode gives incorrect exit code 2 even if the console output says no changes detected

Steps to Reproduce

we used this command as a part of ADO pipeline drift detection
$terraform plan -refresh-only -detailied-exitcode

Additional Context

image
Screenshot 2024-05-06 160231

References

No response

@shaik262 shaik262 added bug new new issue not yet triaged labels May 6, 2024
@jbardin
Copy link
Member

jbardin commented May 6, 2024

Hi @shaik262,

Thanks for filing the issue! I'm not able to replicate the result you are showing here, and seeing a 0 exit code for empty refresh plans. Can you show exactly how you are setting up and executing terraform to get this output?

Thanks!

@jbardin jbardin added waiting-response An issue/pull request is waiting for a response from the community waiting for reproduction unable to reproduce issue without further information labels May 6, 2024
@shaik262
Copy link
Author

shaik262 commented May 7, 2024

Hi @jbardin, thank you for looking into this issue.

We have an azure pipeline which has a drift detection in place (cronjob based) This schedule phase uses a command to check the drift and depending on the exit code it goes to review and apply stage. Here is the logic
We are using
The agent we are using to run this is ubuntu. Please convert the txt files to yml after downloading.
terraform.txt
azure-pipelines.txt

@jbardin
Copy link
Member

jbardin commented May 7, 2024

Thanks @shaik262. That unfortunately doesn't give me enough to reproduce the behavior. I think what we need is the plan data or Terraform configuration rather than the pipeline configuration.

Have you applied a plan to this configuration since upgrading to v1.8? See the release notes or upgrade guide about using -refresh-only after upgrading.

@shaik262
Copy link
Author

Hi @jbardin I went trough the link which you've sent and applied the planned changes, but again in the next schedule the pipeline is waiting in review and apply stage even though there are no changes being displayed by terraform plan. ( the detailed exit code is "2")

@shaik262
Copy link
Author

shaik262 commented May 23, 2024

Hello @jbardin. We have resolved this issue. The "terraform show -json tfplan" command for the file with resource changes outside of terraform is giving an output which has a property relevant_attributes, resource_drift and check along with other properties. But the file which has no changes, is also giving an output with the relevant_attribute andcheck. We changed our condition to look for just resources_drift in the output of terraform plan show for any changes as this property is generated in plan to let us know which external changes are causing this drift.

Issue : For some of the files with no changes, the same command is generating relevant_attributes also which lists the sources of all values contributing to changes in the plan.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug new new issue not yet triaged waiting for reproduction unable to reproduce issue without further information waiting-response An issue/pull request is waiting for a response from the community
Projects
None yet
Development

No branches or pull requests

2 participants