-
Notifications
You must be signed in to change notification settings - Fork 15
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
Add drift handling #226
Add drift handling #226
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.
Nice work @samuel-br
Left some comments/questions
Please also see my comments about the missing test case. It looks like you're missing this tests in all relevant resources
#219 (comment) I'm not 100% sure about what I said, and just raise a flag for you, because that's what I understood from the TF @samuel-br just validate that please, and QA your changes by running the provider after drift changes (in env0). |
|
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.
@samuel-br I am not sure i understood your comment.
also please write a propper description of that PR.
@yaronya @eranelbaz please revisit my comments here.
I am not sure about it...
if !found { | ||
if !d.IsNewResource() { | ||
d.SetId("") | ||
} | ||
} |
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.
if !d.IsNewResource() && !found {
log.Printf("[WARN] Project (%s) not found, removing from state", d.Id())
d.SetId("")
return nil
}
Looks better to me. I took it from S3 bucket provider as example / reference.
Please do the same for others if can.
I am still not sure about this one.
IIUC we should still throw
on d.IsNewResource()==true && someErrorOrBadCodeExists
.
I don't see any error returned on that case. @yaronya maybe you can revisit my thoughts here?
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.
i don't think we need to throw something, but we do need to return nil
here
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.
Yes, @eranelbaz is correct - we don't need to throw anything. This is what we wanted to avoid in first place.
We should be removing the resource from state.
@samuel-br haven't we previously discussed it and said that we don't really need to check whether IsNewResource
because TF doesn't read
the resource before create
(only before update
/delete
) so this would always return 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.
@yaronya i think read
is invoked on create
too..
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.
read
invokes on terraform refresh IIRC
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.
@razbensimon did you mean to fix the if
or for the log?
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.
the if
is good now, just suggested adding logs to the user as I saw in the S3 bucket example.
for your decision @samuel-br
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.
"drift detected: TerraForm will remove {this resource} from state" is that good wording?
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.
"[WARN] Drift Detected: Terraform will remove {this resource} from state"
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.
@@ -286,6 +286,7 @@ type Environment struct { | |||
LifespanEndAt string `json:"lifespanEndAt"` | |||
LatestDeploymentLogId string `json:"latestDeploymentLogId"` | |||
LatestDeploymentLog DeploymentLog `json:"latestDeploymentLog"` | |||
IsArchived bool `json:"isArchived"` |
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.
don't we need to use it on the logic somewhere?
just wondering
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.
The PR handled also environment resource at start but since it isn't so trivial to re-create an environment on some drift and there's a deeper product decision to make before implementing it, we've decided to ditch it for now and create a separate issue for environment and project resources.
This looks like a leftover tho.
@samuel-br did you create that seperate issue btw?
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.
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.
I'm not so sure. I expect to see an issue that includes environment and project resources in its description, but couldn't find it.
If I get that correctly:
- Handle drift - general #205 talks about our drift issues in general
- Handle drift - specific resources #225 tries to tackle specific resources, such as template for e.g
- We're missing another issue that tackles environment and project
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.
nope, Ill do it later today, but I want to summary this before on channel, cause for now there is three or for types of resources in this contexts of problem
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.
@samuel-br maybe just change their title?
Handle drift - general
Handle drift - specific resources
etc
and link them
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.
i am confused with all of those issues.
I just asked to make the PR with a good description (copy-paste the issue if needed to the PR).
anyways, if that line of code is related to this PR keep it.
if not - remove it
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.
I've changed the title for #250 already FYI.
And yes, prefer not having multiple issues with the same name.
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.
@samuel-br can you please share on the main issue (i.e #205) what's needed to be done basically and why it differs from the other issues (parsing the error codes from http client layer and etc.)
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.
@yaronya @eranelbaz I changed the issues names (@yaronya thanks on #250 ) and add #205 (comment) on the main issue, please take a look on that comment to ensure its clear enough
…into fix-handle_drift_withIsDeleted-#225
…into fix-handle_drift_withIsDeleted-#225
…into fix-handle_drift_withIsDeleted-#225
Issue & Steps to Reproduce / Feature Request
fixes #225
Solution
Add check if
deleted
in read function to determine if drift happened , and invoke destroy that remove the resource from the state, instead of throwing error