From 73d5528db2800e7831f853f001b7b6f9690060ae Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Mon, 3 Aug 2020 19:10:54 +0000 Subject: [PATCH] Add labels to Bigtable instance (#3793) Signed-off-by: Modular Magician --- .changelog/3793.txt | 3 +++ google-beta/resource_bigtable_instance.go | 16 ++++++++++++++++ google-beta/resource_bigtable_instance_test.go | 8 ++++++++ website/docs/r/bigtable_instance.html.markdown | 10 ++++++++++ 4 files changed, 37 insertions(+) create mode 100644 .changelog/3793.txt diff --git a/.changelog/3793.txt b/.changelog/3793.txt new file mode 100644 index 0000000000..6aecc4ce53 --- /dev/null +++ b/.changelog/3793.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +bigtable: add support for labels in `google_bigtable_instance` +``` diff --git a/google-beta/resource_bigtable_instance.go b/google-beta/resource_bigtable_instance.go index 1e18c103d5..19ad0e57ba 100644 --- a/google-beta/resource_bigtable_instance.go +++ b/google-beta/resource_bigtable_instance.go @@ -106,6 +106,13 @@ func resourceBigtableInstance() *schema.Resource { Description: `Whether or not to allow Terraform to destroy the instance. Unless this field is set to false in Terraform state, a terraform destroy or terraform apply that would delete the instance will fail.`, }, + "labels": { + Type: schema.TypeMap, + Optional: true, + Elem: &schema.Schema{Type: schema.TypeString}, + Description: `A mapping of labels to assign to the resource.`, + }, + "project": { Type: schema.TypeString, Optional: true, @@ -136,6 +143,10 @@ func resourceBigtableInstanceCreate(d *schema.ResourceData, meta interface{}) er } conf.DisplayName = displayName.(string) + if _, ok := d.GetOk("labels"); ok { + conf.Labels = expandLabels(d) + } + switch d.Get("instance_type").(string) { case "DEVELOPMENT": conf.InstanceType = bigtable.DEVELOPMENT @@ -211,6 +222,7 @@ func resourceBigtableInstanceRead(d *schema.ResourceData, meta interface{}) erro d.Set("name", instance.Name) d.Set("display_name", instance.DisplayName) + d.Set("labels", instance.Labels) // Don't set instance_type: we don't want to detect drift on it because it can // change under-the-hood. @@ -242,6 +254,10 @@ func resourceBigtableInstanceUpdate(d *schema.ResourceData, meta interface{}) er } conf.DisplayName = displayName.(string) + if d.HasChange("labels") { + conf.Labels = expandLabels(d) + } + switch d.Get("instance_type").(string) { case "DEVELOPMENT": conf.InstanceType = bigtable.DEVELOPMENT diff --git a/google-beta/resource_bigtable_instance_test.go b/google-beta/resource_bigtable_instance_test.go index a847b80161..4b702f2045 100644 --- a/google-beta/resource_bigtable_instance_test.go +++ b/google-beta/resource_bigtable_instance_test.go @@ -200,6 +200,10 @@ resource "google_bigtable_instance" "instance" { } deletion_protection = false + + labels = { + env = "default" + } } `, instanceName, instanceName, numNodes) } @@ -344,6 +348,10 @@ resource "google_bigtable_instance" "instance" { } deletion_protection = false + + labels = { + env = "default" + } } `, instanceName, instanceName, numNodes, instanceName, numNodes, instanceName, numNodes) } diff --git a/website/docs/r/bigtable_instance.html.markdown b/website/docs/r/bigtable_instance.html.markdown index 640c5b6b37..f1808dce9f 100644 --- a/website/docs/r/bigtable_instance.html.markdown +++ b/website/docs/r/bigtable_instance.html.markdown @@ -39,6 +39,10 @@ resource "google_bigtable_instance" "production-instance" { lifecycle { prevent_destroy = true } + + labels = { + my-label = "prod-label" + } } ``` @@ -54,6 +58,10 @@ resource "google_bigtable_instance" "development-instance" { zone = "us-central1-b" storage_type = "HDD" } + + labels = { + my-label = "dev-label" + } } ``` @@ -78,6 +86,8 @@ See structure below. * `deletion_protection` - (Optional) Whether or not to allow Terraform to destroy the instance. Unless this field is set to false in Terraform state, a `terraform destroy` or `terraform apply` that would delete the instance will fail. +* `labels` - (Optional) A set of key/value label pairs to assign to the resource. Label keys must follow the requirements at https://cloud.google.com/resource-manager/docs/creating-managing-labels#requirements. + -----