Skip to content

Commit

Permalink
Labels compute instance template (#9051) (#15993)
Browse files Browse the repository at this point in the history
* Apply labels model to compute instance template

* Check if terraform_labels and effective_labels are in schema

* Test out of band labels

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Sep 25, 2023
1 parent 6b55257 commit 9ce1711
Show file tree
Hide file tree
Showing 199 changed files with 1,039 additions and 304 deletions.
3 changes: 3 additions & 0 deletions .changelog/9051.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:none

```
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,13 @@ If CIDR subnets overlap between networks, domain creation will fail.`,
Set: schema.HashString,
},
"labels": {
Type: schema.TypeMap,
Optional: true,
Description: `Resource labels that can contain user-provided metadata`,
Elem: &schema.Schema{Type: schema.TypeString},
Type: schema.TypeMap,
Optional: true,
Description: `Resource labels that can contain user-provided metadata
**Note**: This field is non-authoritative, and will only manage the labels present in your configuration.
Please refer to the field 'effective_labels' for all of the labels present on the resource.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"effective_labels": {
Type: schema.TypeMap,
Expand Down
11 changes: 7 additions & 4 deletions google/services/alloydb/resource_alloydb_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,13 @@ func ResourceAlloydbBackup() *schema.Resource {
},
},
"labels": {
Type: schema.TypeMap,
Optional: true,
Description: `User-defined labels for the alloydb backup.`,
Elem: &schema.Schema{Type: schema.TypeString},
Type: schema.TypeMap,
Optional: true,
Description: `User-defined labels for the alloydb backup.
**Note**: This field is non-authoritative, and will only manage the labels present in your configuration.
Please refer to the field 'effective_labels' for all of the labels present on the resource.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"create_time": {
Type: schema.TypeString,
Expand Down
11 changes: 7 additions & 4 deletions google/services/alloydb/resource_alloydb_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,13 @@ If not set, defaults to 14 days.`,
},
},
"labels": {
Type: schema.TypeMap,
Optional: true,
Description: `User-defined labels for the alloydb cluster.`,
Elem: &schema.Schema{Type: schema.TypeString},
Type: schema.TypeMap,
Optional: true,
Description: `User-defined labels for the alloydb cluster.
**Note**: This field is non-authoritative, and will only manage the labels present in your configuration.
Please refer to the field 'effective_labels' for all of the labels present on the resource.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"network": {
Type: schema.TypeString,
Expand Down
11 changes: 7 additions & 4 deletions google/services/alloydb/resource_alloydb_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,13 @@ can have regional availability (nodes are present in 2 or more zones in a region
Description: `The Compute Engine zone that the instance should serve from, per https://cloud.google.com/compute/docs/regions-zones This can ONLY be specified for ZONAL instances. If present for a REGIONAL instance, an error will be thrown. If this is absent for a ZONAL instance, instance is created in a random zone with available capacity.`,
},
"labels": {
Type: schema.TypeMap,
Optional: true,
Description: `User-defined labels for the alloydb instance.`,
Elem: &schema.Schema{Type: schema.TypeString},
Type: schema.TypeMap,
Optional: true,
Description: `User-defined labels for the alloydb instance.
**Note**: This field is non-authoritative, and will only manage the labels present in your configuration.
Please refer to the field 'effective_labels' for all of the labels present on the resource.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"machine_config": {
Type: schema.TypeList,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ This value may not be changed after the Repository has been created.`,
This field may contain up to 64 entries. Label keys and values may be no
longer than 63 characters. Label keys must begin with a lowercase letter
and may only contain lowercase letters, numeric characters, underscores,
and dashes.`,
and dashes.
**Note**: This field is non-authoritative, and will only manage the labels present in your configuration.
Please refer to the field 'effective_labels' for all of the labels present on the resource.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"location": {
Expand Down
12 changes: 8 additions & 4 deletions google/services/beyondcorp/resource_beyondcorp_app_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,14 @@ for a list of possible values.`,
},
},
"labels": {
Type: schema.TypeMap,
Optional: true,
Description: `Resource labels to represent user provided metadata.`,
Elem: &schema.Schema{Type: schema.TypeString},
Type: schema.TypeMap,
Optional: true,
Description: `Resource labels to represent user provided metadata.
**Note**: This field is non-authoritative, and will only manage the labels present in your configuration.
Please refer to the field 'effective_labels' for all of the labels present on the resource.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"region": {
Type: schema.TypeString,
Expand Down
12 changes: 8 additions & 4 deletions google/services/beyondcorp/resource_beyondcorp_app_connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,14 @@ func ResourceBeyondcorpAppConnector() *schema.Resource {
Description: `An arbitrary user-provided name for the AppConnector.`,
},
"labels": {
Type: schema.TypeMap,
Optional: true,
Description: `Resource labels to represent user provided metadata.`,
Elem: &schema.Schema{Type: schema.TypeString},
Type: schema.TypeMap,
Optional: true,
Description: `Resource labels to represent user provided metadata.
**Note**: This field is non-authoritative, and will only manage the labels present in your configuration.
Please refer to the field 'effective_labels' for all of the labels present on the resource.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"region": {
Type: schema.TypeString,
Expand Down
14 changes: 9 additions & 5 deletions google/services/beyondcorp/resource_beyondcorp_app_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,15 @@ func ResourceBeyondcorpAppGateway() *schema.Resource {
Default: "HOST_TYPE_UNSPECIFIED",
},
"labels": {
Type: schema.TypeMap,
Optional: true,
ForceNew: true,
Description: `Resource labels to represent user provided metadata.`,
Elem: &schema.Schema{Type: schema.TypeString},
Type: schema.TypeMap,
Optional: true,
ForceNew: true,
Description: `Resource labels to represent user provided metadata.
**Note**: This field is non-authoritative, and will only manage the labels present in your configuration.
Please refer to the field 'effective_labels' for all of the labels present on the resource.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"region": {
Type: schema.TypeString,
Expand Down
3 changes: 2 additions & 1 deletion google/services/bigquery/resource_bigquery_dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ case-sensitive. This field does not affect routine references.`,
Type: schema.TypeMap,
Optional: true,
Description: `The labels associated with this dataset. You can use these to
organize and group your datasets
organize and group your datasets.
**Note**: This field is non-authoritative, and will only manage the labels present in your configuration.
Please refer to the field 'effective_labels' for all of the labels present on the resource.`,
Expand Down
81 changes: 81 additions & 0 deletions google/services/bigquery/resource_bigquery_dataset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,49 @@ func TestAccBigQueryDataset_withProvider5(t *testing.T) {
})
}

func TestAccBigQueryDataset_withOutOfBandLabels(t *testing.T) {
acctest.SkipIfVcr(t)
t.Parallel()

datasetID := fmt.Sprintf("tf_test_%s", acctest.RandString(t, 10))

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckBigQueryDatasetDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccBigQueryDataset(datasetID),
Check: addOutOfBandLabels(t, datasetID),
},
{
ResourceName: "google_bigquery_dataset.test",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"delete_contents_on_destroy", "labels", "terraform_labels"},
},
{
Config: testAccBigQueryDatasetUpdated(datasetID),
},
{
ResourceName: "google_bigquery_dataset.test",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"delete_contents_on_destroy", "labels", "terraform_labels"},
},
{
Config: testAccBigQueryDatasetUpdated_withOutOfBandLabels(datasetID),
},
{
ResourceName: "google_bigquery_dataset.test",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"delete_contents_on_destroy", "labels", "terraform_labels"},
},
},
})
}

func TestAccBigQueryDataset_datasetWithContents(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -304,6 +347,25 @@ func testAccAddTable(t *testing.T, datasetID string, tableID string) resource.Te
}
}

func addOutOfBandLabels(t *testing.T, datasetID string) resource.TestCheckFunc {
// Not actually a check, but adds labels independently of terraform
return func(s *terraform.State) error {
config := acctest.GoogleProviderConfig(t)

dataset, err := config.NewBigQueryClient(config.UserAgent).Datasets.Get(config.Project, datasetID).Do()
if err != nil {
return fmt.Errorf("Could not get dataset with ID %s", datasetID)
}

dataset.Labels["outband_key"] = "test"
_, err = config.NewBigQueryClient(config.UserAgent).Datasets.Patch(config.Project, datasetID, dataset).Do()
if err != nil {
return fmt.Errorf("Could not update labele for the dataset")
}
return nil
}
}

func testAccBigQueryDataset_withoutLabels(datasetID string) string {
return fmt.Sprintf(`
resource "google_bigquery_dataset" "test" {
Expand Down Expand Up @@ -353,6 +415,25 @@ resource "google_bigquery_dataset" "test" {
`, datasetID)
}

func testAccBigQueryDatasetUpdated_withOutOfBandLabels(datasetID string) string {
return fmt.Sprintf(`
resource "google_bigquery_dataset" "test" {
dataset_id = "%s"
friendly_name = "bar"
description = "This is a bar description"
location = "EU"
default_partition_expiration_ms = 7200000
default_table_expiration_ms = 7200000
labels = {
env = "bar"
default_table_expiration_ms = 7200000
outband_key = "test-update"
}
}
`, datasetID)
}

func testAccBigQueryDatasetUpdated2(datasetID string) string {
return fmt.Sprintf(`
resource "google_bigquery_dataset" "test" {
Expand Down
14 changes: 9 additions & 5 deletions google/services/bigquery/resource_bigquery_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,15 @@ or of the form 'projects/{{project}}/datasets/{{dataset_id}}/tables/{{table_id}}
Description: `Job timeout in milliseconds. If this time limit is exceeded, BigQuery may attempt to terminate the job.`,
},
"labels": {
Type: schema.TypeMap,
Optional: true,
ForceNew: true,
Description: `The labels associated with this job. You can use these to organize and group your jobs.`,
Elem: &schema.Schema{Type: schema.TypeString},
Type: schema.TypeMap,
Optional: true,
ForceNew: true,
Description: `The labels associated with this job. You can use these to organize and group your jobs.
**Note**: This field is non-authoritative, and will only manage the labels present in your configuration.
Please refer to the field 'effective_labels' for all of the labels present on the resource.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"load": {
Type: schema.TypeList,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,13 @@ and all following characters must be a dash, underscore, letter or digit.`,
Description: `A human-readable description of the resource.`,
},
"labels": {
Type: schema.TypeMap,
Optional: true,
Description: `Set of label tags associated with the Certificate resource.`,
Elem: &schema.Schema{Type: schema.TypeString},
Type: schema.TypeMap,
Optional: true,
Description: `Set of label tags associated with the Certificate resource.
**Note**: This field is non-authoritative, and will only manage the labels present in your configuration.
Please refer to the field 'effective_labels' for all of the labels present on the resource.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"location": {
Type: schema.TypeString,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@ the certificate has been issued and at least 7 days before it expires.`,
Optional: true,
ForceNew: true,
Description: `'Set of label tags associated with the CertificateIssuanceConfig resource.
An object containing a list of "key": value pairs. Example: { "name": "wrench", "count": "3" }.`,
An object containing a list of "key": value pairs. Example: { "name": "wrench", "count": "3" }.
**Note**: This field is non-authoritative, and will only manage the labels present in your configuration.
Please refer to the field 'effective_labels' for all of the labels present on the resource.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"location": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,14 @@ globally and match the pattern 'projects/*/locations/*/certificateMaps/*'.`,
Description: `A human-readable description of the resource.`,
},
"labels": {
Type: schema.TypeMap,
Optional: true,
Description: `Set of labels associated with a Certificate Map resource.`,
Elem: &schema.Schema{Type: schema.TypeString},
Type: schema.TypeMap,
Optional: true,
Description: `Set of labels associated with a Certificate Map resource.
**Note**: This field is non-authoritative, and will only manage the labels present in your configuration.
Please refer to the field 'effective_labels' for all of the labels present on the resource.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"create_time": {
Type: schema.TypeString,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ selecting a proper certificate.`,
Optional: true,
Description: `Set of labels associated with a Certificate Map Entry.
An object containing a list of "key": value pairs.
Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }.`,
Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }.
**Note**: This field is non-authoritative, and will only manage the labels present in your configuration.
Please refer to the field 'effective_labels' for all of the labels present on the resource.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"matcher": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,13 @@ and all following characters must be a dash, underscore, letter or digit.`,
Description: `A human-readable description of the resource.`,
},
"labels": {
Type: schema.TypeMap,
Optional: true,
Description: `Set of label tags associated with the DNS Authorization resource.`,
Elem: &schema.Schema{Type: schema.TypeString},
Type: schema.TypeMap,
Optional: true,
Description: `Set of label tags associated with the DNS Authorization resource.
**Note**: This field is non-authoritative, and will only manage the labels present in your configuration.
Please refer to the field 'effective_labels' for all of the labels present on the resource.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"dns_resource_record": {
Type: schema.TypeList,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,14 @@ func ResourceCertificateManagerTrustConfig() *schema.Resource {
Description: `One or more paragraphs of text description of a trust config.`,
},
"labels": {
Type: schema.TypeMap,
Optional: true,
ForceNew: true,
Description: `Set of label tags associated with the trust config.`,
Elem: &schema.Schema{Type: schema.TypeString},
Type: schema.TypeMap,
Optional: true,
ForceNew: true,
Description: `Set of label tags associated with the trust config.
**Note**: This field is non-authoritative, and will only manage the labels present in your configuration.
Please refer to the field 'effective_labels' for all of the labels present on the resource.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"trust_stores": {
Type: schema.TypeList,
Expand Down
Loading

0 comments on commit 9ce1711

Please sign in to comment.