Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make labels field have all labels in data sources #15957

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/9037.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 @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.%": {}}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
},
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions google/services/compute/data_source_google_compute_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": {}},
),
),
},
Expand All @@ -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": {}},
),
),
},
Expand All @@ -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": {}},
),
),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
4 changes: 4 additions & 0 deletions google/services/kms/data_source_google_kms_crypto_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
4 changes: 4 additions & 0 deletions google/services/pubsub/data_source_pubsub_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
4 changes: 4 additions & 0 deletions google/services/pubsub/data_source_pubsub_topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
3 changes: 3 additions & 0 deletions google/services/pubsub/data_source_pubsub_topic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
4 changes: 4 additions & 0 deletions google/services/redis/data_source_redis_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 4 additions & 0 deletions google/services/redis/data_source_redis_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
Loading