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 labelling of disks #4117

Merged
merged 1 commit into from
Jul 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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