-
Notifications
You must be signed in to change notification settings - Fork 44
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 state not updated on a failed run #527
Comments
It looks like this functionality - not specific to Terraform Cloud - was added only recently, in v1.5.0: https://github.com/hashicorp/terraform/blob/v1.5/CHANGELOG.md#150-june-12-2023
OTF currently runs Thank you for bringing this to my attention. |
Hi @leg100 I have little experience with Golang so please let me see if I understand this. The worker finishes the phase and regardless of the outcome it invokes the FinishPhase but it will set "Errored" in the finishOptions. Lines 70 to 76 in 6b9e6b1
In the service.FinishPhase it creates a report for output (if not Errored) then it updates the state in the DB. It still passes a reference to the error. Lines 324 to 326 in 6b9e6b1
In the DB updateStatus method it checks if the run was errored and it it was it won't update the status. Lines 113 to 115 in 6b9e6b1
So if I remove those 3 lines in db.go it should continue saving the state even in case of an error which is what this issue is about. Is that right? |
@Spritekin That part of code is concerned with updating the run status, not terraform state. See the fix I've made here: https://github.com/leg100/otf/pull/539/files If you read The problem in this case is that the terraform apply step fails and so it would skip the next and last step that uploads the state. The fix is to combine the two steps into one. In Go, a |
🤖 I have created a release *beep* *boop* --- ## [0.1.2](v0.1.1...v0.1.2) (2023-07-26) ### Bug Fixes * agent race error ([#537](#537)) ([6b9e6b1](6b9e6b1)) * handle run-events request from terraform cloud backend ([#534](#534)) ([b1998bd](b1998bd)) * terraform apply partial state updates ([#539](#539)) ([d25e7e4](d25e7e4)), closes [#527](#527) ### Miscellaneous * removed unused config file ([84fe3b1](84fe3b1)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@Spritekin It would be appreciated if you can give the new release a test run, and even better if you can replicate the error scenario above, to see if it successfully persists partial state updates. |
sure I will do now... I'm rebuilding my images with AWS CLI support. |
Now I can't replicate the failure... don't worry I will build a new module soon, new modules usually fail during tests. Will keep you posted. |
@leg100 maybe it would be helpful to list custom images like this or mine in the Readme? To prevent other users from building duplicate ones unnecessarily |
@leg100 I'm still testing but looking good. I say this because in a first run I got a series of objects being created then my module failed... the apply phase looks like this:
But then if I try to rerun th plan already recognises the created objects and tries to refresh:
This wouldn't happen before and it tried to recreate all objects and failed because they existed already. Then I tried deleting the stack and the objects were delete correctly.
So I think this feature is good. Thank you so much! |
I have a run with a series of resources, the plan finishes ok.
During the apply, some of the resources are created, but the run fails mid execution due to some problem which prevents a pod from being created.
Then it fails, like this:
The problem is, in case of a failure, the state file is not updated, then the resources created by this run are not under Terraform control.
If I decide to delete the workspace, any objects created during the failed run are ignored and left in the account.
So, in case of a failed run, the state file should be updated with references to any resource created during the run.
This behavior differs from Terraform Cloud which creates multiple state files during a single run and keeps all the created objects on the state.
The text was updated successfully, but these errors were encountered: