Skip to content

Commit f14ef45

Browse files
Add labels to Bigtable instance (#3793) (#2325)
Signed-off-by: Modular Magician <[email protected]>
1 parent fb73b10 commit f14ef45

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

.changelog/3793.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
bigtable: add support for labels in `google_bigtable_instance`
3+
```

google-beta/resource_bigtable_instance.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ func resourceBigtableInstance() *schema.Resource {
106106
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.`,
107107
},
108108

109+
"labels": {
110+
Type: schema.TypeMap,
111+
Optional: true,
112+
Elem: &schema.Schema{Type: schema.TypeString},
113+
Description: `A mapping of labels to assign to the resource.`,
114+
},
115+
109116
"project": {
110117
Type: schema.TypeString,
111118
Optional: true,
@@ -136,6 +143,10 @@ func resourceBigtableInstanceCreate(d *schema.ResourceData, meta interface{}) er
136143
}
137144
conf.DisplayName = displayName.(string)
138145

146+
if _, ok := d.GetOk("labels"); ok {
147+
conf.Labels = expandLabels(d)
148+
}
149+
139150
switch d.Get("instance_type").(string) {
140151
case "DEVELOPMENT":
141152
conf.InstanceType = bigtable.DEVELOPMENT
@@ -211,6 +222,7 @@ func resourceBigtableInstanceRead(d *schema.ResourceData, meta interface{}) erro
211222

212223
d.Set("name", instance.Name)
213224
d.Set("display_name", instance.DisplayName)
225+
d.Set("labels", instance.Labels)
214226
// Don't set instance_type: we don't want to detect drift on it because it can
215227
// change under-the-hood.
216228

@@ -242,6 +254,10 @@ func resourceBigtableInstanceUpdate(d *schema.ResourceData, meta interface{}) er
242254
}
243255
conf.DisplayName = displayName.(string)
244256

257+
if d.HasChange("labels") {
258+
conf.Labels = expandLabels(d)
259+
}
260+
245261
switch d.Get("instance_type").(string) {
246262
case "DEVELOPMENT":
247263
conf.InstanceType = bigtable.DEVELOPMENT

google-beta/resource_bigtable_instance_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ resource "google_bigtable_instance" "instance" {
200200
}
201201
202202
deletion_protection = false
203+
204+
labels = {
205+
env = "default"
206+
}
203207
}
204208
`, instanceName, instanceName, numNodes)
205209
}
@@ -344,6 +348,10 @@ resource "google_bigtable_instance" "instance" {
344348
}
345349
346350
deletion_protection = false
351+
352+
labels = {
353+
env = "default"
354+
}
347355
}
348356
`, instanceName, instanceName, numNodes, instanceName, numNodes, instanceName, numNodes)
349357
}

website/docs/r/bigtable_instance.html.markdown

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ resource "google_bigtable_instance" "production-instance" {
3939
lifecycle {
4040
prevent_destroy = true
4141
}
42+
43+
labels = {
44+
my-label = "prod-label"
45+
}
4246
}
4347
```
4448

@@ -54,6 +58,10 @@ resource "google_bigtable_instance" "development-instance" {
5458
zone = "us-central1-b"
5559
storage_type = "HDD"
5660
}
61+
62+
labels = {
63+
my-label = "dev-label"
64+
}
5765
}
5866
```
5967

@@ -78,6 +86,8 @@ See structure below.
7886
* `deletion_protection` - (Optional) Whether or not to allow Terraform to destroy the instance. Unless this field is set to false
7987
in Terraform state, a `terraform destroy` or `terraform apply` that would delete the instance will fail.
8088

89+
* `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.
90+
8191

8292
-----
8393

0 commit comments

Comments
 (0)