From 128abfd48bc854198f87fab09e61331fa1e1562f Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Fri, 22 Sep 2023 19:17:07 +0000 Subject: [PATCH] Make labels field have all labels in data sources (#9037) Signed-off-by: Modular Magician --- .changelog/9037.txt | 3 +++ ...ata_source_artifact_registry_repository.go | 4 +++ ...ource_artifact_registry_repository_test.go | 4 +-- ...source_google_beyondcorp_app_connection.go | 4 +++ ...e_google_beyondcorp_app_connection_test.go | 3 +++ ..._source_google_beyondcorp_app_connector.go | 4 +++ ...ce_google_beyondcorp_app_connector_test.go | 3 +++ ...ta_source_google_beyondcorp_app_gateway.go | 4 +++ ...urce_google_beyondcorp_app_gateway_test.go | 3 +++ ...a_source_google_cloudfunctions_function.go | 4 +++ ...rce_google_cloudfunctions_function_test.go | 3 +++ ..._source_google_cloudfunctions2_function.go | 4 +++ ...ce_google_cloudfunctions2_function_test.go | 4 +-- ...data_source_google_composer_environment.go | 4 +++ ...source_google_composer_environment_test.go | 5 ++++ .../data_source_google_compute_disk.go | 4 +++ .../data_source_google_compute_disk_test.go | 5 +++- ...a_source_google_compute_forwarding_rule.go | 4 +++ ...rce_google_compute_forwarding_rule_test.go | 3 +++ .../data_source_google_compute_instance.go | 4 +++ .../data_source_google_compute_snapshot.go | 5 +++- ...ata_source_google_compute_snapshot_test.go | 6 ++--- ...e_google_global_compute_forwarding_rule.go | 4 +++ ...gle_global_compute_forwarding_rule_test.go | 3 +++ .../data_source_dataproc_metastore_service.go | 4 +++ ..._source_dataproc_metastore_service_test.go | 4 +++ .../kms/data_source_google_kms_crypto_key.go | 4 +++ .../data_source_certificate_authority.go | 4 +++ .../data_source_certificate_authority_test.go | 3 +++ .../pubsub/data_source_pubsub_subscription.go | 4 +++ .../data_source_pubsub_subscription_test.go | 3 +++ .../pubsub/data_source_pubsub_topic.go | 4 +++ .../pubsub/data_source_pubsub_topic_test.go | 3 +++ .../redis/data_source_redis_instance.go | 4 +++ .../redis/data_source_redis_instance_test.go | 4 +++ .../data_source_google_project.go | 4 +++ .../data_source_google_project_test.go | 3 +++ .../data_source_secret_manager_secret.go | 8 ++++++ .../data_source_secret_manager_secret_test.go | 6 ++++- .../spanner/data_source_spanner_instance.go | 4 +++ .../vertexai/data_source_vertex_ai_index.go | 4 +++ .../data_source_vertex_ai_index_test.go | 2 -- google/tpgresource/annotations.go | 19 ++++++++++++++ google/tpgresource/labels.go | 26 +++++++++++++++++++ .../d/cloudfunctions_function.html.markdown | 2 +- website/docs/d/compute_disk.html.markdown | 2 +- website/docs/d/compute_image.html.markdown | 2 +- website/docs/d/compute_instance.html.markdown | 2 +- .../d/compute_instance_template.html.markdown | 3 +-- .../r/cloudfunctions_function.html.markdown | 3 +++ .../docs/r/composer_environment.html.markdown | 3 +++ website/docs/r/compute_instance.html.markdown | 2 ++ .../r/compute_instance_template.html.markdown | 6 +++++ website/docs/r/dataproc_job.html.markdown | 2 ++ website/docs/r/google_project.html.markdown | 2 ++ 55 files changed, 222 insertions(+), 18 deletions(-) create mode 100644 .changelog/9037.txt diff --git a/.changelog/9037.txt b/.changelog/9037.txt new file mode 100644 index 00000000000..8ec013c0699 --- /dev/null +++ b/.changelog/9037.txt @@ -0,0 +1,3 @@ +```release-note:none + +``` diff --git a/google/services/artifactregistry/data_source_artifact_registry_repository.go b/google/services/artifactregistry/data_source_artifact_registry_repository.go index 215d57b07a7..c635450f267 100644 --- a/google/services/artifactregistry/data_source_artifact_registry_repository.go +++ b/google/services/artifactregistry/data_source_artifact_registry_repository.go @@ -48,6 +48,10 @@ func dataSourceArtifactRegistryRepositoryRead(d *schema.ResourceData, meta inter return err } + if err := tpgresource.SetDataSourceLabels(d); err != nil { + return err + } + if d.Id() == "" { return fmt.Errorf("%s not found", id) } diff --git a/google/services/artifactregistry/data_source_artifact_registry_repository_test.go b/google/services/artifactregistry/data_source_artifact_registry_repository_test.go index 352b2b27c5b..32842918c6f 100644 --- a/google/services/artifactregistry/data_source_artifact_registry_repository_test.go +++ b/google/services/artifactregistry/data_source_artifact_registry_repository_test.go @@ -25,8 +25,8 @@ func TestAccDataSourceGoogleArtifactRegistryRepositoryConfig(t *testing.T) { { Config: testAccDataSourceGoogleArtifactRegistryRepositoryConfig(context), Check: resource.ComposeTestCheckFunc( - acctest.CheckDataSourceStateMatchesResourceStateWithIgnores(funcDataName, - "google_artifact_registry_repository.my-repo", map[string]struct{}{"labels.%": {}, "terraform_labels.%": {}}), + acctest.CheckDataSourceStateMatchesResourceState(funcDataName, + "google_artifact_registry_repository.my-repo"), ), }, }, diff --git a/google/services/beyondcorp/data_source_google_beyondcorp_app_connection.go b/google/services/beyondcorp/data_source_google_beyondcorp_app_connection.go index 11a6489c4a3..558a3cba3af 100644 --- a/google/services/beyondcorp/data_source_google_beyondcorp_app_connection.go +++ b/google/services/beyondcorp/data_source_google_beyondcorp_app_connection.go @@ -48,6 +48,10 @@ func dataSourceGoogleBeyondcorpAppConnectionRead(d *schema.ResourceData, meta in return err } + if err := tpgresource.SetDataSourceLabels(d); err != nil { + return err + } + if d.Id() == "" { return fmt.Errorf("%s not found", id) } diff --git a/google/services/beyondcorp/data_source_google_beyondcorp_app_connection_test.go b/google/services/beyondcorp/data_source_google_beyondcorp_app_connection_test.go index 8fd3b178835..aaf4679dd69 100644 --- a/google/services/beyondcorp/data_source_google_beyondcorp_app_connection_test.go +++ b/google/services/beyondcorp/data_source_google_beyondcorp_app_connection_test.go @@ -78,6 +78,9 @@ resource "google_beyondcorp_app_connection" "foo" { port = 8080 } connectors = [google_beyondcorp_app_connector.app_connector.id] + labels = { + my-label = "my-label-value" + } } data "google_beyondcorp_app_connection" "foo" { diff --git a/google/services/beyondcorp/data_source_google_beyondcorp_app_connector.go b/google/services/beyondcorp/data_source_google_beyondcorp_app_connector.go index 9a855d3cd6b..288e37d574c 100644 --- a/google/services/beyondcorp/data_source_google_beyondcorp_app_connector.go +++ b/google/services/beyondcorp/data_source_google_beyondcorp_app_connector.go @@ -48,6 +48,10 @@ func dataSourceGoogleBeyondcorpAppConnectorRead(d *schema.ResourceData, meta int return err } + if err := tpgresource.SetDataSourceLabels(d); err != nil { + return err + } + if d.Id() == "" { return fmt.Errorf("%s not found", id) } diff --git a/google/services/beyondcorp/data_source_google_beyondcorp_app_connector_test.go b/google/services/beyondcorp/data_source_google_beyondcorp_app_connector_test.go index 9a6114e51a7..6d112fc375d 100644 --- a/google/services/beyondcorp/data_source_google_beyondcorp_app_connector_test.go +++ b/google/services/beyondcorp/data_source_google_beyondcorp_app_connector_test.go @@ -181,6 +181,9 @@ resource "google_beyondcorp_app_connector" "foo" { email = google_service_account.service_account.email } } + labels = { + my-label = "my-label-value" + } } data "google_beyondcorp_app_connector" "foo" { diff --git a/google/services/beyondcorp/data_source_google_beyondcorp_app_gateway.go b/google/services/beyondcorp/data_source_google_beyondcorp_app_gateway.go index e5111a3aa7a..867ae88426c 100644 --- a/google/services/beyondcorp/data_source_google_beyondcorp_app_gateway.go +++ b/google/services/beyondcorp/data_source_google_beyondcorp_app_gateway.go @@ -48,6 +48,10 @@ func dataSourceGoogleBeyondcorpAppGatewayRead(d *schema.ResourceData, meta inter return err } + if err := tpgresource.SetDataSourceLabels(d); err != nil { + return err + } + if d.Id() == "" { return fmt.Errorf("%s not found", id) } diff --git a/google/services/beyondcorp/data_source_google_beyondcorp_app_gateway_test.go b/google/services/beyondcorp/data_source_google_beyondcorp_app_gateway_test.go index 32607039db0..d9bce5dca30 100644 --- a/google/services/beyondcorp/data_source_google_beyondcorp_app_gateway_test.go +++ b/google/services/beyondcorp/data_source_google_beyondcorp_app_gateway_test.go @@ -103,6 +103,9 @@ resource "google_beyondcorp_app_gateway" "foo" { name = "tf-test-appgateway-%{random_suffix}" type = "TCP_PROXY" host_type = "GCP_REGIONAL_MIG" + labels = { + my-label = "my-label-value" + } } data "google_beyondcorp_app_gateway" "foo" { diff --git a/google/services/cloudfunctions/data_source_google_cloudfunctions_function.go b/google/services/cloudfunctions/data_source_google_cloudfunctions_function.go index b3b45308806..36299741a8d 100644 --- a/google/services/cloudfunctions/data_source_google_cloudfunctions_function.go +++ b/google/services/cloudfunctions/data_source_google_cloudfunctions_function.go @@ -52,6 +52,10 @@ func dataSourceGoogleCloudFunctionsFunctionRead(d *schema.ResourceData, meta int return err } + if err := tpgresource.SetDataSourceLabels(d); err != nil { + return err + } + if d.Id() == "" { return fmt.Errorf("%s not found", cloudFuncId.CloudFunctionId()) } diff --git a/google/services/cloudfunctions/data_source_google_cloudfunctions_function_test.go b/google/services/cloudfunctions/data_source_google_cloudfunctions_function_test.go index 7bac05c42a7..64c22d85369 100644 --- a/google/services/cloudfunctions/data_source_google_cloudfunctions_function_test.go +++ b/google/services/cloudfunctions/data_source_google_cloudfunctions_function_test.go @@ -63,6 +63,9 @@ resource "google_cloudfunctions_function" "function_http" { trigger_http = true timeout = 61 entry_point = "helloGET" + labels = { + my-label = "my-label-value" + } } data "google_cloudfunctions_function" "function_http" { diff --git a/google/services/cloudfunctions2/data_source_google_cloudfunctions2_function.go b/google/services/cloudfunctions2/data_source_google_cloudfunctions2_function.go index c0743867eda..8ceb215661b 100644 --- a/google/services/cloudfunctions2/data_source_google_cloudfunctions2_function.go +++ b/google/services/cloudfunctions2/data_source_google_cloudfunctions2_function.go @@ -42,6 +42,10 @@ func dataSourceGoogleCloudFunctions2FunctionRead(d *schema.ResourceData, meta in return err } + if err := tpgresource.SetDataSourceLabels(d); err != nil { + return err + } + if d.Id() == "" { return fmt.Errorf("%s not found", id) } diff --git a/google/services/cloudfunctions2/data_source_google_cloudfunctions2_function_test.go b/google/services/cloudfunctions2/data_source_google_cloudfunctions2_function_test.go index 7c8ea3704e8..fbf009d0c86 100644 --- a/google/services/cloudfunctions2/data_source_google_cloudfunctions2_function_test.go +++ b/google/services/cloudfunctions2/data_source_google_cloudfunctions2_function_test.go @@ -26,8 +26,8 @@ func TestAccDataSourceGoogleCloudFunctions2Function_basic(t *testing.T) { { Config: testAccDataSourceGoogleCloudFunctions2FunctionConfig(functionName, bucketName, zipFilePath), - // As the value of "labels" and "terraform_labels" in the state is dependent on the configuration, - // and these fields are not set in the configuration of the data source, so these fields are empty in the state of the data source. + // As the value of "labels" and "terraform_labels" in the state of the data source are all labels, + // but the "labels" field in resource are user defined labels, which is the reason for the mismatch. Check: resource.ComposeTestCheckFunc( acctest.CheckDataSourceStateMatchesResourceStateWithIgnores(funcDataNameHttp, "google_cloudfunctions2_function.function_http_v2", map[string]struct{}{"build_config.0.source.0.storage_source.0.bucket": {}, "build_config.0.source.0.storage_source.0.object": {}, "labels.%": {}, "terraform_labels.%": {}}), diff --git a/google/services/composer/data_source_google_composer_environment.go b/google/services/composer/data_source_google_composer_environment.go index 7f7dd4ee0ca..92c37b9ea57 100644 --- a/google/services/composer/data_source_google_composer_environment.go +++ b/google/services/composer/data_source_google_composer_environment.go @@ -44,6 +44,10 @@ func dataSourceGoogleComposerEnvironmentRead(d *schema.ResourceData, meta interf return err } + if err := tpgresource.SetDataSourceLabels(d); err != nil { + return err + } + if d.Id() == "" { return fmt.Errorf("%s not found", id) } diff --git a/google/services/composer/data_source_google_composer_environment_test.go b/google/services/composer/data_source_google_composer_environment_test.go index 94644554067..eff18ea0890 100644 --- a/google/services/composer/data_source_google_composer_environment_test.go +++ b/google/services/composer/data_source_google_composer_environment_test.go @@ -27,6 +27,8 @@ func TestAccDataSourceComposerEnvironment_basic(t *testing.T) { { Config: testAccDataSourceComposerEnvironment_basic(context), Check: resource.ComposeTestCheckFunc( + acctest.CheckDataSourceStateMatchesResourceState("data.google_composer_environment.test", + "google_composer_environment.test"), testAccCheckGoogleComposerEnvironmentMeta("data.google_composer_environment.test"), ), }, @@ -93,6 +95,9 @@ resource "google_composer_environment" "test" { image_version = "composer-1-airflow-2" } } + labels = { + my-label = "my-label-value" + } } // use a separate network to avoid conflicts with other tests running in parallel diff --git a/google/services/compute/data_source_google_compute_disk.go b/google/services/compute/data_source_google_compute_disk.go index ea6e741dddd..e0270524949 100644 --- a/google/services/compute/data_source_google_compute_disk.go +++ b/google/services/compute/data_source_google_compute_disk.go @@ -36,6 +36,10 @@ func dataSourceGoogleComputeDiskRead(d *schema.ResourceData, meta interface{}) e return err } + if err := tpgresource.SetDataSourceLabels(d); err != nil { + return err + } + if d.Id() == "" { return fmt.Errorf("%s not found", id) } diff --git a/google/services/compute/data_source_google_compute_disk_test.go b/google/services/compute/data_source_google_compute_disk_test.go index 8bb7888dfcc..979c5a742f8 100644 --- a/google/services/compute/data_source_google_compute_disk_test.go +++ b/google/services/compute/data_source_google_compute_disk_test.go @@ -34,7 +34,10 @@ func TestAccDataSourceGoogleComputeDisk_basic(t *testing.T) { func testAccDataSourceGoogleComputeDisk_basic(context map[string]interface{}) string { return acctest.Nprintf(` resource "google_compute_disk" "foo" { - name = "tf-test-compute-disk-%{random_suffix}" + name = "tf-test-compute-disk-%{random_suffix}" + labels = { + my-label = "my-label-value" + } } data "google_compute_disk" "foo" { diff --git a/google/services/compute/data_source_google_compute_forwarding_rule.go b/google/services/compute/data_source_google_compute_forwarding_rule.go index a737808a9aa..67774619ef1 100644 --- a/google/services/compute/data_source_google_compute_forwarding_rule.go +++ b/google/services/compute/data_source_google_compute_forwarding_rule.go @@ -49,6 +49,10 @@ func dataSourceGoogleComputeForwardingRuleRead(d *schema.ResourceData, meta inte return err } + if err := tpgresource.SetDataSourceLabels(d); err != nil { + return err + } + if d.Id() == "" { return fmt.Errorf("%s not found", id) } diff --git a/google/services/compute/data_source_google_compute_forwarding_rule_test.go b/google/services/compute/data_source_google_compute_forwarding_rule_test.go index e76c60c2b22..5512f3ae126 100644 --- a/google/services/compute/data_source_google_compute_forwarding_rule_test.go +++ b/google/services/compute/data_source_google_compute_forwarding_rule_test.go @@ -42,6 +42,9 @@ resource "google_compute_forwarding_rule" "foobar-fr" { name = "%s" port_range = "80-81" target = google_compute_target_pool.foobar-tp.self_link + labels = { + my-label = "my-label-value" + } } data "google_compute_forwarding_rule" "my_forwarding_rule" { diff --git a/google/services/compute/data_source_google_compute_instance.go b/google/services/compute/data_source_google_compute_instance.go index 9ddc266c528..acab1b38540 100644 --- a/google/services/compute/data_source_google_compute_instance.go +++ b/google/services/compute/data_source_google_compute_instance.go @@ -99,6 +99,10 @@ func dataSourceGoogleComputeInstanceRead(d *schema.ResourceData, meta interface{ return err } + if err := d.Set("terraform_labels", instance.Labels); err != nil { + return err + } + if instance.LabelFingerprint != "" { if err := d.Set("label_fingerprint", instance.LabelFingerprint); err != nil { return fmt.Errorf("Error setting label_fingerprint: %s", err) diff --git a/google/services/compute/data_source_google_compute_snapshot.go b/google/services/compute/data_source_google_compute_snapshot.go index 316f4d6b2e4..36aa06ca249 100644 --- a/google/services/compute/data_source_google_compute_snapshot.go +++ b/google/services/compute/data_source_google_compute_snapshot.go @@ -104,7 +104,10 @@ func dataSourceGoogleComputeSnapshotRead(d *schema.ResourceData, meta interface{ func retrieveSnapshot(d *schema.ResourceData, meta interface{}, project, name string) error { d.SetId("projects/" + project + "/global/snapshots/" + name) d.Set("name", name) - return resourceComputeSnapshotRead(d, meta) + if err := resourceComputeSnapshotRead(d, meta); err != nil { + return err + } + return tpgresource.SetDataSourceLabels(d) } // ByCreationTimestamp implements sort.Interface for []*Snapshot based on diff --git a/google/services/compute/data_source_google_compute_snapshot_test.go b/google/services/compute/data_source_google_compute_snapshot_test.go index 2a59ee02754..14025b4f8cf 100644 --- a/google/services/compute/data_source_google_compute_snapshot_test.go +++ b/google/services/compute/data_source_google_compute_snapshot_test.go @@ -23,7 +23,7 @@ func TestAccSnapshotDatasource_name(t *testing.T) { acctest.CheckDataSourceStateMatchesResourceStateWithIgnores( "data.google_compute_snapshot.default", "google_compute_snapshot.default", - map[string]struct{}{"zone": {}, "labels.%": {}, "terraform_labels.%": {}}, + map[string]struct{}{"zone": {}}, ), ), }, @@ -44,7 +44,7 @@ func TestAccSnapshotDatasource_filter(t *testing.T) { acctest.CheckDataSourceStateMatchesResourceStateWithIgnores( "data.google_compute_snapshot.default", "google_compute_snapshot.c", - map[string]struct{}{"zone": {}, "labels.%": {}, "terraform_labels.%": {}}, + map[string]struct{}{"zone": {}}, ), ), }, @@ -65,7 +65,7 @@ func TestAccSnapshotDatasource_filterMostRecent(t *testing.T) { acctest.CheckDataSourceStateMatchesResourceStateWithIgnores( "data.google_compute_snapshot.default", "google_compute_snapshot.c", - map[string]struct{}{"zone": {}, "labels.%": {}, "terraform_labels.%": {}}, + map[string]struct{}{"zone": {}}, ), ), }, diff --git a/google/services/compute/data_source_google_global_compute_forwarding_rule.go b/google/services/compute/data_source_google_global_compute_forwarding_rule.go index 8a8859c362e..b60d1626b14 100644 --- a/google/services/compute/data_source_google_global_compute_forwarding_rule.go +++ b/google/services/compute/data_source_google_global_compute_forwarding_rule.go @@ -43,6 +43,10 @@ func dataSourceGoogleComputeGlobalForwardingRuleRead(d *schema.ResourceData, met return err } + if err := tpgresource.SetDataSourceLabels(d); err != nil { + return err + } + if d.Id() == "" { return fmt.Errorf("%s not found", id) } diff --git a/google/services/compute/data_source_google_global_compute_forwarding_rule_test.go b/google/services/compute/data_source_google_global_compute_forwarding_rule_test.go index daef25a5164..1b244358733 100644 --- a/google/services/compute/data_source_google_global_compute_forwarding_rule_test.go +++ b/google/services/compute/data_source_google_global_compute_forwarding_rule_test.go @@ -34,6 +34,9 @@ resource "google_compute_global_forwarding_rule" "foobar-fr" { name = "%s" target = google_compute_target_http_proxy.default.id port_range = "80" + labels = { + my-label = "my-label-value" + } } resource "google_compute_target_http_proxy" "default" { diff --git a/google/services/dataprocmetastore/data_source_dataproc_metastore_service.go b/google/services/dataprocmetastore/data_source_dataproc_metastore_service.go index 3c66d581fe4..f685a5f4fa9 100644 --- a/google/services/dataprocmetastore/data_source_dataproc_metastore_service.go +++ b/google/services/dataprocmetastore/data_source_dataproc_metastore_service.go @@ -34,6 +34,10 @@ func dataSourceDataprocMetastoreServiceRead(d *schema.ResourceData, meta interfa return err } + if err := tpgresource.SetDataSourceLabels(d); err != nil { + return err + } + if d.Id() == "" { return fmt.Errorf("%s not found", id) } diff --git a/google/services/dataprocmetastore/data_source_dataproc_metastore_service_test.go b/google/services/dataprocmetastore/data_source_dataproc_metastore_service_test.go index f41bf381034..d119d87f518 100644 --- a/google/services/dataprocmetastore/data_source_dataproc_metastore_service_test.go +++ b/google/services/dataprocmetastore/data_source_dataproc_metastore_service_test.go @@ -39,6 +39,10 @@ resource "google_dataproc_metastore_service" "my_metastore" { hive_metastore_config { version = "2.3.6" } + + labels = { + env = "test" + } } data "google_dataproc_metastore_service" "my_metastore" { diff --git a/google/services/kms/data_source_google_kms_crypto_key.go b/google/services/kms/data_source_google_kms_crypto_key.go index ac4f93f8331..8628b70ab5c 100644 --- a/google/services/kms/data_source_google_kms_crypto_key.go +++ b/google/services/kms/data_source_google_kms_crypto_key.go @@ -43,6 +43,10 @@ func dataSourceGoogleKmsCryptoKeyRead(d *schema.ResourceData, meta interface{}) return err } + if err := tpgresource.SetDataSourceLabels(d); err != nil { + return err + } + if d.Id() == "" { return fmt.Errorf("%s not found", id) } diff --git a/google/services/privateca/data_source_certificate_authority.go b/google/services/privateca/data_source_certificate_authority.go index ff5562e56e4..08292755cb5 100644 --- a/google/services/privateca/data_source_certificate_authority.go +++ b/google/services/privateca/data_source_certificate_authority.go @@ -47,6 +47,10 @@ func dataSourcePrivatecaCertificateAuthorityRead(d *schema.ResourceData, meta in return err } + if err := tpgresource.SetDataSourceLabels(d); err != nil { + return err + } + // pem_csr is only applicable for SUBORDINATE CertificateAuthorities when their state is AWAITING_USER_ACTIVATION if d.Get("type") == "SUBORDINATE" && d.Get("state") == "AWAITING_USER_ACTIVATION" { url, err := tpgresource.ReplaceVars(d, config, "{{PrivatecaBasePath}}projects/{{project}}/locations/{{location}}/caPools/{{pool}}/certificateAuthorities/{{certificate_authority_id}}:fetch") diff --git a/google/services/privateca/data_source_certificate_authority_test.go b/google/services/privateca/data_source_certificate_authority_test.go index e09331fde08..506e44d6dca 100644 --- a/google/services/privateca/data_source_certificate_authority_test.go +++ b/google/services/privateca/data_source_certificate_authority_test.go @@ -83,6 +83,9 @@ resource "google_privateca_certificate_authority" "default" { key_spec { algorithm = "RSA_PKCS1_4096_SHA256" } + labels = { + my-label = "my-label-value" + } } data "google_privateca_certificate_authority" "default" { diff --git a/google/services/pubsub/data_source_pubsub_subscription.go b/google/services/pubsub/data_source_pubsub_subscription.go index 3e602003528..603c3d02b9e 100644 --- a/google/services/pubsub/data_source_pubsub_subscription.go +++ b/google/services/pubsub/data_source_pubsub_subscription.go @@ -35,6 +35,10 @@ func dataSourceGooglePubsubSubscriptionRead(d *schema.ResourceData, meta interfa return err } + if err := tpgresource.SetDataSourceLabels(d); err != nil { + return err + } + if d.Id() == "" { return fmt.Errorf("%s not found", id) } diff --git a/google/services/pubsub/data_source_pubsub_subscription_test.go b/google/services/pubsub/data_source_pubsub_subscription_test.go index 38159e8c1e7..08c043e52c2 100644 --- a/google/services/pubsub/data_source_pubsub_subscription_test.go +++ b/google/services/pubsub/data_source_pubsub_subscription_test.go @@ -62,6 +62,9 @@ resource "google_pubsub_topic" "foo" { resource "google_pubsub_subscription" "foo" { name = "tf-test-pubsub-subscription-%{random_suffix}" topic = google_pubsub_topic.foo.name + labels = { + my-label = "my-label-value" + } } data "google_pubsub_subscription" "foo" { diff --git a/google/services/pubsub/data_source_pubsub_topic.go b/google/services/pubsub/data_source_pubsub_topic.go index 08e34ab9932..a49474fdcf1 100644 --- a/google/services/pubsub/data_source_pubsub_topic.go +++ b/google/services/pubsub/data_source_pubsub_topic.go @@ -35,6 +35,10 @@ func dataSourceGooglePubsubTopicRead(d *schema.ResourceData, meta interface{}) e return err } + if err := tpgresource.SetDataSourceLabels(d); err != nil { + return err + } + if d.Id() == "" { return fmt.Errorf("%s not found", id) } diff --git a/google/services/pubsub/data_source_pubsub_topic_test.go b/google/services/pubsub/data_source_pubsub_topic_test.go index 00b84659b03..bdc236881f7 100644 --- a/google/services/pubsub/data_source_pubsub_topic_test.go +++ b/google/services/pubsub/data_source_pubsub_topic_test.go @@ -57,6 +57,9 @@ func testAccDataSourceGooglePubsubTopic_basic(context map[string]interface{}) st return acctest.Nprintf(` resource "google_pubsub_topic" "foo" { name = "tf-test-pubsub-%{random_suffix}" + labels = { + my-label = "my-label-value" + } } data "google_pubsub_topic" "foo" { diff --git a/google/services/redis/data_source_redis_instance.go b/google/services/redis/data_source_redis_instance.go index 23d1cd3e403..dd73b7ae288 100644 --- a/google/services/redis/data_source_redis_instance.go +++ b/google/services/redis/data_source_redis_instance.go @@ -38,6 +38,10 @@ func dataSourceGoogleRedisInstanceRead(d *schema.ResourceData, meta interface{}) return err } + if err := tpgresource.SetDataSourceLabels(d); err != nil { + return err + } + if d.Id() == "" { return fmt.Errorf("%s not found", id) } diff --git a/google/services/redis/data_source_redis_instance_test.go b/google/services/redis/data_source_redis_instance_test.go index 62cbb77d557..1372633c4f2 100644 --- a/google/services/redis/data_source_redis_instance_test.go +++ b/google/services/redis/data_source_redis_instance_test.go @@ -32,6 +32,10 @@ func testAccRedisInstanceDatasourceConfig(suffix string) string { resource "google_redis_instance" "redis" { name = "redis-test-%s" memory_size_gb = 1 + + labels = { + my-label = "my-label-value" + } } data "google_redis_instance" "redis" { diff --git a/google/services/resourcemanager/data_source_google_project.go b/google/services/resourcemanager/data_source_google_project.go index 2be4d00773f..4916292a8b3 100644 --- a/google/services/resourcemanager/data_source_google_project.go +++ b/google/services/resourcemanager/data_source_google_project.go @@ -44,6 +44,10 @@ func datasourceGoogleProjectRead(d *schema.ResourceData, meta interface{}) error return err } + if err := tpgresource.SetDataSourceLabels(d); err != nil { + return err + } + if d.Id() == "" { return fmt.Errorf("%s not found or not in ACTIVE state", id) } diff --git a/google/services/resourcemanager/data_source_google_project_test.go b/google/services/resourcemanager/data_source_google_project_test.go index dea8cdc70b2..e37139f3600 100644 --- a/google/services/resourcemanager/data_source_google_project_test.go +++ b/google/services/resourcemanager/data_source_google_project_test.go @@ -43,6 +43,9 @@ resource "google_project" "project" { project_id = "%s" name = "%s" org_id = "%s" + labels = { + my-label = "my-label-value" + } } data "google_project" "project" { diff --git a/google/services/secretmanager/data_source_secret_manager_secret.go b/google/services/secretmanager/data_source_secret_manager_secret.go index 8a070619f00..770cdb2eef1 100644 --- a/google/services/secretmanager/data_source_secret_manager_secret.go +++ b/google/services/secretmanager/data_source_secret_manager_secret.go @@ -33,6 +33,14 @@ func dataSourceSecretManagerSecretRead(d *schema.ResourceData, meta interface{}) return err } + if err := tpgresource.SetDataSourceLabels(d); err != nil { + return err + } + + if err := tpgresource.SetDataSourceAnnotations(d); err != nil { + return err + } + if d.Id() == "" { return fmt.Errorf("%s not found", id) } diff --git a/google/services/secretmanager/data_source_secret_manager_secret_test.go b/google/services/secretmanager/data_source_secret_manager_secret_test.go index 39ae6a4632e..6656fe8ab97 100644 --- a/google/services/secretmanager/data_source_secret_manager_secret_test.go +++ b/google/services/secretmanager/data_source_secret_manager_secret_test.go @@ -27,7 +27,7 @@ func TestAccDataSourceSecretManagerSecret_basic(t *testing.T) { acctest.CheckDataSourceStateMatchesResourceStateWithIgnores( "data.google_secret_manager_secret.foo", "google_secret_manager_secret.bar", - map[string]struct{}{"zone": {}, "labels.%": {}, "terraform_labels.%": {}}, + map[string]struct{}{"zone": {}}, ), ), }, @@ -44,6 +44,10 @@ resource "google_secret_manager_secret" "bar" { label = "my-label" } + annotations = { + annotation = "my-annotation" + } + replication { user_managed { replicas { diff --git a/google/services/spanner/data_source_spanner_instance.go b/google/services/spanner/data_source_spanner_instance.go index 97e6680eb9d..255079f1504 100644 --- a/google/services/spanner/data_source_spanner_instance.go +++ b/google/services/spanner/data_source_spanner_instance.go @@ -39,6 +39,10 @@ func dataSourceSpannerInstanceRead(d *schema.ResourceData, meta interface{}) err return err } + if err := tpgresource.SetDataSourceLabels(d); err != nil { + return err + } + if d.Id() == "" { return fmt.Errorf("%s not found", id) } diff --git a/google/services/vertexai/data_source_vertex_ai_index.go b/google/services/vertexai/data_source_vertex_ai_index.go index 2f994c779d5..7ba9ae28e0c 100644 --- a/google/services/vertexai/data_source_vertex_ai_index.go +++ b/google/services/vertexai/data_source_vertex_ai_index.go @@ -36,6 +36,10 @@ func dataSourceVertexAIIndexRead(d *schema.ResourceData, meta interface{}) error return err } + if err := tpgresource.SetDataSourceLabels(d); err != nil { + return err + } + if d.Id() == "" { return fmt.Errorf("%s not found", id) } diff --git a/google/services/vertexai/data_source_vertex_ai_index_test.go b/google/services/vertexai/data_source_vertex_ai_index_test.go index 7335cc7eded..b4e1888afe4 100644 --- a/google/services/vertexai/data_source_vertex_ai_index_test.go +++ b/google/services/vertexai/data_source_vertex_ai_index_test.go @@ -33,8 +33,6 @@ func TestAccDataSourceVertexAIIndex_basic(t *testing.T) { map[string]struct{}{ "metadata.0.contents_delta_uri": {}, "metadata.0.is_complete_overwrite": {}, - "labels.%": {}, - "terraform_labels.%": {}, }, ), ), diff --git a/google/tpgresource/annotations.go b/google/tpgresource/annotations.go index fa90bdf1ada..23fe7efe58a 100644 --- a/google/tpgresource/annotations.go +++ b/google/tpgresource/annotations.go @@ -68,3 +68,22 @@ func SetMetadataAnnotationsDiff(_ context.Context, d *schema.ResourceDiff, meta return nil } + +// Sets the "annotations" field with the value of the field "effective_annotations" for data sources. +// When reading data source, as the annotations field is unavailable in the configuration of the data source, +// the "annotations" field will be empty. With this funciton, the labels "annotations" will have all of annotations in the resource. +func SetDataSourceAnnotations(d *schema.ResourceData) error { + effectiveAnnotations := d.Get("effective_annotations") + if effectiveAnnotations == nil { + return nil + } + + if d.Get("annotations") == nil { + return fmt.Errorf("`annotations` field is not present in the resource schema.") + } + if err := d.Set("annotations", effectiveAnnotations); err != nil { + return fmt.Errorf("Error setting annotations in data source: %s", err) + } + + return nil +} diff --git a/google/tpgresource/labels.go b/google/tpgresource/labels.go index 680beb57924..f17fa1323fa 100644 --- a/google/tpgresource/labels.go +++ b/google/tpgresource/labels.go @@ -29,6 +29,32 @@ func SetLabels(labels map[string]string, d *schema.ResourceData, lineage string) return d.Set(lineage, transformed) } +// Sets the "labels" field and "terraform_labels" with the value of the field "effective_labels" for data sources. +// When reading data source, as the labels field is unavailable in the configuration of the data source, +// the "labels" field will be empty. With this funciton, the labels "field" will have all of labels in the resource. +func SetDataSourceLabels(d *schema.ResourceData) error { + effectiveLabels := d.Get("effective_labels") + if effectiveLabels == nil { + return nil + } + + if d.Get("labels") == nil { + return fmt.Errorf("`labels` field is not present in the resource schema.") + } + if err := d.Set("labels", effectiveLabels); err != nil { + return fmt.Errorf("Error setting labels in data source: %s", err) + } + + if d.Get("terraform_labels") == nil { + return fmt.Errorf("`terraform_labels` field is not present in the resource schema.") + } + if err := d.Set("terraform_labels", effectiveLabels); err != nil { + return fmt.Errorf("Error setting terraform_labels in data source: %s", err) + } + + return nil +} + func SetLabelsDiff(_ context.Context, d *schema.ResourceDiff, meta interface{}) error { config := meta.(*transport_tpg.Config) diff --git a/website/docs/d/cloudfunctions_function.html.markdown b/website/docs/d/cloudfunctions_function.html.markdown index e3ca05447d0..1b4e2f7dd5b 100644 --- a/website/docs/d/cloudfunctions_function.html.markdown +++ b/website/docs/d/cloudfunctions_function.html.markdown @@ -49,7 +49,7 @@ exported: * `event_trigger` - A source that fires events in response to a condition in another service. Structure is [documented below](#nested_event_trigger). * `https_trigger_url` - If function is triggered by HTTP, trigger URL is set here. * `ingress_settings` - Controls what traffic can reach the function. -* `labels` - A map of labels applied to this function. +* `labels` - All of labels (key/value pairs) present on the resource in GCP, including the labels configured through Terraform, other clients and services. * `service_account_email` - The service account email to be assumed by the cloud function. * `vpc_connector` - The VPC Network Connector that this cloud function can connect to. * `vpc_connector_egress_settings` - The egress settings for the connector, controlling what traffic is diverted through it. diff --git a/website/docs/d/compute_disk.html.markdown b/website/docs/d/compute_disk.html.markdown index 65596b090bf..33ad9dc772a 100644 --- a/website/docs/d/compute_disk.html.markdown +++ b/website/docs/d/compute_disk.html.markdown @@ -82,7 +82,7 @@ In addition to the arguments listed above, the following computed attributes are * `description` - The optional description of this resource. -* `labels` - A map of labels applied to this disk. +* `labels` - All of labels (key/value pairs) present on the resource in GCP, including the labels configured through Terraform, other clients and services. * `size` - Size of the persistent disk, specified in GB. diff --git a/website/docs/d/compute_image.html.markdown b/website/docs/d/compute_image.html.markdown index e9cdc9616ad..883e99fc0bf 100644 --- a/website/docs/d/compute_image.html.markdown +++ b/website/docs/d/compute_image.html.markdown @@ -71,7 +71,7 @@ exported: * `source_disk_id` - The ID value of the disk used to create this image. * `creation_timestamp` - The creation timestamp in RFC3339 text format. * `description` - An optional description of this image. -* `labels` - A map of labels applied to this image. +* `labels` - All of labels (key/value pairs) present on the resource in GCP, including the labels configured through Terraform, other clients and services. * `label_fingerprint` - A fingerprint for the labels being applied to this image. * `licenses` - A list of applicable license URI. * `status` - The status of the image. Possible values are **FAILED**, **PENDING**, or **READY**. diff --git a/website/docs/d/compute_instance.html.markdown b/website/docs/d/compute_instance.html.markdown index d478a3eca5a..1d3e8dc0620 100644 --- a/website/docs/d/compute_instance.html.markdown +++ b/website/docs/d/compute_instance.html.markdown @@ -57,7 +57,7 @@ The following arguments are supported: * `guest_accelerator` - List of the type and count of accelerator cards attached to the instance. Structure is [documented below](#nested_guest_accelerator). -* `labels` - A set of key/value label pairs assigned to the instance. +* `labels` - All of labels (key/value pairs) present on the resource in GCP, including the labels configured through Terraform, other clients and services. * `metadata` - Metadata key/value pairs made available within the instance. diff --git a/website/docs/d/compute_instance_template.html.markdown b/website/docs/d/compute_instance_template.html.markdown index e771c3be87c..3142f0af893 100644 --- a/website/docs/d/compute_instance_template.html.markdown +++ b/website/docs/d/compute_instance_template.html.markdown @@ -78,8 +78,7 @@ The following arguments are supported: * `instance_description` - A brief description to use for instances created from this template. -* `labels` - A set of key/value label pairs to assign to instances - created from this template, +* `labels` - All of labels (key/value pairs) present on the resource in GCP, including the labels configured through Terraform, other clients and services. * `metadata` - Metadata key/value pairs to make available from within instances created from this template. diff --git a/website/docs/r/cloudfunctions_function.html.markdown b/website/docs/r/cloudfunctions_function.html.markdown index 8d0ada5aa62..c73d6561aab 100644 --- a/website/docs/r/cloudfunctions_function.html.markdown +++ b/website/docs/r/cloudfunctions_function.html.markdown @@ -134,6 +134,9 @@ Eg. `"nodejs16"`, `"python39"`, `"dotnet3"`, `"go116"`, `"java11"`, `"ruby30"`, * `labels` - (Optional) 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. +**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. + * `terraform_labels` - The combination of labels configured directly on the resource and default labels configured on the provider. diff --git a/website/docs/r/composer_environment.html.markdown b/website/docs/r/composer_environment.html.markdown index 792ff022fbb..94c3fb60920 100644 --- a/website/docs/r/composer_environment.html.markdown +++ b/website/docs/r/composer_environment.html.markdown @@ -262,6 +262,9 @@ The following arguments are supported: No more than 64 labels can be associated with a given environment. Both keys and values must be <= 128 bytes in size. + **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. + * `terraform_labels` - The combination of labels configured directly on the resource and default labels configured on the provider. diff --git a/website/docs/r/compute_instance.html.markdown b/website/docs/r/compute_instance.html.markdown index 53fc20e6a37..965f0d80a9d 100644 --- a/website/docs/r/compute_instance.html.markdown +++ b/website/docs/r/compute_instance.html.markdown @@ -117,6 +117,8 @@ The following arguments are supported: For more details about this behavior, see [this section](https://www.terraform.io/docs/configuration/attr-as-blocks.html#defining-a-fixed-object-collection-value). * `labels` - (Optional) A map of key/value label pairs to assign to the 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. * `terraform_labels` - The combination of labels configured directly on the resource and default labels configured on the provider. diff --git a/website/docs/r/compute_instance_template.html.markdown b/website/docs/r/compute_instance_template.html.markdown index c04c64137d4..b6c5fe8b88d 100644 --- a/website/docs/r/compute_instance_template.html.markdown +++ b/website/docs/r/compute_instance_template.html.markdown @@ -308,6 +308,12 @@ The following arguments are supported: * `labels` - (Optional) A set of key/value label pairs to assign to instances created from this template. + **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. + +* `effective_labels` - + All of labels (key/value pairs) present on the resource in GCP, including the labels configured through Terraform, other clients and services. + * `metadata` - (Optional) Metadata key/value pairs to make available from within instances created from this template. diff --git a/website/docs/r/dataproc_job.html.markdown b/website/docs/r/dataproc_job.html.markdown index 0e9953079fb..84094a189b4 100644 --- a/website/docs/r/dataproc_job.html.markdown +++ b/website/docs/r/dataproc_job.html.markdown @@ -102,6 +102,8 @@ output "pyspark_status" { job is first cancelled before issuing the delete. * `labels` - (Optional) The list of labels (key/value pairs) to add to the job. + **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. * `terraform_labels` - The combination of labels configured directly on the resource and default labels configured on the provider. diff --git a/website/docs/r/google_project.html.markdown b/website/docs/r/google_project.html.markdown index e5139412d01..1f3a4dff836 100644 --- a/website/docs/r/google_project.html.markdown +++ b/website/docs/r/google_project.html.markdown @@ -82,6 +82,8 @@ The following arguments are supported: without deleting the Project via the Google API. * `labels` - (Optional) A set of key/value label pairs to assign to the project. + **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. * `terraform_labels` - The combination of labels configured directly on the resource and default labels configured on the provider.