Skip to content
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

Supporting Disk Labels on Instance bootDisk and InstanceTemplate disks #3766

Closed

Conversation

marcboudreau
Copy link

This PR introduces a change that allows specifying labels in the disk block of a google_compute_instance_template resource and in the boot_disk block of a google_compute_instance resource.

The Google API allows setting labels in both of these contexts, so the change simply consists of modifying the resource schemas to allow a label map and then adding the code to retrieve the values from within the resource and set the correct parameters for the API request.

@marcboudreau
Copy link
Author

I realize that I haven't updated the documentation for the google_compute_instance and google_compute_instance_template resources. I can add those to the PR if the general approach is ok.

Copy link
Contributor

@chrisst chrisst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a reasonable approach. Yes please add docs!

@@ -587,6 +596,8 @@ func buildDisks(d *schema.ResourceData, config *Config) ([]*computeBeta.Attached
}
disk.InitializeParams.SourceImage = imageUrl
}

disk.InitializeParams.Labels = expandStringMap(d, prefix+".labels")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are allowing labels on all disk types in the Schema but they won't work if somebody is using them on a disk that's using source. Ideally we'd use ConflictsWith to throw a plan level error but due to limitations in core Terraform we can't use it with lists of nested objects.
Unfortunately this is apparently already a bug with all the other initializeParams fields, but can you add a caveat to the docs for labels.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand. I think with the behaviour clearly explained it should be ok. When using the source, an existing disk is being specified, and regardless of how that disk came into existence (Terraform, Google API, Google Cloud console), the labels could have been set at the time of creation.

My PR is to cover the case where the disks do not exist until the instance template is used to create an instance.

@chrisst chrisst changed the title Supporting Disk Labels on Instance and InstanceTemplate Supporting Disk Labels on Instance bootDisk and InstanceTemplate disks Jun 4, 2019
@ghost ghost added the documentation label Jun 5, 2019
@chrisst
Copy link
Contributor

chrisst commented Jul 26, 2019

upstream and closed by GoogleCloudPlatform/magic-modules#2106
Thanks for the contribution!

@chrisst chrisst closed this Jul 26, 2019
@ghost
Copy link

ghost commented Aug 26, 2019

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!

@ghost ghost locked and limited conversation to collaborators Aug 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants