From c39d3e848b4c1b00b0296bc3399aac4cb8d76bc9 Mon Sep 17 00:00:00 2001 From: abheda-crest <105624942+abheda-crest@users.noreply.github.com> Date: Fri, 4 Oct 2024 04:08:57 +0530 Subject: [PATCH] Fix the issue of unpopulated fields in the terraform state for the `google_secret_manager_secrets` datasource (#11904) --- .../data_source_secret_manager_secrets.go | 26 +++++++----- ...data_source_secret_manager_secrets_test.go | 40 ++++++++++++++----- .../d/secret_manager_secrets.html.markdown | 2 + 3 files changed, 47 insertions(+), 21 deletions(-) diff --git a/mmv1/third_party/terraform/services/secretmanager/data_source_secret_manager_secrets.go b/mmv1/third_party/terraform/services/secretmanager/data_source_secret_manager_secrets.go index 877f9ed4b253..3b571af7a6a3 100644 --- a/mmv1/third_party/terraform/services/secretmanager/data_source_secret_manager_secrets.go +++ b/mmv1/third_party/terraform/services/secretmanager/data_source_secret_manager_secrets.go @@ -144,17 +144,21 @@ func flattenSecretManagerSecretsSecrets(v interface{}, d *schema.ResourceData, c continue } transformed = append(transformed, map[string]interface{}{ - "replication": flattenSecretManagerSecretReplication(original["replication"], d, config), - "annotations": flattenSecretManagerSecretAnnotations(original["annotations"], d, config), - "expire_time": flattenSecretManagerSecretExpireTime(original["expireTime"], d, config), - "labels": flattenSecretManagerSecretLabels(original["labels"], d, config), - "rotation": flattenSecretManagerSecretRotation(original["rotation"], d, config), - "topics": flattenSecretManagerSecretTopics(original["topics"], d, config), - "version_aliases": flattenSecretManagerSecretVersionAliases(original["versionAliases"], d, config), - "create_time": flattenSecretManagerSecretCreateTime(original["createTime"], d, config), - "name": flattenSecretManagerSecretName(original["name"], d, config), - "project": getDataFromName(original["name"], 1), - "secret_id": getDataFromName(original["name"], 3), + "replication": flattenSecretManagerSecretReplication(original["replication"], d, config), + "annotations": flattenSecretManagerSecretEffectiveAnnotations(original["annotations"], d, config), + "effective_annotations": flattenSecretManagerSecretEffectiveAnnotations(original["annotations"], d, config), + "expire_time": flattenSecretManagerSecretExpireTime(original["expireTime"], d, config), + "labels": flattenSecretManagerSecretEffectiveLabels(original["labels"], d, config), + "effective_labels": flattenSecretManagerSecretEffectiveLabels(original["labels"], d, config), + "terraform_labels": flattenSecretManagerSecretEffectiveLabels(original["labels"], d, config), + "rotation": flattenSecretManagerSecretRotation(original["rotation"], d, config), + "topics": flattenSecretManagerSecretTopics(original["topics"], d, config), + "version_aliases": flattenSecretManagerSecretVersionAliases(original["versionAliases"], d, config), + "version_destroy_ttl": flattenSecretManagerSecretVersionDestroyTtl(original["versionDestroyTtl"], d, config), + "create_time": flattenSecretManagerSecretCreateTime(original["createTime"], d, config), + "name": flattenSecretManagerSecretName(original["name"], d, config), + "project": getDataFromName(original["name"], 1), + "secret_id": getDataFromName(original["name"], 3), }) } return transformed diff --git a/mmv1/third_party/terraform/services/secretmanager/data_source_secret_manager_secrets_test.go b/mmv1/third_party/terraform/services/secretmanager/data_source_secret_manager_secrets_test.go index afe3300036eb..d457afe6a505 100644 --- a/mmv1/third_party/terraform/services/secretmanager/data_source_secret_manager_secrets_test.go +++ b/mmv1/third_party/terraform/services/secretmanager/data_source_secret_manager_secrets_test.go @@ -30,11 +30,8 @@ func TestAccDataSourceSecretManagerSecrets_basic(t *testing.T) { "data.google_secret_manager_secrets.foo", "google_secret_manager_secret.foo", map[string]struct{}{ - "id": {}, - "project": {}, - "effective_labels": {}, - "labels": {}, - "terraform_labels": {}, + "id": {}, + "project": {}, }, ), ), @@ -59,6 +56,16 @@ resource "google_secret_manager_secret" "foo" { } } } + + labels = { + label = "my-label" + } + + annotations = { + key1 = "value1" + } + + version_destroy_ttl = "360000s" } data "google_secret_manager_secrets" "foo" { @@ -89,11 +96,8 @@ func TestAccDataSourceSecretManagerSecrets_filter(t *testing.T) { "google_secret_manager_secret.foo", "google_secret_manager_secret.bar", map[string]struct{}{ - "id": {}, - "project": {}, - "effective_labels": {}, - "labels": {}, - "terraform_labels": {}, + "id": {}, + "project": {}, }, ), ), @@ -118,6 +122,14 @@ resource "google_secret_manager_secret" "foo" { } } } + + labels = { + label = "my-label" + } + + annotations = { + key1 = "value1" + } } resource "google_secret_manager_secret" "bar" { @@ -130,6 +142,14 @@ resource "google_secret_manager_secret" "bar" { } } } + + labels = { + label= "my-label2" + } + + annotations = { + key1 = "value1" + } } data "google_secret_manager_secrets" "foo" { diff --git a/mmv1/third_party/terraform/website/docs/d/secret_manager_secrets.html.markdown b/mmv1/third_party/terraform/website/docs/d/secret_manager_secrets.html.markdown index 463266f0127b..e6ad5da99d42 100644 --- a/mmv1/third_party/terraform/website/docs/d/secret_manager_secrets.html.markdown +++ b/mmv1/third_party/terraform/website/docs/d/secret_manager_secrets.html.markdown @@ -43,6 +43,8 @@ exported: * `version_aliases` - Mapping from version alias to version name. +* `version_destroy_ttl` - The version destroy ttl for the secret version. + * `topics` - A list of up to 10 Pub/Sub topics to which messages are published when control plane operations are called on the secret or its versions. Structure is [documented below](#nested_topics).