Skip to content

Commit 1baf881

Browse files
Support for Tags in google_data_fusion_instance (#13408) (#21977)
[upstream:22bc52fb8f6bfe4d6d4ee8d52537ed12b853e6c9] Signed-off-by: Modular Magician <[email protected]>
1 parent 5442046 commit 1baf881

File tree

6 files changed

+92
-7
lines changed

6 files changed

+92
-7
lines changed

.changelog/13408.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
datafusion: added `tags` field to `google_data_fusion_instance` resource to allow setting tags for instances at creation time
3+
```

google/services/datafusion/resource_data_fusion_instance.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,16 @@ able to access the public internet.`,
303303
ForceNew: true,
304304
Description: `The region of the Data Fusion instance.`,
305305
},
306+
"tags": {
307+
Type: schema.TypeMap,
308+
Optional: true,
309+
ForceNew: true,
310+
Description: `A map of resource manager tags.
311+
Resource manager tag keys and values have the same definition as resource manager tags.
312+
Keys must be in the format tagKeys/{tag_key_id}, and values are in the format tagValues/{tag_value_id}.
313+
The field is ignored (both PUT & PATCH) when empty.`,
314+
Elem: &schema.Schema{Type: schema.TypeString},
315+
},
306316
"version": {
307317
Type: schema.TypeString,
308318
Computed: true,
@@ -495,6 +505,12 @@ func resourceDataFusionInstanceCreate(d *schema.ResourceData, meta interface{})
495505
} else if v, ok := d.GetOkExists("accelerators"); !tpgresource.IsEmptyValue(reflect.ValueOf(acceleratorsProp)) && (ok || !reflect.DeepEqual(v, acceleratorsProp)) {
496506
obj["accelerators"] = acceleratorsProp
497507
}
508+
tagsProp, err := expandDataFusionInstanceTags(d.Get("tags"), d, config)
509+
if err != nil {
510+
return err
511+
} else if v, ok := d.GetOkExists("tags"); !tpgresource.IsEmptyValue(reflect.ValueOf(tagsProp)) && (ok || !reflect.DeepEqual(v, tagsProp)) {
512+
obj["tags"] = tagsProp
513+
}
498514
labelsProp, err := expandDataFusionInstanceEffectiveLabels(d.Get("effective_labels"), d, config)
499515
if err != nil {
500516
return err
@@ -1402,6 +1418,17 @@ func expandDataFusionInstanceAcceleratorsState(v interface{}, d tpgresource.Terr
14021418
return v, nil
14031419
}
14041420

1421+
func expandDataFusionInstanceTags(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) {
1422+
if v == nil {
1423+
return map[string]string{}, nil
1424+
}
1425+
m := make(map[string]string)
1426+
for k, val := range v.(map[string]interface{}) {
1427+
m[k] = val.(string)
1428+
}
1429+
return m, nil
1430+
}
1431+
14051432
func expandDataFusionInstanceEffectiveLabels(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) {
14061433
if v == nil {
14071434
return map[string]string{}, nil

google/services/datafusion/resource_data_fusion_instance_generated_meta.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ fields:
3737
- field: 'service_endpoint'
3838
- field: 'state'
3939
- field: 'state_message'
40+
- field: 'tags'
4041
- field: 'tenant_project_id'
4142
- field: 'terraform_labels'
4243
provider_only: true

google/services/datafusion/resource_data_fusion_instance_generated_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func TestAccDataFusionInstance_dataFusionInstanceBasicExample(t *testing.T) {
5050
ResourceName: "google_data_fusion_instance.basic_instance",
5151
ImportState: true,
5252
ImportStateVerify: true,
53-
ImportStateVerifyIgnore: []string{"labels", "network_config.0.private_service_connect_config.0.unreachable_cidr_block", "region", "terraform_labels"},
53+
ImportStateVerifyIgnore: []string{"labels", "network_config.0.private_service_connect_config.0.unreachable_cidr_block", "region", "tags", "terraform_labels"},
5454
},
5555
},
5656
})
@@ -87,7 +87,7 @@ func TestAccDataFusionInstance_dataFusionInstanceFullExample(t *testing.T) {
8787
ResourceName: "google_data_fusion_instance.extended_instance",
8888
ImportState: true,
8989
ImportStateVerify: true,
90-
ImportStateVerifyIgnore: []string{"labels", "network_config.0.private_service_connect_config.0.unreachable_cidr_block", "region", "terraform_labels"},
90+
ImportStateVerifyIgnore: []string{"labels", "network_config.0.private_service_connect_config.0.unreachable_cidr_block", "region", "tags", "terraform_labels"},
9191
},
9292
},
9393
})
@@ -159,7 +159,7 @@ func TestAccDataFusionInstance_dataFusionInstancePscExample(t *testing.T) {
159159
ResourceName: "google_data_fusion_instance.psc_instance",
160160
ImportState: true,
161161
ImportStateVerify: true,
162-
ImportStateVerifyIgnore: []string{"labels", "network_config.0.private_service_connect_config.0.unreachable_cidr_block", "region", "terraform_labels"},
162+
ImportStateVerifyIgnore: []string{"labels", "network_config.0.private_service_connect_config.0.unreachable_cidr_block", "region", "tags", "terraform_labels"},
163163
},
164164
},
165165
})
@@ -228,7 +228,7 @@ func TestAccDataFusionInstance_dataFusionInstanceCmekExample(t *testing.T) {
228228
ResourceName: "google_data_fusion_instance.cmek",
229229
ImportState: true,
230230
ImportStateVerify: true,
231-
ImportStateVerifyIgnore: []string{"labels", "network_config.0.private_service_connect_config.0.unreachable_cidr_block", "region", "terraform_labels"},
231+
ImportStateVerifyIgnore: []string{"labels", "network_config.0.private_service_connect_config.0.unreachable_cidr_block", "region", "tags", "terraform_labels"},
232232
},
233233
},
234234
})
@@ -289,7 +289,7 @@ func TestAccDataFusionInstance_dataFusionInstanceEnterpriseExample(t *testing.T)
289289
ResourceName: "google_data_fusion_instance.enterprise_instance",
290290
ImportState: true,
291291
ImportStateVerify: true,
292-
ImportStateVerifyIgnore: []string{"labels", "network_config.0.private_service_connect_config.0.unreachable_cidr_block", "region", "terraform_labels"},
292+
ImportStateVerifyIgnore: []string{"labels", "network_config.0.private_service_connect_config.0.unreachable_cidr_block", "region", "tags", "terraform_labels"},
293293
},
294294
},
295295
})
@@ -326,7 +326,7 @@ func TestAccDataFusionInstance_dataFusionInstanceEventExample(t *testing.T) {
326326
ResourceName: "google_data_fusion_instance.event",
327327
ImportState: true,
328328
ImportStateVerify: true,
329-
ImportStateVerifyIgnore: []string{"labels", "network_config.0.private_service_connect_config.0.unreachable_cidr_block", "region", "terraform_labels"},
329+
ImportStateVerifyIgnore: []string{"labels", "network_config.0.private_service_connect_config.0.unreachable_cidr_block", "region", "tags", "terraform_labels"},
330330
},
331331
},
332332
})
@@ -370,7 +370,7 @@ func TestAccDataFusionInstance_dataFusionInstanceZoneExample(t *testing.T) {
370370
ResourceName: "google_data_fusion_instance.zone",
371371
ImportState: true,
372372
ImportStateVerify: true,
373-
ImportStateVerifyIgnore: []string{"labels", "network_config.0.private_service_connect_config.0.unreachable_cidr_block", "region", "terraform_labels"},
373+
ImportStateVerifyIgnore: []string{"labels", "network_config.0.private_service_connect_config.0.unreachable_cidr_block", "region", "tags", "terraform_labels"},
374374
},
375375
},
376376
})

google/services/datafusion/resource_data_fusion_instance_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
1010
"github.com/hashicorp/terraform-provider-google/google/acctest"
11+
"github.com/hashicorp/terraform-provider-google/google/envvar"
1112
)
1213

1314
func TestAccDataFusionInstance_update(t *testing.T) {
@@ -210,3 +211,49 @@ resource "google_data_fusion_instance" "basic_instance" {
210211
}
211212
`, context)
212213
}
214+
215+
func TestAccDatafusionInstance_tags(t *testing.T) {
216+
t.Parallel()
217+
org := envvar.GetTestOrgFromEnv(t)
218+
context := map[string]interface{}{
219+
"random_suffix": acctest.RandString(t, 10),
220+
"version": "6.9.1",
221+
}
222+
tagKey := acctest.BootstrapSharedTestTagKey(t, "datafusion-instances-tagkey")
223+
tagValue := acctest.BootstrapSharedTestTagValue(t, "datafusion-instances-tagvalue", tagKey)
224+
225+
acctest.VcrTest(t, resource.TestCase{
226+
PreCheck: func() { acctest.AccTestPreCheck(t) },
227+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
228+
CheckDestroy: testAccCheckDataFusionInstanceDestroyProducer(t),
229+
Steps: []resource.TestStep{
230+
{
231+
Config: testAccDatafusionInstanceTags(context, map[string]string{org + "/" + tagKey: tagValue}),
232+
},
233+
{
234+
ResourceName: "google_data_fusion_instance.instance",
235+
ImportState: true,
236+
ImportStateVerify: true,
237+
ImportStateVerifyIgnore: []string{"region", "labels", "terraform_labels", "tags"},
238+
},
239+
},
240+
})
241+
}
242+
243+
func testAccDatafusionInstanceTags(context map[string]interface{}, tags map[string]string) string {
244+
245+
r := acctest.Nprintf(`
246+
resource "google_data_fusion_instance" "instance" {
247+
name = "my-instance"
248+
region = "us-central1"
249+
type = "BASIC"
250+
tags = {`, context)
251+
252+
l := ""
253+
for key, value := range tags {
254+
l += fmt.Sprintf("%q = %q\n", key, value)
255+
}
256+
257+
l += fmt.Sprintf("}\n}")
258+
return r + l
259+
}

website/docs/r/data_fusion_instance.html.markdown

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,13 @@ The following arguments are supported:
343343
Users will need to either manually update their state file to include these diffed options, or include the field in a [lifecycle ignore changes block](https://developer.hashicorp.com/terraform/language/meta-arguments/lifecycle#ignore_changes).
344344
Structure is [documented below](#nested_accelerators).
345345

346+
* `tags` -
347+
(Optional)
348+
A map of resource manager tags.
349+
Resource manager tag keys and values have the same definition as resource manager tags.
350+
Keys must be in the format tagKeys/{tag_key_id}, and values are in the format tagValues/{tag_value_id}.
351+
The field is ignored (both PUT & PATCH) when empty.
352+
346353
* `region` -
347354
(Optional)
348355
The region of the Data Fusion instance.

0 commit comments

Comments
 (0)