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

Add labels to Bigtable instance #2325

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
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