Skip to content

Commit

Permalink
Add labels to Bigtable instance (#3793) (#2325)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Aug 3, 2020
1 parent fb73b10 commit f14ef45
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/3793.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
bigtable: add support for labels in `google_bigtable_instance`
```
16 changes: 16 additions & 0 deletions google-beta/resource_bigtable_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions google-beta/resource_bigtable_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ resource "google_bigtable_instance" "instance" {
}
deletion_protection = false
labels = {
env = "default"
}
}
`, instanceName, instanceName, numNodes)
}
Expand Down Expand Up @@ -344,6 +348,10 @@ resource "google_bigtable_instance" "instance" {
}
deletion_protection = false
labels = {
env = "default"
}
}
`, instanceName, instanceName, numNodes, instanceName, numNodes, instanceName, numNodes)
}
Expand Down
10 changes: 10 additions & 0 deletions website/docs/r/bigtable_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ resource "google_bigtable_instance" "production-instance" {
lifecycle {
prevent_destroy = true
}
labels = {
my-label = "prod-label"
}
}
```

Expand All @@ -54,6 +58,10 @@ resource "google_bigtable_instance" "development-instance" {
zone = "us-central1-b"
storage_type = "HDD"
}
labels = {
my-label = "dev-label"
}
}
```

Expand All @@ -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.


-----

Expand Down

0 comments on commit f14ef45

Please sign in to comment.