-
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
Fix bug with CSEK where the key stored in state might be associated with the wrong disk #327
Conversation
…ith the wrong disk
Changed test to include one unencrypted disk so the order matters, and updated code so the order doesn't change. |
With your change, When applying this config: resource "google_compute_disk" "foobar2" {
name = "foobar2"
size = 10
type = "pd-ssd"
zone = "us-central1-a"
disk_encryption_key_raw = "dGhpcmQ2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTI="
}
resource "google_compute_disk" "foobar3" {
name = "foobar3"
size = 10
type = "pd-ssd"
zone = "us-central1-a"
disk_encryption_key_raw = "dGhpcmQ2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTI="
}
resource "google_compute_disk" "foobar4" {
name = "foobar4"
size = 10
type = "pd-ssd"
zone = "us-central1-a"
}
resource "google_compute_instance" "foobar" {
name = "foobar"
machine_type = "n1-standard-1"
zone = "us-central1-a"
boot_disk {
initialize_params{
image = "debian-8-jessie-v20160803"
}
disk_encryption_key_raw = "Ym9vdDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTI="
}
attached_disk {
source = "${google_compute_disk.foobar2.self_link}"
disk_encryption_key_raw = "dGhpcmQ2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTI="
}
attached_disk {
source = "${google_compute_disk.foobar4.self_link}"
}
attached_disk {
source = "${google_compute_disk.foobar3.self_link}"
disk_encryption_key_raw = "dGhpcmQ2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTI="
}
network_interface {
network = "default"
}
metadata {
foo = "bar"
}
} I get a diff after the first apply succeeds:
If I apply again, I get the following error
|
Good catch, thanks! Made a fix (which conveniently simplifies the solution a whole bunch) |
@@ -1003,16 +1006,15 @@ func resourceComputeInstanceRead(d *schema.ResourceData, meta interface{}) error | |||
return fmt.Errorf("Expected %d disks, API returned %d", expectedDisks, len(instance.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 might be outside the scope of this PR but if we add or remove a disk outside of Terraform, then this line fails preventing the user from updating the instance.
Is this a behavior we want to fix?
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.
Not right now- because we're relying so much on what's written in state, we can't really support that case without a fair amount of effort. It'll probably be easier once disks
is gone for good, so it'll probably be worth a shot then.
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 think even with a fair amount of effort, we might not be able to support that case. :/ I think we may just have to accept it for a couple more weeks as a price for getting to a saner model of disks.
@paddycarver are you all good with this change (once I resolve conflicts)? |
All right I'm assuming no answer means yes. Merging now. |
…ith the wrong disk (hashicorp#327) * Fix bug with CSEK where the key stored in state might be associated with the wrong disk * preserve original order of attached disks * use the disk index to figure out the raw key
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! |
Instances don't necessarily return disks in the order they were sent, so we can't just set the encryption key in state based on the index. This matches the correct key to the correct disk information.
This change could potentially break existing configs by changing the order disks are in or adding keys that were not in state before. However, these configs were technically wrong before.