Skip to content

Commit

Permalink
Supporting labelling of disks (#4117)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored and chrisst committed Jul 26, 2019
1 parent 88d6a9a commit 1174486
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
16 changes: 14 additions & 2 deletions google/resource_compute_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ func resourceComputeInstance() *schema.Resource {
ForceNew: true,
DiffSuppressFunc: diskImageDiffSuppress,
},

"labels": {
Type: schema.TypeMap,
Optional: true,
Computed: true,
ForceNew: true,
},
},
},
},
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
}}
}

Expand Down
12 changes: 12 additions & 0 deletions google/resource_compute_instance_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions google/resource_compute_instance_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1335,6 +1335,9 @@ resource "google_compute_instance_template" "foobar" {
auto_delete = true
disk_size_gb = 100
boot = true
labels = {
foo = "bar"
}
}
disk {
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/container_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down

0 comments on commit 1174486

Please sign in to comment.