From abaed61e4820cd0399002033178f587e92d9f44c Mon Sep 17 00:00:00 2001 From: Chris Stephens Date: Fri, 26 Jul 2019 18:33:51 +0000 Subject: [PATCH] Supporting labelling of disks Signed-off-by: Modular Magician --- google/resource_compute_instance.go | 16 ++++++++++++++-- google/resource_compute_instance_template.go | 12 ++++++++++++ .../resource_compute_instance_template_test.go | 3 +++ website/docs/r/container_cluster.html.markdown | 2 +- 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/google/resource_compute_instance.go b/google/resource_compute_instance.go index cd6a5216597..a219c68aaec 100644 --- a/google/resource_compute_instance.go +++ b/google/resource_compute_instance.go @@ -115,6 +115,13 @@ func resourceComputeInstance() *schema.Resource { ForceNew: true, DiffSuppressFunc: diskImageDiffSuppress, }, + + "labels": { + Type: schema.TypeMap, + Optional: true, + Computed: true, + ForceNew: true, + }, }, }, }, @@ -1652,6 +1659,10 @@ func expandBootDisk(d *schema.ResourceData, config *Config, zone *compute.Zone, disk.InitializeParams.SourceImage = imageUrl } + + if _, ok := d.GetOk("boot_disk.0.initialize_params.0.labels"); ok { + disk.InitializeParams.Labels = expandStringMap(d, "boot_disk.0.initialize_params.0.labels") + } } return disk, nil @@ -1682,8 +1693,9 @@ func flattenBootDisk(d *schema.ResourceData, disk *computeBeta.AttachedDisk, con "type": GetResourceNameFromSelfLink(diskDetails.Type), // If the config specifies a family name that doesn't match the image name, then // the diff won't be properly suppressed. See DiffSuppressFunc for this field. - "image": diskDetails.SourceImage, - "size": diskDetails.SizeGb, + "image": diskDetails.SourceImage, + "size": diskDetails.SizeGb, + "labels": diskDetails.Labels, }} } diff --git a/google/resource_compute_instance_template.go b/google/resource_compute_instance_template.go index 061a74c29bf..bd51b3bcff3 100644 --- a/google/resource_compute_instance_template.go +++ b/google/resource_compute_instance_template.go @@ -99,6 +99,15 @@ func resourceComputeInstanceTemplate() *schema.Resource { Computed: true, }, + "labels": { + Type: schema.TypeMap, + Optional: true, + ForceNew: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "source_image": { Type: schema.TypeString, Optional: true, @@ -599,6 +608,8 @@ func buildDisks(d *schema.ResourceData, config *Config) ([]*computeBeta.Attached } disk.InitializeParams.SourceImage = imageUrl } + + disk.InitializeParams.Labels = expandStringMap(d, prefix+".labels") } if v, ok := d.GetOk(prefix + ".interface"); ok { @@ -784,6 +795,7 @@ func flattenDisk(disk *computeBeta.AttachedDisk, defaultProject string) (map[str diskMap["disk_type"] = disk.InitializeParams.DiskType diskMap["disk_name"] = disk.InitializeParams.DiskName diskMap["disk_size_gb"] = disk.InitializeParams.DiskSizeGb + diskMap["labels"] = disk.InitializeParams.Labels } if disk.DiskEncryptionKey != nil { diff --git a/google/resource_compute_instance_template_test.go b/google/resource_compute_instance_template_test.go index 48ac0761c8c..0afc603ca9e 100644 --- a/google/resource_compute_instance_template_test.go +++ b/google/resource_compute_instance_template_test.go @@ -1335,6 +1335,9 @@ resource "google_compute_instance_template" "foobar" { auto_delete = true disk_size_gb = 100 boot = true + labels = { + foo = "bar" + } } disk { diff --git a/website/docs/r/container_cluster.html.markdown b/website/docs/r/container_cluster.html.markdown index 5a0dfa9ca32..3a3084806bc 100644 --- a/website/docs/r/container_cluster.html.markdown +++ b/website/docs/r/container_cluster.html.markdown @@ -667,7 +667,7 @@ exported: notation (e.g. `1.2.3.4/29`). * `services_ipv4_cidr` - The IP address range of the Kubernetes services in this - cluster, in [CIDR](http://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing) + cluster, in [CIDR](http:en.wikipedia.org/wiki/Classless_Inter-Domain_Routing) notation (e.g. `1.2.3.4/29`). Service addresses are typically put in the last `/16` from the container CIDR.