-
Notifications
You must be signed in to change notification settings - Fork 9.9k
Drift detection " terraform plan --refresh-only --detailed-exitcode " exits with 2, even when there are no changes. #36403
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
Comments
Hi @stehubhex, The azurerm provider has many legacy resources which create a lot of incorrect drift in plans, and I wonder if there are actually changes which are just being suppressed in the CLI output for convenience. Can you show the json output from the generated plan? Thanks! |
Hello @jbardin , Thanks for your answer . To confirm your question , I run the drift detection (terraform plan -refresh-only -detailed-exitcode) immediately after terraform apply , so there should not be any changes at all . I can get you the Json output to view ... I just need some time to find and sanitize it . Please expect reply soon |
Here is the file you requested ... It is json output of |
Thanks @stehubhex, the plan has I wonder if it's not the resources, but the outputs that are somehow triggering the applyable status. Could you check if this happens with v1.9 as well? |
This is exactly what I am trying to convey .
I tested it with and without outputs and it still has the same results . I will respond soon with the plan from the repeated test. |
Thanks, the change from 1.9 was specifically around the outputs, but it can't hurt to check anyway just in case this is a new regression. |
I have change the version. Terraform v1.9.8
on windows_amd64
+ provider registry.terraform.io/hashicorp/azurerm v4.16.0 And redeployed the infrastructure with terraform apply . After a successful execution my next command was the below. PS D:\temp\jan\TFTest> terraform plan -refresh-only -detailed-exitcode -out=plan
azurerm_resource_group.rg: Refreshing state... [...]
azurerm_storage_account.sa: Refreshing state... [...]
No changes. Your infrastructure still matches the configuration.
Terraform has checked that the real remote objects still match the result of your most recent changes, and found no differences.
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Saved the plan to: plan
To perform exactly these actions, run the following command to apply:
terraform apply "plan"
PS D:\> $LASTEXITCODE
2 Here is the detailed refresh plan of "RG" and "SA" without outputs : TFplanRFonly-rg-sa-no-output.json You can see the same results are repeated. Please advise or suggest different test you would need to see . |
Thanks @stehubhex, that is very helpful. I don't think there's any other tests to run, we will need to continue debugging this within Terraform. |
Thanks you @jbardin , |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Terraform Version
Terraform Configuration Files
Debug Output
Expected Behavior
The command
terraform plan -refresh-only -detailed-exitcode
should return 0 if the configuration was just deployed withterraform apply
and there are no changes detected .Actual Behavior
When running the command
terraform plan -refresh-only -detailed-exitcode
it returns "$LASTEXITCODE 2" even though it is ran right afterterraform apply
and there are no changes detected .Steps to Reproduce
Additional Context
When deploying a new configuration methodically and checking the drift on each step I see the following :
Deploying successfully the resource "azurerm_resource_group" "rg" and running
terraform plan -refresh-only -detailed-exitcode -out=tfplan
and then checking $LASTEXITCODE returns 0 as expected. Checking the plan withterraform show -json tfplan
also confirms that there are no changes pending.Continuing with the same actions for the next resource "azurerm_storage_account" "sa" , it is successfully deployed. Immediately after the
terraform apply
aterraform plan -refresh-only -detailed-exitcode -out=tfplan1
is triggered in the terminal. This results in "No changes." , but suddenly $LASTEXITCODE returns 2 . Reviewing the planterraform show -json tfplan1
also does not indicate any changes.This behavior is seen with other resources as well for example: resource "azurerm_service_plan" "sp" ; resource "azurerm_linux_function_app" "fn" ; and some more complicated resources other than a "azurerm_resource_group" .
The documentation clearly explains the expected behavior and results for the -detailed-exitcode option
References
terraform plan
should execute Checks and exit with0
if everything matches. #35226Generative AI / LLM assisted development?
No response
The text was updated successfully, but these errors were encountered: