Skip to content

Commit 848f349

Browse files
Modify labels field for some handwritten resources (#8579) (#15548)
* Modify lables field * Fix description * Fix tests * Ignore labels for import state verify * Ignore labels for import state verify Signed-off-by: Modular Magician <[email protected]>
1 parent 27c0249 commit 848f349

17 files changed

+194
-61
lines changed

.changelog/8579.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:none
2+
3+
```

google/resource_bigquery_table_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,7 @@ func TestAccBigQueryDataTable_jsonEquivalency(t *testing.T) {
914914
ResourceName: "google_bigquery_table.test",
915915
ImportState: true,
916916
ImportStateVerify: true,
917-
ImportStateVerifyIgnore: []string{"etag", "last_modified_time", "deletion_protection"},
917+
ImportStateVerifyIgnore: []string{"etag", "last_modified_time", "deletion_protection", "labels"},
918918
},
919919
{
920920
Config: testAccBigQueryTable_jsonEqModeRemoved(datasetID, tableID),
@@ -923,7 +923,7 @@ func TestAccBigQueryDataTable_jsonEquivalency(t *testing.T) {
923923
ResourceName: "google_bigquery_table.test",
924924
ImportState: true,
925925
ImportStateVerify: true,
926-
ImportStateVerifyIgnore: []string{"etag", "last_modified_time", "deletion_protection"},
926+
ImportStateVerifyIgnore: []string{"etag", "last_modified_time", "deletion_protection", "labels"},
927927
},
928928
},
929929
})
@@ -973,7 +973,7 @@ func TestAccBigQueryDataTable_expandArray(t *testing.T) {
973973
ResourceName: "google_bigquery_table.test",
974974
ImportState: true,
975975
ImportStateVerify: true,
976-
ImportStateVerifyIgnore: []string{"etag", "last_modified_time", "deletion_protection"},
976+
ImportStateVerifyIgnore: []string{"etag", "last_modified_time", "deletion_protection", "labels"},
977977
},
978978
{
979979
Config: testAccBigQueryTable_arrayExpanded(datasetID, tableID),
@@ -982,7 +982,7 @@ func TestAccBigQueryDataTable_expandArray(t *testing.T) {
982982
ResourceName: "google_bigquery_table.test",
983983
ImportState: true,
984984
ImportStateVerify: true,
985-
ImportStateVerifyIgnore: []string{"etag", "last_modified_time", "deletion_protection"},
985+
ImportStateVerifyIgnore: []string{"etag", "last_modified_time", "deletion_protection", "labels"},
986986
},
987987
},
988988
})
@@ -1006,7 +1006,7 @@ func TestAccBigQueryTable_allowDestroy(t *testing.T) {
10061006
ResourceName: "google_bigquery_table.test",
10071007
ImportState: true,
10081008
ImportStateVerify: true,
1009-
ImportStateVerifyIgnore: []string{"deletion_protection"},
1009+
ImportStateVerifyIgnore: []string{"deletion_protection", "labels"},
10101010
},
10111011
{
10121012
Config: testAccBigQueryTable_noAllowDestroy(datasetID, tableID),

google/resource_bigtable_instance_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func TestAccBigtableInstance_cluster(t *testing.T) {
9191
ResourceName: "google_bigtable_instance.instance",
9292
ImportState: true,
9393
ImportStateVerify: true,
94-
ImportStateVerifyIgnore: []string{"deletion_protection", "instance_type", "cluster"}, // we don't read instance type back
94+
ImportStateVerifyIgnore: []string{"deletion_protection", "instance_type", "cluster", "labels"}, // we don't read instance type back
9595
},
9696
{
9797
Config: testAccBigtableInstance_clusterReordered(instanceName, 5),
@@ -110,7 +110,7 @@ func TestAccBigtableInstance_cluster(t *testing.T) {
110110
ResourceName: "google_bigtable_instance.instance",
111111
ImportState: true,
112112
ImportStateVerify: true,
113-
ImportStateVerifyIgnore: []string{"deletion_protection", "instance_type", "cluster"}, // we don't read instance type back
113+
ImportStateVerifyIgnore: []string{"deletion_protection", "instance_type", "cluster", "labels"}, // we don't read instance type back
114114
},
115115
},
116116
})
@@ -430,7 +430,7 @@ func TestAccBigtableInstance_MultipleClustersSameID(t *testing.T) {
430430
ResourceName: "google_bigtable_instance.instance",
431431
ImportState: true,
432432
ImportStateVerify: true,
433-
ImportStateVerifyIgnore: []string{"deletion_protection", "instance_type"}, // we don't read instance type back
433+
ImportStateVerifyIgnore: []string{"deletion_protection", "instance_type", "labels"}, // we don't read instance type back
434434
},
435435
{
436436
Config: testAccBigtableInstance_multipleClustersSameID(instanceName),

google/resource_cloudfunctions_function_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func TestAccCloudFunctionsFunction_basic(t *testing.T) {
8585
ResourceName: funcResourceName,
8686
ImportState: true,
8787
ImportStateVerify: true,
88-
ImportStateVerifyIgnore: []string{"build_environment_variables"},
88+
ImportStateVerifyIgnore: []string{"build_environment_variables", "labels"},
8989
},
9090
},
9191
})
@@ -122,7 +122,7 @@ func TestAccCloudFunctionsFunction_update(t *testing.T) {
122122
ResourceName: funcResourceName,
123123
ImportState: true,
124124
ImportStateVerify: true,
125-
ImportStateVerifyIgnore: []string{"build_environment_variables"},
125+
ImportStateVerifyIgnore: []string{"build_environment_variables", "labels"},
126126
},
127127
{
128128
Config: testAccCloudFunctionsFunction_updated(functionName, bucketName, zipFileUpdatePath, random_suffix),
@@ -155,7 +155,7 @@ func TestAccCloudFunctionsFunction_update(t *testing.T) {
155155
ResourceName: funcResourceName,
156156
ImportState: true,
157157
ImportStateVerify: true,
158-
ImportStateVerifyIgnore: []string{"build_environment_variables"},
158+
ImportStateVerifyIgnore: []string{"build_environment_variables", "labels"},
159159
},
160160
},
161161
})
@@ -371,7 +371,7 @@ func TestAccCloudFunctionsFunction_vpcConnector(t *testing.T) {
371371
ResourceName: funcResourceName,
372372
ImportState: true,
373373
ImportStateVerify: true,
374-
ImportStateVerifyIgnore: []string{"build_environment_variables"},
374+
ImportStateVerifyIgnore: []string{"build_environment_variables", "labels"},
375375
},
376376
{
377377
Config: testAccCloudFunctionsFunction_vpcConnector(projectNumber, networkName, functionName, bucketName, zipFilePath, "10.20.0.0/28", vpcConnectorName+"-update"),
@@ -380,7 +380,7 @@ func TestAccCloudFunctionsFunction_vpcConnector(t *testing.T) {
380380
ResourceName: funcResourceName,
381381
ImportState: true,
382382
ImportStateVerify: true,
383-
ImportStateVerifyIgnore: []string{"build_environment_variables"},
383+
ImportStateVerifyIgnore: []string{"build_environment_variables", "labels"},
384384
},
385385
},
386386
})

google/resource_composer_environment_test.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,10 @@ func TestAccComposerEnvironment_update(t *testing.T) {
9898
Config: testAccComposerEnvironment_update(envName, network, subnetwork),
9999
},
100100
{
101-
ResourceName: "google_composer_environment.test",
102-
ImportState: true,
103-
ImportStateVerify: true,
101+
ResourceName: "google_composer_environment.test",
102+
ImportState: true,
103+
ImportStateVerify: true,
104+
ImportStateVerifyIgnore: []string{"labels"},
104105
},
105106
// This is a terrible clean-up step in order to get destroy to succeed,
106107
// due to dangling firewall rules left by the Composer Environment blocking network deletion.

google/resource_compute_instance_template_test.go

+20-15
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ func TestAccComputeInstanceTemplate_basic(t *testing.T) {
4444
),
4545
},
4646
{
47-
ResourceName: "google_compute_instance_template.foobar",
48-
ImportState: true,
49-
ImportStateVerify: true,
47+
ResourceName: "google_compute_instance_template.foobar",
48+
ImportState: true,
49+
ImportStateVerify: true,
50+
ImportStateVerifyIgnore: []string{"labels"},
5051
},
5152
},
5253
})
@@ -70,9 +71,10 @@ func TestAccComputeInstanceTemplate_imageShorthand(t *testing.T) {
7071
),
7172
},
7273
{
73-
ResourceName: "google_compute_instance_template.foobar",
74-
ImportState: true,
75-
ImportStateVerify: true,
74+
ResourceName: "google_compute_instance_template.foobar",
75+
ImportState: true,
76+
ImportStateVerify: true,
77+
ImportStateVerifyIgnore: []string{"labels"},
7678
},
7779
},
7880
})
@@ -545,9 +547,10 @@ func TestAccComputeInstanceTemplate_EncryptKMS(t *testing.T) {
545547
),
546548
},
547549
{
548-
ResourceName: "google_compute_instance_template.foobar",
549-
ImportState: true,
550-
ImportStateVerify: true,
550+
ResourceName: "google_compute_instance_template.foobar",
551+
ImportState: true,
552+
ImportStateVerify: true,
553+
ImportStateVerifyIgnore: []string{"labels"},
551554
},
552555
},
553556
})
@@ -854,9 +857,10 @@ func TestAccComputeInstanceTemplate_diskResourcePolicies(t *testing.T) {
854857
),
855858
},
856859
{
857-
ResourceName: "google_compute_instance_template.foobar",
858-
ImportState: true,
859-
ImportStateVerify: true,
860+
ResourceName: "google_compute_instance_template.foobar",
861+
ImportState: true,
862+
ImportStateVerify: true,
863+
ImportStateVerifyIgnore: []string{"labels"},
860864
},
861865
},
862866
})
@@ -931,9 +935,10 @@ func TestAccComputeInstanceTemplate_managedEnvoy(t *testing.T) {
931935
),
932936
},
933937
{
934-
ResourceName: "google_compute_instance_template.foobar",
935-
ImportState: true,
936-
ImportStateVerify: true,
938+
ResourceName: "google_compute_instance_template.foobar",
939+
ImportState: true,
940+
ImportStateVerify: true,
941+
ImportStateVerifyIgnore: []string{"labels"},
937942
},
938943
},
939944
})

google/resource_compute_instance_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func TestAccComputeInstance_basic1(t *testing.T) {
136136
testAccCheckComputeInstanceHasConfiguredDeletionProtection(&instance, false),
137137
),
138138
},
139-
computeInstanceImportStep("us-central1-a", instanceName, []string{"metadata.baz", "metadata.foo", "desired_status", "current_status"}),
139+
computeInstanceImportStep("us-central1-a", instanceName, []string{"metadata.baz", "metadata.foo", "desired_status", "current_status", "labels"}),
140140
},
141141
})
142142
}
@@ -1398,7 +1398,7 @@ func TestAccComputeInstance_forceChangeMachineTypeManually(t *testing.T) {
13981398
),
13991399
ExpectNonEmptyPlan: true,
14001400
},
1401-
computeInstanceImportStep("us-central1-a", instanceName, []string{"metadata.baz", "metadata.foo", "desired_status", "current_status"}),
1401+
computeInstanceImportStep("us-central1-a", instanceName, []string{"metadata.baz", "metadata.foo", "desired_status", "current_status", "labels"}),
14021402
},
14031403
})
14041404
}

google/resource_google_project_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func TestAccProject_labels(t *testing.T) {
137137
ResourceName: "google_project.acceptance",
138138
ImportState: true,
139139
ImportStateVerify: true,
140-
ImportStateVerifyIgnore: []string{"skip_delete"},
140+
ImportStateVerifyIgnore: []string{"skip_delete", "labels"},
141141
},
142142
// update project with labels
143143
{

google/services/bigquery/resource_bigquery_table.go

+15-4
Original file line numberDiff line numberDiff line change
@@ -769,12 +769,20 @@ func ResourceBigQueryTable() *schema.Resource {
769769
// start with a letter and each label in the list must have a different
770770
// key.
771771
"labels": {
772+
Type: schema.TypeMap,
773+
Optional: true,
774+
Elem: &schema.Schema{Type: schema.TypeString},
775+
Description: `A mapping of labels to assign to the resource.
776+
777+
**Note**: This field is non-authoritative, and will only manage the labels present in your configuration.
778+
Please refer to the field 'effective_labels' for all of the labels present on the resource.`,
779+
},
780+
"effective_labels": {
772781
Type: schema.TypeMap,
773-
Optional: true,
782+
Computed: true,
783+
Description: `All of labels (key/value pairs) present on the resource in GCP, including the labels configured through Terraform, other clients and services.`,
774784
Elem: &schema.Schema{Type: schema.TypeString},
775-
Description: `A mapping of labels to assign to the resource.`,
776785
},
777-
778786
// Schema: [Optional] Describes the schema of this table.
779787
// Schema is mutually exclusive with View and Materialized View.
780788
"schema": {
@@ -1245,9 +1253,12 @@ func resourceBigQueryTableRead(d *schema.ResourceData, meta interface{}) error {
12451253
if err := d.Set("max_staleness", res.MaxStaleness); err != nil {
12461254
return fmt.Errorf("Error setting max_staleness: %s", err)
12471255
}
1248-
if err := d.Set("labels", res.Labels); err != nil {
1256+
if err := d.Set("labels", tpgresource.FlattenLabels(res.Labels, d)); err != nil {
12491257
return fmt.Errorf("Error setting labels: %s", err)
12501258
}
1259+
if err := d.Set("effective_labels", res.Labels); err != nil {
1260+
return fmt.Errorf("Error setting effective_labels: %s", err)
1261+
}
12511262
if err := d.Set("creation_time", res.CreationTime); err != nil {
12521263
return fmt.Errorf("Error setting creation_time: %s", err)
12531264
}

google/services/bigtable/resource_bigtable_instance.go

+16-3
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,20 @@ func ResourceBigtableInstance() *schema.Resource {
155155
},
156156

157157
"labels": {
158+
Type: schema.TypeMap,
159+
Optional: true,
160+
Elem: &schema.Schema{Type: schema.TypeString},
161+
Description: `A mapping of labels to assign to the resource.
162+
163+
**Note**: This field is non-authoritative, and will only manage the labels present in your configuration.
164+
Please refer to the field 'effective_labels' for all of the labels present on the resource.`,
165+
},
166+
167+
"effective_labels": {
158168
Type: schema.TypeMap,
159-
Optional: true,
169+
Computed: true,
170+
Description: `All of labels (key/value pairs) present on the resource in GCP, including the labels configured through Terraform, other clients and services.`,
160171
Elem: &schema.Schema{Type: schema.TypeString},
161-
Description: `A mapping of labels to assign to the resource.`,
162172
},
163173

164174
"project": {
@@ -303,9 +313,12 @@ func resourceBigtableInstanceRead(d *schema.ResourceData, meta interface{}) erro
303313
if err := d.Set("display_name", instance.DisplayName); err != nil {
304314
return fmt.Errorf("Error setting display_name: %s", err)
305315
}
306-
if err := d.Set("labels", instance.Labels); err != nil {
316+
if err := d.Set("labels", tpgresource.FlattenLabels(instance.Labels, d)); err != nil {
307317
return fmt.Errorf("Error setting labels: %s", err)
308318
}
319+
if err := d.Set("effective_labels", instance.Labels); err != nil {
320+
return fmt.Errorf("Error setting effective_labels: %s", err)
321+
}
309322
// Don't set instance_type: we don't want to detect drift on it because it can
310323
// change under-the-hood.
311324

google/services/cloudfunctions/resource_cloudfunctions_function.go

+15-2
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,17 @@ func ResourceCloudFunctionsFunction() *schema.Resource {
259259
Type: schema.TypeMap,
260260
ValidateFunc: labelKeyValidator,
261261
Optional: true,
262-
Description: `A set of key/value label pairs to assign to the function. Label keys must follow the requirements at https://cloud.google.com/resource-manager/docs/creating-managing-labels#requirements.`,
262+
Description: `A set of key/value label pairs to assign to the function. Label keys must follow the requirements at https://cloud.google.com/resource-manager/docs/creating-managing-labels#requirements.
263+
264+
**Note**: This field is non-authoritative, and will only manage the labels present in your configuration.
265+
Please refer to the field 'effective_labels' for all of the labels present on the resource.`,
266+
},
267+
268+
"effective_labels": {
269+
Type: schema.TypeMap,
270+
Computed: true,
271+
Description: `All of labels (key/value pairs) present on the resource in GCP, including the labels configured through Terraform, other clients and services.`,
272+
Elem: &schema.Schema{Type: schema.TypeString},
263273
},
264274

265275
"runtime": {
@@ -672,9 +682,12 @@ func resourceCloudFunctionsRead(d *schema.ResourceData, meta interface{}) error
672682
if err := d.Set("ingress_settings", function.IngressSettings); err != nil {
673683
return fmt.Errorf("Error setting ingress_settings: %s", err)
674684
}
675-
if err := d.Set("labels", function.Labels); err != nil {
685+
if err := d.Set("labels", tpgresource.FlattenLabels(function.Labels, d)); err != nil {
676686
return fmt.Errorf("Error setting labels: %s", err)
677687
}
688+
if err := d.Set("effective_labels", function.Labels); err != nil {
689+
return fmt.Errorf("Error setting effective_labels: %s", err)
690+
}
678691
if err := d.Set("runtime", function.Runtime); err != nil {
679692
return fmt.Errorf("Error setting runtime: %s", err)
680693
}

google/services/composer/resource_composer_environment.go

+16-3
Original file line numberDiff line numberDiff line change
@@ -800,10 +800,20 @@ func ResourceComposerEnvironment() *schema.Resource {
800800
},
801801
},
802802
"labels": {
803+
Type: schema.TypeMap,
804+
Optional: true,
805+
Elem: &schema.Schema{Type: schema.TypeString},
806+
Description: `User-defined labels for this environment. The labels map can contain no more than 64 entries. Entries of the labels map are UTF8 strings that comply with the following restrictions: Label keys must be between 1 and 63 characters long and must conform to the following regular expression: [a-z]([-a-z0-9]*[a-z0-9])?. Label values must be between 0 and 63 characters long and must conform to the regular expression ([a-z]([-a-z0-9]*[a-z0-9])?)?. No more than 64 labels can be associated with a given environment. Both keys and values must be <= 128 bytes in size.
807+
808+
**Note**: This field is non-authoritative, and will only manage the labels present in your configuration.
809+
Please refer to the field 'effective_labels' for all of the labels present on the resource.`,
810+
},
811+
812+
"effective_labels": {
803813
Type: schema.TypeMap,
804-
Optional: true,
814+
Computed: true,
815+
Description: `All of labels (key/value pairs) present on the resource in GCP, including the labels configured through Terraform, other clients and services.`,
805816
Elem: &schema.Schema{Type: schema.TypeString},
806-
Description: `User-defined labels for this environment. The labels map can contain no more than 64 entries. Entries of the labels map are UTF8 strings that comply with the following restrictions: Label keys must be between 1 and 63 characters long and must conform to the following regular expression: [a-z]([-a-z0-9]*[a-z0-9])?. Label values must be between 0 and 63 characters long and must conform to the regular expression ([a-z]([-a-z0-9]*[a-z0-9])?)?. No more than 64 labels can be associated with a given environment. Both keys and values must be <= 128 bytes in size.`,
807817
},
808818
},
809819
UseJSONNumber: true,
@@ -907,7 +917,10 @@ func resourceComposerEnvironmentRead(d *schema.ResourceData, meta interface{}) e
907917
if err := d.Set("config", flattenComposerEnvironmentConfig(res.Config)); err != nil {
908918
return fmt.Errorf("Error setting Environment: %s", err)
909919
}
910-
if err := d.Set("labels", res.Labels); err != nil {
920+
if err := d.Set("labels", tpgresource.FlattenLabels(res.Labels, d)); err != nil {
921+
return fmt.Errorf("Error setting Environment: %s", err)
922+
}
923+
if err := d.Set("effective_labels", res.Labels); err != nil {
911924
return fmt.Errorf("Error setting Environment: %s", err)
912925
}
913926
return nil

0 commit comments

Comments
 (0)