-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Allow attaching and detaching disks from instances #636
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.
Hi there! Drive-by thoughts:
- is the ordering of
attached_disk
relevant? If so,TypeList
is correct because we want the order of the config to be enforced, and reading from the API with a different order should trigger a diff. If not, we should useTypeSet
for them; their key will be the hash and not their spot in line, if that makes sense. I realize the usage ofTypeList
is not part of this PR, but it's relevant to my next point.. - Continuing down that path, Set’s offer an advantage with the
Difference()
method. See Set#Difference and usage example in AWS Security Groups UPDATE method. It seems in this code we’re doing a similar diff operation, and using Sets would greatly simply it for you - I see in the
READ
method (understandably not being changed here) there seems to be a notion of updating existing disks in config and also adding extra disks and storing them inattached_disk
. It seems there is an issue here, in that we’re not completely overwritingattached_disk
with what we find in the API results. Example, if there is a change and a disk Terraform thinks is attached (it’s in the config) is removed outside of Terraform, does Terraform notice on refresh? There doesn’t seem to be any part in theREAD
that’s removing disks not found. If we simply built up the list from the API and wrote those results, regardless of what we had in the config, we could detect that drift. Again, I realize this is outside of the current PR, but I noticed it.
google/resource_compute_instance.go
Outdated
// were at the time we ran terraform plan. | ||
currDisks := map[string]struct{}{} | ||
for _, disk := range instance.Disks { | ||
if !disk.Boot { |
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.
Silly question: does this take scratch disks into account?
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 it would have done anything unexpected since we're only using it to check whether a disk in state is still attached, but may as well do the check just in case. Done.
google/resource_compute_instance.go
Outdated
} | ||
} | ||
|
||
// Keep track of previous config's disks. |
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 isn't the previous config, it's the state. Terraform does not version configs itself, and so cannot tell you what was in the previous 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.
Fixed.
From what I can see, the disks are being properly set based on the API response. That code should detect drift of:
I think the confusion may be around the |
Yeah, having attached_disks as a Set would definitely simplify things, especially with that Difference method. I'll add that in a new PR and then come back to this one. |
Paddy and I talked this over, and we're not going to try to make |
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.
👍
…ch (hashicorp#636) Signed-off-by: Modular Magician <[email protected]>
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. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks! |
Third time's the charm? Fixes #33.