diff --git a/mmv1/third_party/terraform/fwprovider/data_source_provider_config_plugin_framework.go b/mmv1/third_party/terraform/fwprovider/data_source_provider_config_plugin_framework.go index 6d3b17785034..98ec9011e6ed 100644 --- a/mmv1/third_party/terraform/fwprovider/data_source_provider_config_plugin_framework.go +++ b/mmv1/third_party/terraform/fwprovider/data_source_provider_config_plugin_framework.go @@ -217,8 +217,8 @@ func (d *GoogleProviderConfigPluginFrameworkDataSource) Read(ctx context.Context data.RequestReason = d.providerConfig.RequestReason // TODO(SarahFrench) - request_timeout data.DefaultLabels = d.providerConfig.DefaultLabels - // TODO(SarahFrench) - add_terraform_attribution_label - // TODO(SarahFrench) - terraform_attribution_label_addition_strategy + data.AddTerraformAttributionLabel = d.providerConfig.AddTerraformAttributionLabel + data.TerraformAttributionLabelAdditionStrategy = d.providerConfig.TerraformAttributionLabelAdditionStrategy // Warn users against using this data source resp.Diagnostics.Append(diag.NewWarningDiagnostic( diff --git a/mmv1/third_party/terraform/fwprovider/framework_provider_add_terraform_attribution_label_test.go b/mmv1/third_party/terraform/fwprovider/framework_provider_add_terraform_attribution_label_test.go new file mode 100644 index 000000000000..d9eeb07ed5a2 --- /dev/null +++ b/mmv1/third_party/terraform/fwprovider/framework_provider_add_terraform_attribution_label_test.go @@ -0,0 +1,98 @@ +package fwprovider_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-provider-google/google/acctest" +) + +// TestAccFwProvider_add_terraform_attribution_label is a series of acc tests asserting how the plugin-framework provider handles add_terraform_attribution_label arguments +// It is plugin-framework specific because the HCL used provisions plugin-framework-implemented resources +// It is a counterpart to TestAccSdkProvider_add_terraform_attribution_label +func TestAccFwProvider_add_terraform_attribution_label(t *testing.T) { + testCases := map[string]func(t *testing.T){ + // Configuring the provider using inputs + "when add_terraform_attribution_label is set in the config, the value is set in the provider meta data": testAccFwProvider_add_terraform_attribution_label_configUsed, + "when add_terraform_attribution_label is unset in the config, the default value 'true' is NOT set on the provider meta data": testAccFwProvider_add_terraform_attribution_label_defaultValue, + } + + for name, tc := range testCases { + // shadow the tc variable into scope so that when + // the loop continues, if t.Run hasn't executed tc(t) + // yet, we don't have a race condition + // see https://github.com/golang/go/wiki/CommonMistakes#using-goroutines-on-loop-iterator-variables + tc := tc + t.Run(name, func(t *testing.T) { + tc(t) + }) + } +} + +func testAccFwProvider_add_terraform_attribution_label_configUsed(t *testing.T) { + acctest.SkipIfVcr(t) // Test doesn't interact with API + + contextFalse := map[string]interface{}{ + "add_terraform_attribution_label": "false", + } + contextTrue := map[string]interface{}{ + "add_terraform_attribution_label": "true", + } + + acctest.VcrTest(t, resource.TestCase{ + // No PreCheck for checking ENVs + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + Steps: []resource.TestStep{ + { + Config: testAccFwProvider_add_terraform_attribution_label_inProviderBlock(contextFalse), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("data.google_provider_config_plugin_framework.default", "add_terraform_attribution_label", "false"), + ), + }, + { + Config: testAccFwProvider_add_terraform_attribution_label_inProviderBlock(contextTrue), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("data.google_provider_config_plugin_framework.default", "add_terraform_attribution_label", "true"), + ), + }, + }, + }) +} + +func testAccFwProvider_add_terraform_attribution_label_defaultValue(t *testing.T) { + acctest.SkipIfVcr(t) // Test doesn't interact with API + + context := map[string]interface{}{} + + acctest.VcrTest(t, resource.TestCase{ + // No PreCheck for checking ENVs + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + Steps: []resource.TestStep{ + { + Config: testAccFwProvider_add_terraform_attribution_label_inEnvsOnly(context), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckNoResourceAttr("data.google_provider_config_plugin_framework.default", "add_terraform_attribution_label"), + ), + }, + }, + }) +} + +// testAccFwProvider_add_terraform_attribution_label_inProviderBlock allows setting the add_terraform_attribution_label argument in a provider block. +func testAccFwProvider_add_terraform_attribution_label_inProviderBlock(context map[string]interface{}) string { + return acctest.Nprintf(` +provider "google" { + add_terraform_attribution_label = "%{add_terraform_attribution_label}" +} + +data "google_provider_config_plugin_framework" "default" {} +`, context) +} + +// testAccFwProvider_add_terraform_attribution_label_inEnvsOnly allows testing when the add_terraform_attribution_label argument +// is only supplied via ENVs +func testAccFwProvider_add_terraform_attribution_label_inEnvsOnly(context map[string]interface{}) string { + return acctest.Nprintf(` +data "google_provider_config_plugin_framework" "default" {} +`, context) +} diff --git a/mmv1/third_party/terraform/fwprovider/framework_provider_terraform_attribution_label_addition_strategy_test.go b/mmv1/third_party/terraform/fwprovider/framework_provider_terraform_attribution_label_addition_strategy_test.go new file mode 100644 index 000000000000..921edce47d38 --- /dev/null +++ b/mmv1/third_party/terraform/fwprovider/framework_provider_terraform_attribution_label_addition_strategy_test.go @@ -0,0 +1,98 @@ +package fwprovider_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-provider-google/google/acctest" +) + +// TestAccFwProvider_terraform_attribution_label_addition_strategy is a series of acc tests asserting how the plugin-framework provider handles terraform_attribution_label_addition_strategy arguments +// It is plugin-framework specific because the HCL used provisions plugin-framework-implemented resources +// It is a counterpart to TestAccSdkProvider_terraform_attribution_label_addition_strategy +func TestAccFwProvider_terraform_attribution_label_addition_strategy(t *testing.T) { + testCases := map[string]func(t *testing.T){ + // Configuring the provider using inputs + "config sets terraform_attribution_label_addition_strategy values": testAccFwProvider_terraform_attribution_label_addition_strategy_configUsed, + "when terraform_attribution_label_addition_strategy is unset in the config, the default value'CREATION_ONLY' is NOT set in the provider meta data": testAccFwProvider_terraform_attribution_label_addition_strategy_defaultValue, + } + + for name, tc := range testCases { + // shadow the tc variable into scope so that when + // the loop continues, if t.Run hasn't executed tc(t) + // yet, we don't have a race condition + // see https://github.com/golang/go/wiki/CommonMistakes#using-goroutines-on-loop-iterator-variables + tc := tc + t.Run(name, func(t *testing.T) { + tc(t) + }) + } +} + +func testAccFwProvider_terraform_attribution_label_addition_strategy_configUsed(t *testing.T) { + acctest.SkipIfVcr(t) // Test doesn't interact with API + + context1 := map[string]interface{}{ + "terraform_attribution_label_addition_strategy": "CREATION_ONLY", + } + context2 := map[string]interface{}{ + "terraform_attribution_label_addition_strategy": "PROACTIVE", + } + + acctest.VcrTest(t, resource.TestCase{ + // No PreCheck for checking ENVs + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + Steps: []resource.TestStep{ + { + Config: testAccFwProvider_terraform_attribution_label_addition_strategy_inProviderBlock(context1), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("data.google_provider_config_plugin_framework.default", "terraform_attribution_label_addition_strategy", "CREATION_ONLY"), + ), + }, + { + Config: testAccFwProvider_terraform_attribution_label_addition_strategy_inProviderBlock(context2), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("data.google_provider_config_plugin_framework.default", "terraform_attribution_label_addition_strategy", "PROACTIVE"), + ), + }, + }, + }) +} + +func testAccFwProvider_terraform_attribution_label_addition_strategy_defaultValue(t *testing.T) { + acctest.SkipIfVcr(t) // Test doesn't interact with API + + context := map[string]interface{}{} + + acctest.VcrTest(t, resource.TestCase{ + // No PreCheck for checking ENVs + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + Steps: []resource.TestStep{ + { + Config: testAccFwProvider_terraform_attribution_label_addition_strategy_inEnvsOnly(context), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckNoResourceAttr("data.google_provider_config_plugin_framework.default", "terraform_attribution_label_addition_strategy"), + ), + }, + }, + }) +} + +// testAccFwProvider_terraform_attribution_label_addition_strategy_inProviderBlock allows setting the terraform_attribution_label_addition_strategy argument in a provider block. +func testAccFwProvider_terraform_attribution_label_addition_strategy_inProviderBlock(context map[string]interface{}) string { + return acctest.Nprintf(` +provider "google" { + terraform_attribution_label_addition_strategy = "%{terraform_attribution_label_addition_strategy}" +} + +data "google_provider_config_plugin_framework" "default" {} +`, context) +} + +// testAccFwProvider_terraform_attribution_label_addition_strategy_inEnvsOnly allows testing when the terraform_attribution_label_addition_strategy argument +// is only supplied via ENVs +func testAccFwProvider_terraform_attribution_label_addition_strategy_inEnvsOnly(context map[string]interface{}) string { + return acctest.Nprintf(` +data "google_provider_config_plugin_framework" "default" {} +`, context) +} diff --git a/mmv1/third_party/terraform/fwtransport/framework_config.go.tmpl b/mmv1/third_party/terraform/fwtransport/framework_config.go.tmpl index f99a8dc0dfc8..9107259edd08 100644 --- a/mmv1/third_party/terraform/fwtransport/framework_config.go.tmpl +++ b/mmv1/third_party/terraform/fwtransport/framework_config.go.tmpl @@ -39,6 +39,8 @@ type FrameworkProviderConfig struct { ImpersonateServiceAccount types.String ImpersonateServiceAccountDelegates types.List RequestReason types.String + AddTerraformAttributionLabel types.Bool + TerraformAttributionLabelAdditionStrategy types.String // End temporary BillingProject types.String @@ -111,7 +113,8 @@ func (p *FrameworkProviderConfig) LoadAndValidateFramework(ctx context.Context, p.ImpersonateServiceAccount = data.ImpersonateServiceAccount p.ImpersonateServiceAccountDelegates = data.ImpersonateServiceAccountDelegates p.RequestReason = data.RequestReason - + p.AddTerraformAttributionLabel = data.AddTerraformAttributionLabel + p.TerraformAttributionLabelAdditionStrategy = data.TerraformAttributionLabelAdditionStrategy // End temporary // Copy values from the ProviderModel struct containing data about the provider configuration (present only when responsing to ConfigureProvider rpc calls) diff --git a/mmv1/third_party/terraform/provider/provider_add_terraform_attribution_label_test.go b/mmv1/third_party/terraform/provider/provider_add_terraform_attribution_label_test.go new file mode 100644 index 000000000000..390d5e75ec9c --- /dev/null +++ b/mmv1/third_party/terraform/provider/provider_add_terraform_attribution_label_test.go @@ -0,0 +1,98 @@ +package provider_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-provider-google/google/acctest" +) + +// TestAccSdkProvider_add_terraform_attribution_label is a series of acc tests asserting how the plugin-framework provider handles add_terraform_attribution_label arguments +// It is plugin-framework specific because the HCL used provisions plugin-framework-implemented resources +// It is a counterpart to TestAccFwProvider_add_terraform_attribution_label +func TestAccSdkProvider_add_terraform_attribution_label(t *testing.T) { + testCases := map[string]func(t *testing.T){ + // Configuring the provider using inputs + "config sets add_terraform_attribution_label values": testAccSdkProvider_add_terraform_attribution_label_configUsed, + "when add_terraform_attribution_label is unset in the config, the default value 'true' is set in the provider meta data": testAccSdkProvider_add_terraform_attribution_label_defaultValue, + } + + for name, tc := range testCases { + // shadow the tc variable into scope so that when + // the loop continues, if t.Run hasn't executed tc(t) + // yet, we don't have a race condition + // see https://github.com/golang/go/wiki/CommonMistakes#using-goroutines-on-loop-iterator-variables + tc := tc + t.Run(name, func(t *testing.T) { + tc(t) + }) + } +} + +func testAccSdkProvider_add_terraform_attribution_label_configUsed(t *testing.T) { + acctest.SkipIfVcr(t) // Test doesn't interact with API + + contextFalse := map[string]interface{}{ + "add_terraform_attribution_label": "false", + } + contextTrue := map[string]interface{}{ + "add_terraform_attribution_label": "true", + } + + acctest.VcrTest(t, resource.TestCase{ + // No PreCheck for checking ENVs + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + Steps: []resource.TestStep{ + { + Config: testAccSdkProvider_add_terraform_attribution_label_inProviderBlock(contextFalse), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("data.google_provider_config_sdk.default", "add_terraform_attribution_label", "false"), + ), + }, + { + Config: testAccSdkProvider_add_terraform_attribution_label_inProviderBlock(contextTrue), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("data.google_provider_config_sdk.default", "add_terraform_attribution_label", "true"), + ), + }, + }, + }) +} + +func testAccSdkProvider_add_terraform_attribution_label_defaultValue(t *testing.T) { + acctest.SkipIfVcr(t) // Test doesn't interact with API + + context := map[string]interface{}{} + + acctest.VcrTest(t, resource.TestCase{ + // No PreCheck for checking ENVs + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + Steps: []resource.TestStep{ + { + Config: testAccSdkProvider_add_terraform_attribution_label_inEnvsOnly(context), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("data.google_provider_config_sdk.default", "add_terraform_attribution_label", "true"), + ), + }, + }, + }) +} + +// testAccSdkProvider_add_terraform_attribution_label_inProviderBlock allows setting the add_terraform_attribution_label argument in a provider block. +func testAccSdkProvider_add_terraform_attribution_label_inProviderBlock(context map[string]interface{}) string { + return acctest.Nprintf(` +provider "google" { + add_terraform_attribution_label = "%{add_terraform_attribution_label}" +} + +data "google_provider_config_sdk" "default" {} +`, context) +} + +// testAccSdkProvider_add_terraform_attribution_label_inEnvsOnly allows testing when the add_terraform_attribution_label argument +// is only supplied via ENVs +func testAccSdkProvider_add_terraform_attribution_label_inEnvsOnly(context map[string]interface{}) string { + return acctest.Nprintf(` +data "google_provider_config_sdk" "default" {} +`, context) +} diff --git a/mmv1/third_party/terraform/provider/provider_terraform_attribution_label_addition_strategy_test.go b/mmv1/third_party/terraform/provider/provider_terraform_attribution_label_addition_strategy_test.go new file mode 100644 index 000000000000..a36af05cd2ec --- /dev/null +++ b/mmv1/third_party/terraform/provider/provider_terraform_attribution_label_addition_strategy_test.go @@ -0,0 +1,98 @@ +package provider_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-provider-google/google/acctest" +) + +// TestAccSdkProvider_terraform_attribution_label_addition_strategy is a series of acc tests asserting how the plugin-framework provider handles terraform_attribution_label_addition_strategy arguments +// It is plugin-framework specific because the HCL used provisions plugin-framework-implemented resources +// It is a counterpart to TestAccFwProvider_terraform_attribution_label_addition_strategy +func TestAccSdkProvider_terraform_attribution_label_addition_strategy(t *testing.T) { + testCases := map[string]func(t *testing.T){ + // Configuring the provider using inputs + "config sets terraform_attribution_label_addition_strategy values": testAccSdkProvider_terraform_attribution_label_addition_strategy_configUsed, + "when terraform_attribution_label_addition_strategy is unset in the config, the default value 'CREATION_ONLY' is set on the provider meta data": testAccSdkProvider_terraform_attribution_label_addition_strategy_defaultValue, + } + + for name, tc := range testCases { + // shadow the tc variable into scope so that when + // the loop continues, if t.Run hasn't executed tc(t) + // yet, we don't have a race condition + // see https://github.com/golang/go/wiki/CommonMistakes#using-goroutines-on-loop-iterator-variables + tc := tc + t.Run(name, func(t *testing.T) { + tc(t) + }) + } +} + +func testAccSdkProvider_terraform_attribution_label_addition_strategy_configUsed(t *testing.T) { + acctest.SkipIfVcr(t) // Test doesn't interact with API + + context1 := map[string]interface{}{ + "terraform_attribution_label_addition_strategy": "CREATION_ONLY", + } + context2 := map[string]interface{}{ + "terraform_attribution_label_addition_strategy": "PROACTIVE", + } + + acctest.VcrTest(t, resource.TestCase{ + // No PreCheck for checking ENVs + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + Steps: []resource.TestStep{ + { + Config: testAccSdkProvider_terraform_attribution_label_addition_strategy_inProviderBlock(context1), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("data.google_provider_config_sdk.default", "terraform_attribution_label_addition_strategy", "CREATION_ONLY"), + ), + }, + { + Config: testAccSdkProvider_terraform_attribution_label_addition_strategy_inProviderBlock(context2), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("data.google_provider_config_sdk.default", "terraform_attribution_label_addition_strategy", "PROACTIVE"), + ), + }, + }, + }) +} + +func testAccSdkProvider_terraform_attribution_label_addition_strategy_defaultValue(t *testing.T) { + acctest.SkipIfVcr(t) // Test doesn't interact with API + + context := map[string]interface{}{} + + acctest.VcrTest(t, resource.TestCase{ + // No PreCheck for checking ENVs + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + Steps: []resource.TestStep{ + { + Config: testAccSdkProvider_terraform_attribution_label_addition_strategy_inEnvsOnly(context), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("data.google_provider_config_sdk.default", "terraform_attribution_label_addition_strategy", "CREATION_ONLY"), + ), + }, + }, + }) +} + +// testAccSdkProvider_terraform_attribution_label_addition_strategy_inProviderBlock allows setting the terraform_attribution_label_addition_strategy argument in a provider block. +func testAccSdkProvider_terraform_attribution_label_addition_strategy_inProviderBlock(context map[string]interface{}) string { + return acctest.Nprintf(` +provider "google" { + terraform_attribution_label_addition_strategy = "%{terraform_attribution_label_addition_strategy}" +} + +data "google_provider_config_sdk" "default" {} +`, context) +} + +// testAccSdkProvider_terraform_attribution_label_addition_strategy_inEnvsOnly allows testing when the terraform_attribution_label_addition_strategy argument +// is only supplied via ENVs +func testAccSdkProvider_terraform_attribution_label_addition_strategy_inEnvsOnly(context map[string]interface{}) string { + return acctest.Nprintf(` +data "google_provider_config_sdk" "default" {} +`, context) +}