-
Notifications
You must be signed in to change notification settings - Fork 101
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
job: prevent partial update on error #412
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⛅ (this is a "partly sunny" emoji 😋)
@@ -409,6 +410,10 @@ func resourceJobRegister(d *schema.ResourceData, meta interface{}) error { | |||
return fmt.Errorf("error applying jobspec: %s", err) | |||
} | |||
|
|||
if !d.IsNewResource() { | |||
d.Partial(false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is after the job is successfully registered, but before its deployment has succeeded (assuming detach = false
). I suppose this makes sense, because the resource is a job, not a deployment, but I guess I want to flag that a failing deployment would still show "no changes" on a subsequent apply, right? So in that case, one would need to taint
or otherwise destroy and re-apply the job, if the fix for the failing deployment was something other than the job resource config.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's right, but that's Nomad's behaviour. The goal of the TF provider is to update the job state in Nomad. Once that's complete Nomad is responsible for the deployment. Applying again has not effect the same way as running nomad job run
would also not have any effect.
The default behaviour of the Terraform SDK is to copy the plan result into state which could result in partial state updates, where Terraform state is updated, but the actual resource state is not, in case of an error during the apply. This is normally not an issue because resources are expected to undo these changes on state refresh. Any partial update is reconciled with the actual resource state. But due to #1, the `nomad_job` resource is not able to properly reconcile on refresh, causing the partial update to prevent further applies unless the configuration is also changed. This commit uses the `d.Partial()` method to signal to Terraform that any state changes should be rolledback in case of an error.
658adcb
to
9230318
Compare
The default behaviour of the Terraform SDK is to copy the plan result into state which could result in partial state updates, where Terraform state is updated, but the actual resource state is not, in case of an error during the apply.
This is normally not an issue because resources are expected to undo these changes on state refresh. Any partial update is reconciled with the actual resource state.
But due to #1, the
nomad_job
resource is not able to properly reconcile on refresh, causing the partial update to prevent further applies unless the configuration is also changed.This commit uses the
d.Partial()
method to signal to Terraform that any state changes should be rolledback in case of an error.Closes #385