-
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
Attaching an additional disk to a template containing a boot disk fails with google_compute_instance_from_template #2122
Attaching an additional disk to a template containing a boot disk fails with google_compute_instance_from_template #2122
Comments
Does using the |
I didn't see this resource. I cannot try this right now, but I'll check that asap |
Hello, I was able to try this workaround today, and it is working as expected, the instance is started with the additional disk attached. So your hunch seems correct. I will be able to use this workaround in the meantime. Thanks |
I don't think this is a race condition, but a bug in the way we handle disks. The compute instances API expects one block of disks, where the first one is the boot disk. We decided that in TF we were going to separate that out separately into a boot disk block, attached disks, and scratch disks. When we actually make the API request, we put the boot disk, all attached disks, and then all scratch disks in a list and send it off to the API. In the compute_instance_from_template resource, we create the instance in the same way as the instance resource. Since we allow only specifying a subset of the disks, this means that the list we send to the API in this example is just the attached disk, which is the bug. Instead, we should read the instance template, get the list of disks, and append this one onto the end. Then in the read function, we should read both the instance and the template, subtract out any disks that appear in both lists, and store the difference in state. But yes, as Paddy said, the compute_attached_disk resource works great as a workaround until this bug is fixed. |
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! |
Community Note
Terraform Version
Terraform v0.11.8
Affected Resource(s)
Terraform Configuration Files
Debug Output
Trace output : https://gist.github.com/bmoyet/8a9c65ade4ed8b9c69569a0e8af6511d
Debug output if you prefer : https://gist.github.com/bmoyet/f08ff914750af09e86c730718f171c52
Expected Behavior
Terraform should have created a google instance template containing a boot disk with the specified image. Then, when creating the actual instance from it, it should have used the boot disk and attached another disks.
Maybe I'm using google_compute_instance_from_template wrong, I tried different other setup including trying to specify "boot_disk" inside since it is a google_compute_instance property and the doc says I can use any property from google_compute_instance in google_compute_instance_from_template, but to no avail.
Actual Behavior
Apply fails giving me the error : * google_compute_instance_from_template.member: Error creating instance: googleapi: Error 400: Invalid value for field 'resource.disks[0]': ''. Boot disk must be the first disk attached to the instance., invalid
On google cloud the template is created with the correct boot disk attached, so is the data disk created with google_compute_disk.
Steps to Reproduce
terraform plan -var 'instance_group_name=mongo-cluster-shd04' -var 'replica_set=rs04' -var 'instance_count=1' -out deployRs
terraform apply "deployRs"
Thank you for you help
The text was updated successfully, but these errors were encountered: