Skip to content

Commit 52d1efb

Browse files
Support for Tags in google_dataproc_metastore_service resource (#13440) (#22313)
[upstream:34f56dcedf4eaa1dc72509c019342bba6ae018d7] Signed-off-by: Modular Magician <[email protected]>
1 parent 0a754aa commit 52d1efb

6 files changed

+107
-15
lines changed

.changelog/13440.txt

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

google/services/dataprocmetastore/resource_dataproc_metastore_service.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,15 @@ There must be at least one IP address available in the subnet's primary range. T
416416
},
417417
},
418418
},
419+
"tags": {
420+
Type: schema.TypeMap,
421+
Optional: true,
422+
ForceNew: true,
423+
Description: `A map of resource manager tags.
424+
Resource manager tag keys and values have the same definition as resource manager tags.
425+
Keys must be in the format tagKeys/{tag_key_id}, and values are in the format tagValues/{tag_value_id}.`,
426+
Elem: &schema.Schema{Type: schema.TypeString},
427+
},
419428
"telemetry_config": {
420429
Type: schema.TypeList,
421430
Computed: true,
@@ -598,6 +607,12 @@ func resourceDataprocMetastoreServiceCreate(d *schema.ResourceData, meta interfa
598607
} else if v, ok := d.GetOkExists("telemetry_config"); !tpgresource.IsEmptyValue(reflect.ValueOf(telemetryConfigProp)) && (ok || !reflect.DeepEqual(v, telemetryConfigProp)) {
599608
obj["telemetryConfig"] = telemetryConfigProp
600609
}
610+
tagsProp, err := expandDataprocMetastoreServiceTags(d.Get("tags"), d, config)
611+
if err != nil {
612+
return err
613+
} else if v, ok := d.GetOkExists("tags"); !tpgresource.IsEmptyValue(reflect.ValueOf(tagsProp)) && (ok || !reflect.DeepEqual(v, tagsProp)) {
614+
obj["tags"] = tagsProp
615+
}
601616
labelsProp, err := expandDataprocMetastoreServiceEffectiveLabels(d.Get("effective_labels"), d, config)
602617
if err != nil {
603618
return err
@@ -2037,6 +2052,17 @@ func expandDataprocMetastoreServiceTelemetryConfigLogFormat(v interface{}, d tpg
20372052
return v, nil
20382053
}
20392054

2055+
func expandDataprocMetastoreServiceTags(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) {
2056+
if v == nil {
2057+
return map[string]string{}, nil
2058+
}
2059+
m := make(map[string]string)
2060+
for k, val := range v.(map[string]interface{}) {
2061+
m[k] = val.(string)
2062+
}
2063+
return m, nil
2064+
}
2065+
20402066
func expandDataprocMetastoreServiceEffectiveLabels(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) {
20412067
if v == nil {
20422068
return map[string]string{}, nil

google/services/dataprocmetastore/resource_dataproc_metastore_service_generated_meta.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ fields:
4747
provider_only: true
4848
- field: 'state'
4949
- field: 'state_message'
50+
- field: 'tags'
5051
- field: 'telemetry_config.log_format'
5152
- field: 'terraform_labels'
5253
provider_only: true

google/services/dataprocmetastore/resource_dataproc_metastore_service_generated_test.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func TestAccDataprocMetastoreService_dataprocMetastoreServiceBasicExample(t *tes
4949
ResourceName: "google_dataproc_metastore_service.default",
5050
ImportState: true,
5151
ImportStateVerify: true,
52-
ImportStateVerifyIgnore: []string{"labels", "location", "service_id", "terraform_labels"},
52+
ImportStateVerifyIgnore: []string{"labels", "location", "service_id", "tags", "terraform_labels"},
5353
},
5454
},
5555
})
@@ -99,7 +99,7 @@ func TestAccDataprocMetastoreService_dataprocMetastoreServiceDeletionProtectionE
9999
ResourceName: "google_dataproc_metastore_service.default",
100100
ImportState: true,
101101
ImportStateVerify: true,
102-
ImportStateVerifyIgnore: []string{"labels", "location", "service_id", "terraform_labels"},
102+
ImportStateVerifyIgnore: []string{"labels", "location", "service_id", "tags", "terraform_labels"},
103103
},
104104
},
105105
})
@@ -150,7 +150,7 @@ func TestAccDataprocMetastoreService_dataprocMetastoreServiceCmekTestExample(t *
150150
ResourceName: "google_dataproc_metastore_service.default",
151151
ImportState: true,
152152
ImportStateVerify: true,
153-
ImportStateVerifyIgnore: []string{"labels", "location", "service_id", "terraform_labels"},
153+
ImportStateVerifyIgnore: []string{"labels", "location", "service_id", "tags", "terraform_labels"},
154154
},
155155
},
156156
})
@@ -216,7 +216,7 @@ func TestAccDataprocMetastoreService_dataprocMetastoreServiceEndpointExample(t *
216216
ResourceName: "google_dataproc_metastore_service.endpoint",
217217
ImportState: true,
218218
ImportStateVerify: true,
219-
ImportStateVerifyIgnore: []string{"labels", "location", "service_id", "terraform_labels"},
219+
ImportStateVerifyIgnore: []string{"labels", "location", "service_id", "tags", "terraform_labels"},
220220
},
221221
},
222222
})
@@ -256,7 +256,7 @@ func TestAccDataprocMetastoreService_dataprocMetastoreServiceAuxExample(t *testi
256256
ResourceName: "google_dataproc_metastore_service.aux",
257257
ImportState: true,
258258
ImportStateVerify: true,
259-
ImportStateVerifyIgnore: []string{"labels", "location", "service_id", "terraform_labels"},
259+
ImportStateVerifyIgnore: []string{"labels", "location", "service_id", "tags", "terraform_labels"},
260260
},
261261
},
262262
})
@@ -299,7 +299,7 @@ func TestAccDataprocMetastoreService_dataprocMetastoreServiceMetadataExample(t *
299299
ResourceName: "google_dataproc_metastore_service.metadata",
300300
ImportState: true,
301301
ImportStateVerify: true,
302-
ImportStateVerifyIgnore: []string{"labels", "location", "service_id", "terraform_labels"},
302+
ImportStateVerifyIgnore: []string{"labels", "location", "service_id", "tags", "terraform_labels"},
303303
},
304304
},
305305
})
@@ -344,7 +344,7 @@ func TestAccDataprocMetastoreService_dataprocMetastoreServiceTelemetryExample(t
344344
ResourceName: "google_dataproc_metastore_service.telemetry",
345345
ImportState: true,
346346
ImportStateVerify: true,
347-
ImportStateVerifyIgnore: []string{"labels", "location", "service_id", "terraform_labels"},
347+
ImportStateVerifyIgnore: []string{"labels", "location", "service_id", "tags", "terraform_labels"},
348348
},
349349
},
350350
})
@@ -388,7 +388,7 @@ func TestAccDataprocMetastoreService_dataprocMetastoreServiceDpms2Example(t *tes
388388
ResourceName: "google_dataproc_metastore_service.dpms2",
389389
ImportState: true,
390390
ImportStateVerify: true,
391-
ImportStateVerifyIgnore: []string{"labels", "location", "service_id", "terraform_labels"},
391+
ImportStateVerifyIgnore: []string{"labels", "location", "service_id", "tags", "terraform_labels"},
392392
},
393393
},
394394
})
@@ -434,7 +434,7 @@ func TestAccDataprocMetastoreService_dataprocMetastoreServiceDpms2ScalingFactorE
434434
ResourceName: "google_dataproc_metastore_service.dpms2_scaling_factor",
435435
ImportState: true,
436436
ImportStateVerify: true,
437-
ImportStateVerifyIgnore: []string{"labels", "location", "service_id", "terraform_labels"},
437+
ImportStateVerifyIgnore: []string{"labels", "location", "service_id", "tags", "terraform_labels"},
438438
},
439439
},
440440
})
@@ -480,7 +480,7 @@ func TestAccDataprocMetastoreService_dataprocMetastoreServiceDpms2ScalingFactorL
480480
ResourceName: "google_dataproc_metastore_service.dpms2_scaling_factor_lt1",
481481
ImportState: true,
482482
ImportStateVerify: true,
483-
ImportStateVerifyIgnore: []string{"labels", "location", "service_id", "terraform_labels"},
483+
ImportStateVerifyIgnore: []string{"labels", "location", "service_id", "tags", "terraform_labels"},
484484
},
485485
},
486486
})
@@ -526,7 +526,7 @@ func TestAccDataprocMetastoreService_dataprocMetastoreServiceScheduledBackupExam
526526
ResourceName: "google_dataproc_metastore_service.backup",
527527
ImportState: true,
528528
ImportStateVerify: true,
529-
ImportStateVerifyIgnore: []string{"labels", "location", "service_id", "terraform_labels"},
529+
ImportStateVerifyIgnore: []string{"labels", "location", "service_id", "tags", "terraform_labels"},
530530
},
531531
},
532532
})
@@ -587,7 +587,7 @@ func TestAccDataprocMetastoreService_dataprocMetastoreServiceAutoscalingMaxScali
587587
ResourceName: "google_dataproc_metastore_service.test_resource",
588588
ImportState: true,
589589
ImportStateVerify: true,
590-
ImportStateVerifyIgnore: []string{"labels", "location", "service_id", "terraform_labels"},
590+
ImportStateVerifyIgnore: []string{"labels", "location", "service_id", "tags", "terraform_labels"},
591591
},
592592
},
593593
})
@@ -638,7 +638,7 @@ func TestAccDataprocMetastoreService_dataprocMetastoreServiceAutoscalingMinAndMa
638638
ResourceName: "google_dataproc_metastore_service.test_resource",
639639
ImportState: true,
640640
ImportStateVerify: true,
641-
ImportStateVerifyIgnore: []string{"labels", "location", "service_id", "terraform_labels"},
641+
ImportStateVerifyIgnore: []string{"labels", "location", "service_id", "tags", "terraform_labels"},
642642
},
643643
},
644644
})
@@ -690,7 +690,7 @@ func TestAccDataprocMetastoreService_dataprocMetastoreServiceAutoscalingMinScali
690690
ResourceName: "google_dataproc_metastore_service.test_resource",
691691
ImportState: true,
692692
ImportStateVerify: true,
693-
ImportStateVerifyIgnore: []string{"labels", "location", "service_id", "terraform_labels"},
693+
ImportStateVerifyIgnore: []string{"labels", "location", "service_id", "tags", "terraform_labels"},
694694
},
695695
},
696696
})
@@ -741,7 +741,7 @@ func TestAccDataprocMetastoreService_dataprocMetastoreServiceAutoscalingNoLimitC
741741
ResourceName: "google_dataproc_metastore_service.test_resource",
742742
ImportState: true,
743743
ImportStateVerify: true,
744-
ImportStateVerifyIgnore: []string{"labels", "location", "service_id", "terraform_labels"},
744+
ImportStateVerifyIgnore: []string{"labels", "location", "service_id", "tags", "terraform_labels"},
745745
},
746746
},
747747
})

google/services/dataprocmetastore/resource_dataproc_metastore_service_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package dataprocmetastore_test
55
import (
66
"fmt"
77
"github.com/hashicorp/terraform-provider-google/google/acctest"
8+
"github.com/hashicorp/terraform-provider-google/google/envvar"
89
"testing"
910

1011
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
@@ -169,3 +170,58 @@ resource "google_storage_bucket" "bucket" {
169170
}
170171
`, context)
171172
}
173+
174+
func TestAccMetastoreService_tags(t *testing.T) {
175+
t.Parallel()
176+
tagKey := acctest.BootstrapSharedTestTagKey(t, "metastore-service-tagkey")
177+
context := map[string]interface{}{
178+
"random_suffix": acctest.RandString(t, 10),
179+
"org": envvar.GetTestOrgFromEnv(t),
180+
"tagKey": tagKey,
181+
"tagValue": acctest.BootstrapSharedTestTagValue(t, "metastore-service-tagvalue", tagKey),
182+
}
183+
184+
acctest.VcrTest(t, resource.TestCase{
185+
PreCheck: func() { acctest.AccTestPreCheck(t) },
186+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
187+
CheckDestroy: testAccCheckDataprocMetastoreServiceDestroyProducer(t),
188+
Steps: []resource.TestStep{
189+
{
190+
Config: testAccMetastoreServiceTags(context),
191+
},
192+
{
193+
ResourceName: "google_dataproc_metastore_service.default",
194+
ImportState: true,
195+
ImportStateVerify: true,
196+
ImportStateVerifyIgnore: []string{"service_id", "location", "labels", "terraform_labels", "tags"},
197+
},
198+
},
199+
})
200+
}
201+
202+
func testAccMetastoreServiceTags(context map[string]interface{}) string {
203+
return acctest.Nprintf(`
204+
resource "google_dataproc_metastore_service" "default" {
205+
service_id = "tf-test-my-service-%{random_suffix}"
206+
location = "us-central1"
207+
port = 9080
208+
tier = "DEVELOPER"
209+
210+
maintenance_window {
211+
hour_of_day = 2
212+
day_of_week = "SUNDAY"
213+
}
214+
215+
hive_metastore_config {
216+
version = "2.3.6"
217+
}
218+
219+
labels = {
220+
env = "test"
221+
}
222+
tags = {
223+
"%{org}/%{tagKey}" = "%{tagValue}"
224+
}
225+
}
226+
`, context)
227+
}

website/docs/r/dataproc_metastore_service.html.markdown

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,12 @@ The following arguments are supported:
499499
The configuration specifying telemetry settings for the Dataproc Metastore service. If unspecified defaults to JSON.
500500
Structure is [documented below](#nested_telemetry_config).
501501

502+
* `tags` -
503+
(Optional)
504+
A map of resource manager tags.
505+
Resource manager tag keys and values have the same definition as resource manager tags.
506+
Keys must be in the format tagKeys/{tag_key_id}, and values are in the format tagValues/{tag_value_id}.
507+
502508
* `location` -
503509
(Optional)
504510
The location where the metastore service should reside.

0 commit comments

Comments
 (0)