From d8bed571a5796ac4cebdbe58aaeb81bb2e483a24 Mon Sep 17 00:00:00 2001 From: Saurabh Uttam Date: Wed, 2 Aug 2023 04:34:02 +0000 Subject: [PATCH 01/14] Added PSC connectivity support in Cloud SQL Terraform --- mmv1/third_party/terraform/go.mod.erb | 4 +- .../sql/resource_sql_database_instance.go.erb | 66 +++++++++++++++++++ 2 files changed, 68 insertions(+), 2 deletions(-) diff --git a/mmv1/third_party/terraform/go.mod.erb b/mmv1/third_party/terraform/go.mod.erb index a35b7596aae7..01f5f3c5bfa5 100644 --- a/mmv1/third_party/terraform/go.mod.erb +++ b/mmv1/third_party/terraform/go.mod.erb @@ -26,8 +26,8 @@ require ( github.com/sirupsen/logrus v1.8.1 golang.org/x/net v0.12.0 golang.org/x/oauth2 v0.10.0 - google.golang.org/api v0.132.0 - google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 + google.golang.org/api v0.134.0 + google.golang.org/genproto/googleapis/rpc v0.0.0-20230720185612-659f7aaaa771 google.golang.org/grpc v1.56.2 google.golang.org/protobuf v1.31.0 ) diff --git a/mmv1/third_party/terraform/services/sql/resource_sql_database_instance.go.erb b/mmv1/third_party/terraform/services/sql/resource_sql_database_instance.go.erb index 2d173db79d3b..d4ed44637c07 100644 --- a/mmv1/third_party/terraform/services/sql/resource_sql_database_instance.go.erb +++ b/mmv1/third_party/terraform/services/sql/resource_sql_database_instance.go.erb @@ -64,6 +64,7 @@ var ( "settings.0.ip_configuration.0.private_network", "settings.0.ip_configuration.0.allocated_ip_range", "settings.0.ip_configuration.0.enable_private_path_for_google_cloud_services", + "settings.0.ip_configuration.0.psc_config", } maintenanceWindowKeys = []string{ @@ -451,6 +452,29 @@ is set to true. Defaults to ZONAL.`, AtLeastOneOf: ipConfigurationKeys, Description: `Whether Google Cloud services such as BigQuery are allowed to access data in this Cloud SQL instance over a private IP connection. SQLSERVER database type is not supported.`, }, + "psc_config": { + Type: schema.TypeSet, + Optional: true, + Description: `PSC settings for a Cloud SQL instance.`, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "psc_enabled": { + Type: schema.TypeBool, + Optional: true, + Description: `Whether PSC connectivity is enabled for this instance.`, + }, + "allowed_consumer_projects": { + Type: schema.TypeSet, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Set: schema.HashString, + Description: `List of consumer projects that are allow-listed for PSC connections to this instance. This instance can be connected to with PSC from any network in these projects. Each consumer project in this list may be represented by a project number (numeric) or by a project id (alphanumeric).`, + }, + }, + }, + }, }, }, }, @@ -868,6 +892,16 @@ is set to true. Defaults to ZONAL.`, Computed: true, Description: `The URI of the created resource.`, }, + "psc_service_attachment_link": { + Type: schema.TypeString, + Computed: true, + Description: `The link to service attachment of PSC instance.`, + }, + "dns_name": { + Type: schema.TypeString, + Computed: true, + Description: `The dns name of the instance.`, + }, "restore_backup_context": { Type: schema.TypeList, Optional: true, @@ -1336,7 +1370,20 @@ func expandIpConfiguration(configured []interface{}, databaseVersion string) *sq AuthorizedNetworks: expandAuthorizedNetworks(_ipConfiguration["authorized_networks"].(*schema.Set).List()), EnablePrivatePathForGoogleCloudServices: _ipConfiguration["enable_private_path_for_google_cloud_services"].(bool), ForceSendFields: forceSendFields, + PscConfig: expandPscConfig(_ipConfiguration["psc_config"].(*schema.Set).List()), + } +} + +func expandPscConfig(configured []interface{}) *sqladmin.PscConfig { + for _, _pscConfig := range configured { + _entry := _pscConfig.(map[string]interface{}) + return &sqladmin.PscConfig{ + PscEnabled: _entry["psc_enabled"].(bool), + AllowedConsumerProjects: convertStringArr(_entry["allowed_consumer_projects"].(*schema.Set).List()), + } } + + return nil } func expandAuthorizedNetworks(configured []interface{}) []*sqladmin.AclEntry { @@ -1604,6 +1651,12 @@ func resourceSqlDatabaseInstanceRead(d *schema.ResourceData, meta interface{}) e if err := d.Set("self_link", instance.SelfLink); err != nil { return fmt.Errorf("Error setting self_link: %s", err) } + if err := d.Set("psc_service_attachment_link", instance.PscServiceAttachmentLink); err != nil { + return fmt.Errorf("Error setting psc_service_attachment_link: %s", err) + } + if err := d.Set("dns_name", instance.DnsName); err != nil { + return fmt.Errorf("Error setting dns_name: %s", err) + } d.SetId(instance.Name) return nil @@ -2131,6 +2184,19 @@ func flattenIpConfiguration(ipConfiguration *sqladmin.IpConfiguration) interface data["authorized_networks"] = flattenAuthorizedNetworks(ipConfiguration.AuthorizedNetworks) } + if ipConfiguration.PscConfig != nil { + data["psc_config"] = flattenPscConfigs(ipConfiguration.PscConfig) + } + + return []map[string]interface{}{data} +} + +func flattenPscConfigs(pscConfig *sqladmin.PscConfig) interface{} { + data := map[string]interface{}{ + "psc_enabled": pscConfig.PscEnabled, + "allowed_consumer_projects": schema.NewSet(schema.HashString, convertStringArrToInterface(pscConfig.AllowedConsumerProjects)), + } + return []map[string]interface{}{data} } From 2fd056e381b4cc9ebe2fd74d582680660766d6e9 Mon Sep 17 00:00:00 2001 From: Saurabh Uttam Date: Wed, 2 Aug 2023 08:53:10 +0000 Subject: [PATCH 02/14] Added functional tests for PSC support in Cloud SQL --- .../resource_sql_database_instance_test.go | 299 ++++++++++++++++++ 1 file changed, 299 insertions(+) diff --git a/mmv1/third_party/terraform/tests/resource_sql_database_instance_test.go b/mmv1/third_party/terraform/tests/resource_sql_database_instance_test.go index 2e0941754f01..48e95c93b00a 100644 --- a/mmv1/third_party/terraform/tests/resource_sql_database_instance_test.go +++ b/mmv1/third_party/terraform/tests/resource_sql_database_instance_test.go @@ -3,6 +3,7 @@ package google import ( "fmt" "regexp" + "strings" "testing" "time" @@ -783,6 +784,180 @@ func TestAccSqlDatabaseInstance_withPrivateNetwork_withoutAllocatedIpRange(t *te }) } +func TestAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(t *testing.T) { + t.Parallel() + + instanceName := "tf-test-" + acctest.RandString(t, 10) + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + CheckDestroy: testAccSqlDatabaseInstanceDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(instanceName), + }, + { + ResourceName: "google_sql_database_instance.instance", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"deletion_protection"}, + }, + }, + }) +} + +func TestAccSqlDatabaseInstance_withPSCEnabled_withEmptyAllowedConsumerProjects(t *testing.T) { + t.Parallel() + + instanceName := "tf-test-" + acctest.RandString(t, 10) + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + CheckDestroy: testAccSqlDatabaseInstanceDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccSqlDatabaseInstance_withPSCEnabled_withEmptyAllowedConsumerProjects(instanceName), + }, + { + ResourceName: "google_sql_database_instance.instance", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"deletion_protection"}, + }, + }, + }) +} + +func TestAccSqlDatabaseInstance_withPSCEnabled_withAllowedConsumerProjects(t *testing.T) { + t.Parallel() + + instanceName := "tf-test-" + acctest.RandString(t, 10) + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + CheckDestroy: testAccSqlDatabaseInstanceDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccSqlDatabaseInstance_withPSCEnabled_withAllowedConsumerProjects(instanceName), + }, + { + ResourceName: "google_sql_database_instance.instance", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"deletion_protection"}, + }, + }, + }) +} + +func TestAccSqlDatabaseInstance_withPSCEnabled_thenAddAllowedConsumerProjects_thenRemoveAllowedConsumerProject(t *testing.T) { + t.Parallel() + + instanceName := "tf-test-" + acctest.RandString(t, 10) + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + CheckDestroy: testAccSqlDatabaseInstanceDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(instanceName), + }, + { + ResourceName: "google_sql_database_instance.instance", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"deletion_protection"}, + }, + { + Config: testAccSqlDatabaseInstance_withPSCEnabled_withAllowedConsumerProjects(instanceName), + }, + { + ResourceName: "google_sql_database_instance.instance", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"deletion_protection"}, + }, + { + Config: testAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(instanceName), + }, + { + ResourceName: "google_sql_database_instance.instance", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"deletion_protection"}, + }, + }, + }) +} + +func TestAccSqlDatabaseInstance_basicInstance_thenPSCEnabled(t *testing.T) { + t.Parallel() + + instanceName := "tf-test-" + acctest.RandString(t, 10) + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + CheckDestroy: testAccSqlDatabaseInstanceDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccSqlDatabaseInstance_basicInstanceForPsc(instanceName), + }, + { + ResourceName: "google_sql_database_instance.instance", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"deletion_protection"}, + }, + { + Config: testAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(instanceName), + }, + { + ResourceName: "google_sql_database_instance.instance", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"deletion_protection"}, + }, + }, + }) +} + +func TestAccSqlDatabaseInstance_withPSCEnabled_withIpV4Enabled(t *testing.T) { + t.Parallel() + + instanceName := "tf-test-" + acctest.RandString(t, 10) + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + CheckDestroy: testAccSqlDatabaseInstanceDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccSqlDatabaseInstance_basicInstanceForPsc(instanceName), + }, + { + ResourceName: "google_sql_database_instance.instance", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"deletion_protection"}, + }, + { + Config: testAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(instanceName), + }, + { + ResourceName: "google_sql_database_instance.instance", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"deletion_protection"}, + }, + }, + }) +} + func TestAccSqlDatabaseInstance_withPrivateNetwork_withAllocatedIpRange(t *testing.T) { // Service Networking acctest.SkipIfVcr(t) @@ -2394,6 +2569,130 @@ resource "google_sql_database_instance" "instance-failover" { `, instanceName, failoverName) } +func testAccSqlDatabaseInstance_basicInstanceForPsc(instanceName string) string { + return fmt.Sprintf(` +resource "google_sql_database_instance" "instance" { + name = "%s" + region = "us-central1" + database_version = "MYSQL_8_0" + deletion_protection = false + settings { + tier = "db-f1-micro" + } +} +`, instanceName) +} + +func testAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(instanceName string) string { + return fmt.Sprintf(` +resource "google_sql_database_instance" "instance" { + name = "%s" + region = "us-central1" + database_version = "MYSQL_8_0" + deletion_protection = false + settings { + tier = "db-f1-micro" + ip_configuration { + psc_config { + psc_enabled = true + } + } + } +} +`, instanceName) +} + +func testAccSqlDatabaseInstance_withPSCEnabled_withEmptyAllowedConsumerProjects(instanceName string) string { + return fmt.Sprintf(` +resource "google_sql_database_instance" "instance" { + name = "%s" + region = "us-central1" + database_version = "MYSQL_8_0" + deletion_protection = false + settings { + tier = "db-f1-micro" + ip_configuration { + psc_config { + psc_enabled = true + allowed_consumer_projects = [] + } + } + } +} +`, instanceName) +} + +func testAccSqlDatabaseInstance_withPSCEnabled_withAllowedConsumerProjects(instanceName string) string { + project_id := envvar.GetTestProjectFromEnv() + return fmt.Sprintf(` +resource "google_sql_database_instance" "instance" { + name = "%s" + region = "us-central1" + database_version = "MYSQL_8_0" + deletion_protection = false + settings { + tier = "db-f1-micro" + ip_configuration { + psc_config { + psc_enabled = true + allowed_consumer_projects = ["%s"] + } + } + } +} +`, instanceName, project_id) +} + +func verifyPscOperation(resourceName string, isPscConfigExpected bool, expectedPscEnabled bool, expectedAllowedConsumerProjects []string) func(*terraform.State) error +{ + return func(s *terraform.State) error { + resource, ok := s.RootModule().Resources[resourceName] + if !ok { + return fmt.Errorf("Can't find %s in state", resourceName) + } + + resourceAttributes := resource.Primary.Attributes + settings, ok := resourceAttributes["settings"] + if !ok { + return fmt.Errorf("settings block is not present in state for %s", resourceName) + } + + ipConfiguration, ok := settings["ip_configuration"] + if !ok { + return fmt.Errorf("ip_configuration block is not present in state of %s", resourceName) + } + + if isPscConfigExpected { + pscConfig, ok := ipConfiguration["psc_config"] + if !ok { + return fmt.Errorf("psc_config block is not present in state of %s", resourceName) + } + + pscEnabled, ok := pscConfig["psc_enabled"] + if !ok && expectedPscEnabled { + return fmt.Errorf("psc_enabled property is not present or set in state of %s", resourceName) + } + + if bool(pscEnabled) != expectedPscEnabled { + return fmt.Errorf("psc_enabled property value is not set as expected in state of %s, expected %v, actual %v", resourceName, expectedPscEnabled, pscEnabled) + } + + allowedConsumerProjects, ok := pscConfig["allowed_consumer_projects"] + if !ok && (allowedConsumerProjects != nil && len(expectedAllowedConsumerProjects) != 0) { + return fmt.Errorf("psc_enabled property is not present or set in state of %s", resourceName) + } + + sort.Strings(allowedConsumerProjects) + sort.Strings(expectedAllowedConsumerProjects) + if len(allowedConsumerProjects) != len(expectedAllowedConsumerProjects) || allowedConsumerProjects != expectedAllowedConsumerProjects { + return fmt.Errorf("psc_enabled property value is not set as expected in state of %s, expected %v, actual %v", resourceName, expectedAllowedConsumerProjects, allowedConsumerProjects) + } + } + + return nil + } +} + func testAccSqlDatabaseInstance_withPrivateNetwork_withoutAllocatedIpRange(databaseName, networkName, addressRangeName string, specifyPrivatePathOption bool, enablePrivatePath bool) string { privatePathOption := "" if specifyPrivatePathOption { From d8fd57d667abd5b3c3336ac29176c77bbd7fe7ca Mon Sep 17 00:00:00 2001 From: Saurabh Uttam Date: Wed, 2 Aug 2023 10:07:21 +0000 Subject: [PATCH 03/14] Added test fixes and compilation fixes --- .../sql/resource_sql_database_instance.go.erb | 4 +- .../resource_sql_database_instance_test.go | 53 +++++++++++-------- 2 files changed, 32 insertions(+), 25 deletions(-) diff --git a/mmv1/third_party/terraform/services/sql/resource_sql_database_instance.go.erb b/mmv1/third_party/terraform/services/sql/resource_sql_database_instance.go.erb index d4ed44637c07..28004b4c275d 100644 --- a/mmv1/third_party/terraform/services/sql/resource_sql_database_instance.go.erb +++ b/mmv1/third_party/terraform/services/sql/resource_sql_database_instance.go.erb @@ -1379,7 +1379,7 @@ func expandPscConfig(configured []interface{}) *sqladmin.PscConfig { _entry := _pscConfig.(map[string]interface{}) return &sqladmin.PscConfig{ PscEnabled: _entry["psc_enabled"].(bool), - AllowedConsumerProjects: convertStringArr(_entry["allowed_consumer_projects"].(*schema.Set).List()), + AllowedConsumerProjects: tpgresource.ConvertStringArr(_entry["allowed_consumer_projects"].(*schema.Set).List()), } } @@ -2194,7 +2194,7 @@ func flattenIpConfiguration(ipConfiguration *sqladmin.IpConfiguration) interface func flattenPscConfigs(pscConfig *sqladmin.PscConfig) interface{} { data := map[string]interface{}{ "psc_enabled": pscConfig.PscEnabled, - "allowed_consumer_projects": schema.NewSet(schema.HashString, convertStringArrToInterface(pscConfig.AllowedConsumerProjects)), + "allowed_consumer_projects": schema.NewSet(schema.HashString, tpgresource.ConvertStringArrToInterface(pscConfig.AllowedConsumerProjects)), } return []map[string]interface{}{data} diff --git a/mmv1/third_party/terraform/tests/resource_sql_database_instance_test.go b/mmv1/third_party/terraform/tests/resource_sql_database_instance_test.go index 48e95c93b00a..b513cc129f62 100644 --- a/mmv1/third_party/terraform/tests/resource_sql_database_instance_test.go +++ b/mmv1/third_party/terraform/tests/resource_sql_database_instance_test.go @@ -796,6 +796,7 @@ func TestAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(t Steps: []resource.TestStep{ { Config: testAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(instanceName), + Check: resource.ComposeTestCheckFunc(verifyPscOperation("google_sql_database_instance.instance", true, true, nil)), }, { ResourceName: "google_sql_database_instance.instance", @@ -819,6 +820,7 @@ func TestAccSqlDatabaseInstance_withPSCEnabled_withEmptyAllowedConsumerProjects( Steps: []resource.TestStep{ { Config: testAccSqlDatabaseInstance_withPSCEnabled_withEmptyAllowedConsumerProjects(instanceName), + Check: resource.ComposeTestCheckFunc(verifyPscOperation("google_sql_database_instance.instance", true, true, [])), }, { ResourceName: "google_sql_database_instance.instance", @@ -842,6 +844,7 @@ func TestAccSqlDatabaseInstance_withPSCEnabled_withAllowedConsumerProjects(t *te Steps: []resource.TestStep{ { Config: testAccSqlDatabaseInstance_withPSCEnabled_withAllowedConsumerProjects(instanceName), + Check: resource.ComposeTestCheckFunc(verifyPscOperation("google_sql_database_instance.instance", true, true, [envvar.GetTestProjectFromEnv()])), }, { ResourceName: "google_sql_database_instance.instance", @@ -865,6 +868,7 @@ func TestAccSqlDatabaseInstance_withPSCEnabled_thenAddAllowedConsumerProjects_th Steps: []resource.TestStep{ { Config: testAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(instanceName), + Check: resource.ComposeTestCheckFunc(verifyPscOperation("google_sql_database_instance.instance", true, true, nil)), }, { ResourceName: "google_sql_database_instance.instance", @@ -874,6 +878,7 @@ func TestAccSqlDatabaseInstance_withPSCEnabled_thenAddAllowedConsumerProjects_th }, { Config: testAccSqlDatabaseInstance_withPSCEnabled_withAllowedConsumerProjects(instanceName), + Check: resource.ComposeTestCheckFunc(verifyPscOperation("google_sql_database_instance.instance", true, true, [envvar.GetTestProjectFromEnv()])), }, { ResourceName: "google_sql_database_instance.instance", @@ -883,6 +888,7 @@ func TestAccSqlDatabaseInstance_withPSCEnabled_thenAddAllowedConsumerProjects_th }, { Config: testAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(instanceName), + Check: resource.ComposeTestCheckFunc(verifyPscOperation("google_sql_database_instance.instance", true, true, [])), }, { ResourceName: "google_sql_database_instance.instance", @@ -915,12 +921,7 @@ func TestAccSqlDatabaseInstance_basicInstance_thenPSCEnabled(t *testing.T) { }, { Config: testAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(instanceName), - }, - { - ResourceName: "google_sql_database_instance.instance", - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"deletion_protection"}, + ExpectError: regexp.MustCompile("Can not enable PSC"), }, }, }) @@ -937,23 +938,9 @@ func TestAccSqlDatabaseInstance_withPSCEnabled_withIpV4Enabled(t *testing.T) { CheckDestroy: testAccSqlDatabaseInstanceDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccSqlDatabaseInstance_basicInstanceForPsc(instanceName), - }, - { - ResourceName: "google_sql_database_instance.instance", - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"deletion_protection"}, - }, - { - Config: testAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(instanceName), - }, - { - ResourceName: "google_sql_database_instance.instance", - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"deletion_protection"}, - }, + Config: testAccSqlDatabaseInstance_withPSCEnabled_withIpV4Enable(instanceName), + ExpectError: regexp.MustCompile("Can not enable PSC"), + } }, }) } @@ -2583,6 +2570,26 @@ resource "google_sql_database_instance" "instance" { `, instanceName) } +func testAccSqlDatabaseInstance_withPSCEnabled_withIpV4Enable(instanceName string) string { + return fmt.Sprintf(` +resource "google_sql_database_instance" "instance" { + name = "%s" + region = "us-central1" + database_version = "MYSQL_8_0" + deletion_protection = false + settings { + tier = "db-f1-micro" + ip_configuration { + psc_config { + psc_enabled = true + } + ipv4_enabled = true + } + } +} +`, instanceName) +} + func testAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(instanceName string) string { return fmt.Sprintf(` resource "google_sql_database_instance" "instance" { From 6e3be2a0c843f1c2b119ae60b1f3bd213681b60e Mon Sep 17 00:00:00 2001 From: Saurabh Uttam Date: Thu, 3 Aug 2023 12:01:47 +0000 Subject: [PATCH 04/14] Fixed test cases --- .../resource_sql_database_instance_test.go | 92 +++++++++++-------- 1 file changed, 53 insertions(+), 39 deletions(-) diff --git a/mmv1/third_party/terraform/tests/resource_sql_database_instance_test.go b/mmv1/third_party/terraform/tests/resource_sql_database_instance_test.go index b513cc129f62..6cf18c7643a8 100644 --- a/mmv1/third_party/terraform/tests/resource_sql_database_instance_test.go +++ b/mmv1/third_party/terraform/tests/resource_sql_database_instance_test.go @@ -3,7 +3,7 @@ package google import ( "fmt" "regexp" - "strings" + "strconv" "testing" "time" @@ -796,7 +796,7 @@ func TestAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(t Steps: []resource.TestStep{ { Config: testAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(instanceName), - Check: resource.ComposeTestCheckFunc(verifyPscOperation("google_sql_database_instance.instance", true, true, nil)), + Check: resource.ComposeTestCheckFunc(verifyPscOperation("google_sql_database_instance.instance", true, true, nil)), }, { ResourceName: "google_sql_database_instance.instance", @@ -820,7 +820,7 @@ func TestAccSqlDatabaseInstance_withPSCEnabled_withEmptyAllowedConsumerProjects( Steps: []resource.TestStep{ { Config: testAccSqlDatabaseInstance_withPSCEnabled_withEmptyAllowedConsumerProjects(instanceName), - Check: resource.ComposeTestCheckFunc(verifyPscOperation("google_sql_database_instance.instance", true, true, [])), + Check: resource.ComposeTestCheckFunc(verifyPscOperation("google_sql_database_instance.instance", true, true, []string{})), }, { ResourceName: "google_sql_database_instance.instance", @@ -844,7 +844,7 @@ func TestAccSqlDatabaseInstance_withPSCEnabled_withAllowedConsumerProjects(t *te Steps: []resource.TestStep{ { Config: testAccSqlDatabaseInstance_withPSCEnabled_withAllowedConsumerProjects(instanceName), - Check: resource.ComposeTestCheckFunc(verifyPscOperation("google_sql_database_instance.instance", true, true, [envvar.GetTestProjectFromEnv()])), + Check: resource.ComposeTestCheckFunc(verifyPscOperation("google_sql_database_instance.instance", true, true, []string{envvar.GetTestProjectFromEnv()})), }, { ResourceName: "google_sql_database_instance.instance", @@ -868,7 +868,7 @@ func TestAccSqlDatabaseInstance_withPSCEnabled_thenAddAllowedConsumerProjects_th Steps: []resource.TestStep{ { Config: testAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(instanceName), - Check: resource.ComposeTestCheckFunc(verifyPscOperation("google_sql_database_instance.instance", true, true, nil)), + Check: resource.ComposeTestCheckFunc(verifyPscOperation("google_sql_database_instance.instance", true, true, nil)), }, { ResourceName: "google_sql_database_instance.instance", @@ -878,7 +878,7 @@ func TestAccSqlDatabaseInstance_withPSCEnabled_thenAddAllowedConsumerProjects_th }, { Config: testAccSqlDatabaseInstance_withPSCEnabled_withAllowedConsumerProjects(instanceName), - Check: resource.ComposeTestCheckFunc(verifyPscOperation("google_sql_database_instance.instance", true, true, [envvar.GetTestProjectFromEnv()])), + Check: resource.ComposeTestCheckFunc(verifyPscOperation("google_sql_database_instance.instance", true, true, []string{envvar.GetTestProjectFromEnv()})), }, { ResourceName: "google_sql_database_instance.instance", @@ -888,7 +888,7 @@ func TestAccSqlDatabaseInstance_withPSCEnabled_thenAddAllowedConsumerProjects_th }, { Config: testAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(instanceName), - Check: resource.ComposeTestCheckFunc(verifyPscOperation("google_sql_database_instance.instance", true, true, [])), + Check: resource.ComposeTestCheckFunc(verifyPscOperation("google_sql_database_instance.instance", true, true, []string{})), }, { ResourceName: "google_sql_database_instance.instance", @@ -920,8 +920,8 @@ func TestAccSqlDatabaseInstance_basicInstance_thenPSCEnabled(t *testing.T) { ImportStateVerifyIgnore: []string{"deletion_protection"}, }, { - Config: testAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(instanceName), - ExpectError: regexp.MustCompile("Can not enable PSC"), + Config: testAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(instanceName), + ExpectError: regexp.MustCompile("PSC connectivity can not be enabled"), }, }, }) @@ -938,9 +938,9 @@ func TestAccSqlDatabaseInstance_withPSCEnabled_withIpV4Enabled(t *testing.T) { CheckDestroy: testAccSqlDatabaseInstanceDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccSqlDatabaseInstance_withPSCEnabled_withIpV4Enable(instanceName), - ExpectError: regexp.MustCompile("Can not enable PSC"), - } + Config: testAccSqlDatabaseInstance_withPSCEnabled_withIpV4Enable(instanceName), + ExpectError: regexp.MustCompile("PSC connectivity cannot be enabled together with public IP"), + }, }, }) } @@ -2565,6 +2565,11 @@ resource "google_sql_database_instance" "instance" { deletion_protection = false settings { tier = "db-f1-micro" + backup_configuration { + enabled = true + binary_log_enabled = true + } + availability_type = "REGIONAL" } } `, instanceName) @@ -2585,6 +2590,11 @@ resource "google_sql_database_instance" "instance" { } ipv4_enabled = true } + backup_configuration { + enabled = true + binary_log_enabled = true + } + availability_type = "REGIONAL" } } `, instanceName) @@ -2603,7 +2613,13 @@ resource "google_sql_database_instance" "instance" { psc_config { psc_enabled = true } + ipv4_enabled = false } + backup_configuration { + enabled = true + binary_log_enabled = true + } + availability_type = "REGIONAL" } } `, instanceName) @@ -2623,7 +2639,13 @@ resource "google_sql_database_instance" "instance" { psc_enabled = true allowed_consumer_projects = [] } + ipv4_enabled = false } + backup_configuration { + enabled = true + binary_log_enabled = true + } + availability_type = "REGIONAL" } } `, instanceName) @@ -2644,14 +2666,19 @@ resource "google_sql_database_instance" "instance" { psc_enabled = true allowed_consumer_projects = ["%s"] } + ipv4_enabled = false } + backup_configuration { + enabled = true + binary_log_enabled = true + } + availability_type = "REGIONAL" } } `, instanceName, project_id) } -func verifyPscOperation(resourceName string, isPscConfigExpected bool, expectedPscEnabled bool, expectedAllowedConsumerProjects []string) func(*terraform.State) error -{ +func verifyPscOperation(resourceName string, isPscConfigExpected bool, expectedPscEnabled bool, expectedAllowedConsumerProjects []string) func(*terraform.State) error { return func(s *terraform.State) error { resource, ok := s.RootModule().Resources[resourceName] if !ok { @@ -2659,40 +2686,27 @@ func verifyPscOperation(resourceName string, isPscConfigExpected bool, expectedP } resourceAttributes := resource.Primary.Attributes - settings, ok := resourceAttributes["settings"] - if !ok { - return fmt.Errorf("settings block is not present in state for %s", resourceName) - } - - ipConfiguration, ok := settings["ip_configuration"] + _, ok = resourceAttributes["settings.0.ip_configuration.#"] if !ok { - return fmt.Errorf("ip_configuration block is not present in state of %s", resourceName) + return fmt.Errorf("settings.0.ip_configuration.# block is not present in state for %s", resourceName) } if isPscConfigExpected { - pscConfig, ok := ipConfiguration["psc_config"] + _, ok := resourceAttributes["settings.0.ip_configuration.0.psc_config.#"] if !ok { - return fmt.Errorf("psc_config block is not present in state of %s", resourceName) - } - - pscEnabled, ok := pscConfig["psc_enabled"] - if !ok && expectedPscEnabled { - return fmt.Errorf("psc_enabled property is not present or set in state of %s", resourceName) - } - - if bool(pscEnabled) != expectedPscEnabled { - return fmt.Errorf("psc_enabled property value is not set as expected in state of %s, expected %v, actual %v", resourceName, expectedPscEnabled, pscEnabled) + return fmt.Errorf("settings.0.ip_configuration.0.psc_config property is not present or set in state of %s", resourceName) } - allowedConsumerProjects, ok := pscConfig["allowed_consumer_projects"] - if !ok && (allowedConsumerProjects != nil && len(expectedAllowedConsumerProjects) != 0) { - return fmt.Errorf("psc_enabled property is not present or set in state of %s", resourceName) + pscEnabledStr, ok := resourceAttributes["settings.0.ip_configuration.0.psc_config.0.psc_enabled"] + pscEnabled, err := strconv.ParseBool(pscEnabledStr) + if err != nil || pscEnabled != expectedPscEnabled { + return fmt.Errorf("settings.0.ip_configuration.0.psc_config.0.psc_enabled property value is not set as expected in state of %s, expected %v, actual %v", resourceName, expectedPscEnabled, pscEnabled) } - sort.Strings(allowedConsumerProjects) - sort.Strings(expectedAllowedConsumerProjects) - if len(allowedConsumerProjects) != len(expectedAllowedConsumerProjects) || allowedConsumerProjects != expectedAllowedConsumerProjects { - return fmt.Errorf("psc_enabled property value is not set as expected in state of %s, expected %v, actual %v", resourceName, expectedAllowedConsumerProjects, allowedConsumerProjects) + allowedConsumerProjectsStr, ok := resourceAttributes["settings.0.ip_configuration.0.psc_config.0.allowed_consumer_projects.#"] + allowedConsumerProjects, err := strconv.Atoi(allowedConsumerProjectsStr) + if !ok || allowedConsumerProjects != len(expectedAllowedConsumerProjects) { + return fmt.Errorf("settings.0.ip_configuration.0.psc_config.0.allowed_consumer_projects property is not present or set as expected in state of %s", resourceName) } } From 165e067946b1b0757c4f1036072bc6413cd7fc86 Mon Sep 17 00:00:00 2001 From: Saurabh Uttam Date: Tue, 8 Aug 2023 04:17:05 +0000 Subject: [PATCH 05/14] Upgraded google.golang.org/api to v0.135.0 --- mmv1/third_party/terraform/go.mod.erb | 6 +++--- mmv1/third_party/terraform/go.sum | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/mmv1/third_party/terraform/go.mod.erb b/mmv1/third_party/terraform/go.mod.erb index 01f5f3c5bfa5..c20da4d632e7 100644 --- a/mmv1/third_party/terraform/go.mod.erb +++ b/mmv1/third_party/terraform/go.mod.erb @@ -26,9 +26,9 @@ require ( github.com/sirupsen/logrus v1.8.1 golang.org/x/net v0.12.0 golang.org/x/oauth2 v0.10.0 - google.golang.org/api v0.134.0 - google.golang.org/genproto/googleapis/rpc v0.0.0-20230720185612-659f7aaaa771 - google.golang.org/grpc v1.56.2 + google.golang.org/api v0.135.0 + google.golang.org/genproto/googleapis/rpc v0.0.0-20230726155614-23370e0ffb3e + google.golang.org/grpc v1.57.0 google.golang.org/protobuf v1.31.0 ) diff --git a/mmv1/third_party/terraform/go.sum b/mmv1/third_party/terraform/go.sum index 1ffa419204b3..39d56e2d4411 100644 --- a/mmv1/third_party/terraform/go.sum +++ b/mmv1/third_party/terraform/go.sum @@ -426,6 +426,8 @@ google.golang.org/api v0.130.0 h1:A50ujooa1h9iizvfzA4rrJr2B7uRmWexwbekQ2+5FPQ= google.golang.org/api v0.130.0/go.mod h1:J/LCJMYSDFvAVREGCbrESb53n4++NMBDetSHGL5I5RY= google.golang.org/api v0.132.0 h1:8t2/+qZ26kAOGSmOiHwVycqVaDg7q3JDILrNi/Z6rvc= google.golang.org/api v0.132.0/go.mod h1:AeTBC6GpJnJSRJjktDcPX0QwtS8pGYZOV6MSuSCusw0= +google.golang.org/api v0.135.0 h1:6Vgfj6uPMXcyy66waYWBwmkeNB+9GmUlJDOzkukPQYQ= +google.golang.org/api v0.135.0/go.mod h1:Bp77uRFgwsSKI0BWH573F5Q6wSlznwI2NFayLOp/7mQ= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= @@ -448,6 +450,8 @@ google.golang.org/genproto/googleapis/rpc v0.0.0-20230629202037-9506855d4529 h1: google.golang.org/genproto/googleapis/rpc v0.0.0-20230629202037-9506855d4529/go.mod h1:66JfowdXAEgad5O9NnYcsNPLCPZJD++2L9X0PCMODrA= google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 h1:bVf09lpb+OJbByTj913DRJioFFAjf/ZGxEz7MajTp2U= google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98/go.mod h1:TUfxEVdsvPg18p6AslUXFoLdpED4oBnGwyqk3dV1XzM= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230726155614-23370e0ffb3e h1:S83+ibolgyZ0bqz7KEsUOPErxcv4VzlszxY+31OfB/E= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230726155614-23370e0ffb3e/go.mod h1:TUfxEVdsvPg18p6AslUXFoLdpED4oBnGwyqk3dV1XzM= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= @@ -461,6 +465,8 @@ google.golang.org/grpc v1.56.1 h1:z0dNfjIl0VpaZ9iSVjA6daGatAYwPGstTjt5vkRMFkQ= google.golang.org/grpc v1.56.1/go.mod h1:I9bI3vqKfayGqPUAwGdOSu7kt6oIJLixfffKrpXqQ9s= google.golang.org/grpc v1.56.2 h1:fVRFRnXvU+x6C4IlHZewvJOVHoOv1TUuQyoRsYnB4bI= google.golang.org/grpc v1.56.2/go.mod h1:I9bI3vqKfayGqPUAwGdOSu7kt6oIJLixfffKrpXqQ9s= +google.golang.org/grpc v1.57.0 h1:kfzNeI/klCGD2YPMUlaGNT3pxvYfga7smW3Vth8Zsiw= +google.golang.org/grpc v1.57.0/go.mod h1:Sd+9RMTACXwmub0zcNY2c4arhtrbBYD1AUHI/dt16Mo= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= From da7f9ee6821535cfc623d326b72e16d268b3f642 Mon Sep 17 00:00:00 2001 From: Saurabh Uttam Date: Tue, 8 Aug 2023 06:04:03 +0000 Subject: [PATCH 06/14] Added documentation for PSC configuration support --- .../r/sql_database_instance.html.markdown | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/mmv1/third_party/terraform/website/docs/r/sql_database_instance.html.markdown b/mmv1/third_party/terraform/website/docs/r/sql_database_instance.html.markdown index 717ac3d67256..7cf741ed9260 100644 --- a/mmv1/third_party/terraform/website/docs/r/sql_database_instance.html.markdown +++ b/mmv1/third_party/terraform/website/docs/r/sql_database_instance.html.markdown @@ -173,6 +173,30 @@ resource "google_sql_database_instance" "main" { } ``` +### Cloud SQL Instance with PSC connectivity + +```hcl +resource "google_sql_database_instance" "main" { + name = "psc-enabled-main-instance" + database_version = "MYSQL_8_0" + settings { + tier = "db-f1-micro" + ip_configuration { + psc_config { + psc_enabled = true + allowed_consumer_projects = ["allowed-consumer-project-name"] + } + ipv4_enabled = false + } + backup_configuration { + enabled = true + binary_log_enabled = true + } + availability_type = "REGIONAL" + } +} +``` + ## Argument Reference The following arguments are supported: @@ -325,7 +349,7 @@ The optional `settings.backup_configuration` subblock supports: * `location` - (Optional) The region where the backup will be stored -* `transaction_log_retention_days` - (Optional) The number of days of transaction logs we retain for point in time restore, from 1-7. For PostgreSQL Enterprise Plus instances, the number of days of retained transaction logs can be set from 1 to 35. +* `transaction_log_retention_days` - (Optional) The number of days of transaction logs we retain for point in time restore, from 1-7. For PostgreSQL Enterprise Plus instances, the number of days of retained transaction logs can be set from 1 to 35. * `backup_retention_settings` - (Optional) Backup retention settings. The configuration is detailed below. @@ -365,6 +389,12 @@ The optional `settings.ip_configuration.authorized_networks[]` sublist supports: access this instance. Must be set even if other two attributes are not for the whitelist to become active. +The optional `settings.ip_configuration.psc_config` sublist supports: + +* `psc_enabled` - (Optional) Whether PSC connectivity is enabled for this instance. + +* `allowed_consumer_projects` - (Optional) List of consumer projects that are allow-listed for PSC connections to this instance. This instance can be connected to with PSC from any network in these projects. Each consumer project in this list may be represented by a project number (numeric) or by a project id (alphanumeric). + The optional `settings.location_preference` subblock supports: * `follow_gae_application` - (Optional) A GAE application whose zone to remain From 6f28e046d0a9ad97d3d22e7997371e284fc8afe6 Mon Sep 17 00:00:00 2001 From: Saurabh Uttam Date: Tue, 8 Aug 2023 08:11:21 +0000 Subject: [PATCH 07/14] Fixed go.sum file --- mmv1/third_party/terraform/go.sum | 1 + 1 file changed, 1 insertion(+) diff --git a/mmv1/third_party/terraform/go.sum b/mmv1/third_party/terraform/go.sum index fae769d18f10..22b7ce4f1832 100644 --- a/mmv1/third_party/terraform/go.sum +++ b/mmv1/third_party/terraform/go.sum @@ -360,6 +360,7 @@ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= +golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= From 9c12f80e277eaf0e1e6b872b67f7ba34850884e7 Mon Sep 17 00:00:00 2001 From: Saurabh Uttam Date: Tue, 8 Aug 2023 08:21:45 +0000 Subject: [PATCH 08/14] Fixed go mod and go sum file --- mmv1/third_party/terraform/go.mod.erb | 1 + mmv1/third_party/terraform/go.sum | 26 -------------------------- 2 files changed, 1 insertion(+), 26 deletions(-) diff --git a/mmv1/third_party/terraform/go.mod.erb b/mmv1/third_party/terraform/go.mod.erb index c20da4d632e7..557ae0436663 100644 --- a/mmv1/third_party/terraform/go.mod.erb +++ b/mmv1/third_party/terraform/go.mod.erb @@ -86,6 +86,7 @@ require ( github.com/zclconf/go-cty v1.11.0 // indirect go.opencensus.io v0.24.0 // indirect golang.org/x/crypto v0.11.0 // indirect + golang.org/x/sync v0.3.0 // indirect golang.org/x/sys v0.10.0 // indirect golang.org/x/text v0.11.0 // indirect golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect diff --git a/mmv1/third_party/terraform/go.sum b/mmv1/third_party/terraform/go.sum index 22b7ce4f1832..4fc01560c0c1 100644 --- a/mmv1/third_party/terraform/go.sum +++ b/mmv1/third_party/terraform/go.sum @@ -2,22 +2,16 @@ bitbucket.org/creachadair/stringset v0.0.8 h1:gQqe4vs8XWgMyijfyKE6K8o4TcyGGrRXe0 bitbucket.org/creachadair/stringset v0.0.8/go.mod h1:AgthVMyMxC/6FK1KBJ2ALdqkZObGN8hOetgpwXyMn34= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cloud.google.com/go v0.110.2 h1:sdFPBr6xG9/wkBbfhmUz/JmZC7X6LavQgcrVINrKiVA= -cloud.google.com/go v0.110.2/go.mod h1:k04UEeEtb6ZBRTv3dZz4CeJC3jKGxyhl0sAiVVquxiw= cloud.google.com/go v0.110.4 h1:1JYyxKMN9hd5dR2MYTPWkGUgcoxVVhg0LKNKEo0qvmk= cloud.google.com/go v0.110.4/go.mod h1:+EYjdK8e5RME/VY/qLCAtuyALQ9q67dvuum8i+H5xsI= cloud.google.com/go/bigtable v1.19.0 h1:wiq9LT0kukfInzvy1joMDijCw/OD1UChpSbORXYn0LI= cloud.google.com/go/bigtable v1.19.0/go.mod h1:xl5kPa8PTkJjdBxg6qdGH88464nNqmbISHSRU+D2yFE= -cloud.google.com/go/compute v1.19.3 h1:DcTwsFgGev/wV5+q8o2fzgcHOaac+DKGC91ZlvpsQds= -cloud.google.com/go/compute v1.19.3/go.mod h1:qxvISKp/gYnXkSAD1ppcSOveRAmzxicEv/JlizULFrI= cloud.google.com/go/compute v1.20.1 h1:6aKEtlUiwEpJzM001l0yFkpXmUVXaN8W+fbkb2AZNbg= cloud.google.com/go/compute v1.20.1/go.mod h1:4tCnrn48xsqlwSAiLf1HXMQk8CONslYbdiEZc9FEIbM= cloud.google.com/go/compute/metadata v0.2.3 h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGBW5aJ7UnBMY= cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2AawlZn8kiOGuCv6gTkwuA= cloud.google.com/go/iam v1.1.0 h1:67gSqaPukx7O8WLLHMa0PNs3EBGd2eE4d+psbO/CO94= cloud.google.com/go/iam v1.1.0/go.mod h1:nxdHjaKfCr7fNYx/HJMM8LgiMugmveWlkatear5gVyk= -cloud.google.com/go/longrunning v0.5.0 h1:DK8BH0+hS+DIvc9a2TPnteUievsTCH4ORMAASSb7JcQ= -cloud.google.com/go/longrunning v0.5.0/go.mod h1:0JNuqRShmscVAhIACGtskSAWtqtOoPkwP0YF1oVEchc= cloud.google.com/go/longrunning v0.5.1 h1:Fr7TXftcqTudoyRJa113hyaqlGdiBQkp0Gq7tErFDWI= cloud.google.com/go/longrunning v0.5.1/go.mod h1:spvimkwdz6SPWKEt/XBij79E9fiTkHSQl/fRUUQJYJc= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= @@ -148,8 +142,6 @@ github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/enterprise-certificate-proxy v0.2.5 h1:UR4rDjcgpgEnqpIEvkiqTYKBCKLNmlge2eVjoZfySzM= github.com/googleapis/enterprise-certificate-proxy v0.2.5/go.mod h1:RxW0N9901Cko1VOCW3SXCpWP+mlIEkk2tP7jnHy9a3w= -github.com/googleapis/gax-go/v2 v2.11.0 h1:9V9PWXEsWnPpQhu/PeQIkS4eGzMlTLGgt80cUUI8Ki4= -github.com/googleapis/gax-go/v2 v2.11.0/go.mod h1:DxmR61SGKkGLa2xigwuZIQpkCI2S5iydzRfb3peWZJI= github.com/googleapis/gax-go/v2 v2.12.0 h1:A+gCJKdRfqXkr+BIRGtZLibNXf0m1f9E4HG56etFpas= github.com/googleapis/gax-go/v2 v2.12.0/go.mod h1:y+aIqrI5eb1YGMVJfuV3185Ts/D7qKpsEkdD5+I6QGU= github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 h1:+9834+KizmvFV7pXQGSXQTsaWhq2GjuNUt0aUU0YBYw= @@ -348,8 +340,6 @@ golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.9.0 h1:BPpt2kU7oMRq3kCHAA1tbSEshXRw1LpG2ztgDwrzuAs= -golang.org/x/oauth2 v0.9.0/go.mod h1:qYgFZaFiu6Wg24azG8bdV52QJXJGbZzIIsRCdVKzbLw= golang.org/x/oauth2 v0.10.0 h1:zHCpF2Khkwy4mMB4bv0U37YtJdTGW8jI0glAApi0Kh8= golang.org/x/oauth2 v0.10.0/go.mod h1:kTpgurOux7LqtuxjuyZa4Gj2gdezIt/jQtGnNFfypQI= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -414,10 +404,6 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 h1:H2TDz8ibqkAF6YGhCdN3jS9O0/s90v0rJh3X/OLHEUk= golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8= -google.golang.org/api v0.130.0 h1:A50ujooa1h9iizvfzA4rrJr2B7uRmWexwbekQ2+5FPQ= -google.golang.org/api v0.130.0/go.mod h1:J/LCJMYSDFvAVREGCbrESb53n4++NMBDetSHGL5I5RY= -google.golang.org/api v0.132.0 h1:8t2/+qZ26kAOGSmOiHwVycqVaDg7q3JDILrNi/Z6rvc= -google.golang.org/api v0.132.0/go.mod h1:AeTBC6GpJnJSRJjktDcPX0QwtS8pGYZOV6MSuSCusw0= google.golang.org/api v0.135.0 h1:6Vgfj6uPMXcyy66waYWBwmkeNB+9GmUlJDOzkukPQYQ= google.golang.org/api v0.135.0/go.mod h1:Bp77uRFgwsSKI0BWH573F5Q6wSlznwI2NFayLOp/7mQ= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= @@ -430,18 +416,10 @@ google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98 google.golang.org/genproto v0.0.0-20200423170343-7949de9c1215/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= -google.golang.org/genproto v0.0.0-20230530153820-e85fd2cbaebc h1:8DyZCyvI8mE1IdLy/60bS+52xfymkE72wv1asokgtao= -google.golang.org/genproto v0.0.0-20230530153820-e85fd2cbaebc/go.mod h1:xZnkP7mREFX5MORlOPEzLMr+90PPZQ2QWzrVTWfAq64= google.golang.org/genproto v0.0.0-20230706204954-ccb25ca9f130 h1:Au6te5hbKUV8pIYWHqOUZ1pva5qK/rwbIhoXEUB9Lu8= google.golang.org/genproto v0.0.0-20230706204954-ccb25ca9f130/go.mod h1:O9kGHb51iE/nOGvQaDUuadVYqovW56s5emA88lQnj6Y= -google.golang.org/genproto/googleapis/api v0.0.0-20230530153820-e85fd2cbaebc h1:kVKPf/IiYSBWEWtkIn6wZXwWGCnLKcC8oWfZvXjsGnM= -google.golang.org/genproto/googleapis/api v0.0.0-20230530153820-e85fd2cbaebc/go.mod h1:vHYtlOoi6TsQ3Uk2yxR7NI5z8uoV+3pZtR4jmHIkRig= google.golang.org/genproto/googleapis/api v0.0.0-20230706204954-ccb25ca9f130 h1:XVeBY8d/FaK4848myy41HBqnDwvxeV3zMZhwN1TvAMU= google.golang.org/genproto/googleapis/api v0.0.0-20230706204954-ccb25ca9f130/go.mod h1:mPBs5jNgx2GuQGvFwUvVKqtn6HsUw9nP64BedgvqEsQ= -google.golang.org/genproto/googleapis/rpc v0.0.0-20230629202037-9506855d4529 h1:DEH99RbiLZhMxrpEJCZ0A+wdTe0EOgou/poSLx9vWf4= -google.golang.org/genproto/googleapis/rpc v0.0.0-20230629202037-9506855d4529/go.mod h1:66JfowdXAEgad5O9NnYcsNPLCPZJD++2L9X0PCMODrA= -google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 h1:bVf09lpb+OJbByTj913DRJioFFAjf/ZGxEz7MajTp2U= -google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98/go.mod h1:TUfxEVdsvPg18p6AslUXFoLdpED4oBnGwyqk3dV1XzM= google.golang.org/genproto/googleapis/rpc v0.0.0-20230726155614-23370e0ffb3e h1:S83+ibolgyZ0bqz7KEsUOPErxcv4VzlszxY+31OfB/E= google.golang.org/genproto/googleapis/rpc v0.0.0-20230726155614-23370e0ffb3e/go.mod h1:TUfxEVdsvPg18p6AslUXFoLdpED4oBnGwyqk3dV1XzM= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= @@ -453,10 +431,6 @@ google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTp google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= google.golang.org/grpc v1.45.0/go.mod h1:lN7owxKUQEqMfSyQikvvk5tf/6zMPsrK+ONuO11+0rQ= -google.golang.org/grpc v1.56.1 h1:z0dNfjIl0VpaZ9iSVjA6daGatAYwPGstTjt5vkRMFkQ= -google.golang.org/grpc v1.56.1/go.mod h1:I9bI3vqKfayGqPUAwGdOSu7kt6oIJLixfffKrpXqQ9s= -google.golang.org/grpc v1.56.2 h1:fVRFRnXvU+x6C4IlHZewvJOVHoOv1TUuQyoRsYnB4bI= -google.golang.org/grpc v1.56.2/go.mod h1:I9bI3vqKfayGqPUAwGdOSu7kt6oIJLixfffKrpXqQ9s= google.golang.org/grpc v1.57.0 h1:kfzNeI/klCGD2YPMUlaGNT3pxvYfga7smW3Vth8Zsiw= google.golang.org/grpc v1.57.0/go.mod h1:Sd+9RMTACXwmub0zcNY2c4arhtrbBYD1AUHI/dt16Mo= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= From 7c8af1c848d9d76486e7f4d78ffcb77fda84ec5f Mon Sep 17 00:00:00 2001 From: Saurabh Uttam Date: Wed, 16 Aug 2023 16:41:50 +0000 Subject: [PATCH 09/14] Modified test case --- .../sql/resource_sql_database_instance_test.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/mmv1/third_party/terraform/services/sql/resource_sql_database_instance_test.go b/mmv1/third_party/terraform/services/sql/resource_sql_database_instance_test.go index 0f0765795e53..8d610c10d32c 100644 --- a/mmv1/third_party/terraform/services/sql/resource_sql_database_instance_test.go +++ b/mmv1/third_party/terraform/services/sql/resource_sql_database_instance_test.go @@ -789,6 +789,7 @@ func TestAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(t t.Parallel() instanceName := "tf-test-" + acctest.RandString(t, 10) + project_id := "psctestproject" + acctest.RandString(t, 10) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -796,7 +797,7 @@ func TestAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(t CheckDestroy: testAccSqlDatabaseInstanceDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(instanceName), + Config: testAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(instanceName, project_id), Check: resource.ComposeTestCheckFunc(verifyPscOperation("google_sql_database_instance.instance", true, true, nil)), }, { @@ -2601,9 +2602,15 @@ resource "google_sql_database_instance" "instance" { `, instanceName) } -func testAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(instanceName string) string { +func testAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(instanceName string, project_id string) string { return fmt.Sprintf(` +resource "google_project" "testproject" { + name = "%s" + project_id = "%s" +} + resource "google_sql_database_instance" "instance" { + project = google_project.testproject.project_id name = "%s" region = "us-central1" database_version = "MYSQL_8_0" @@ -2623,7 +2630,7 @@ resource "google_sql_database_instance" "instance" { availability_type = "REGIONAL" } } -`, instanceName) +`, project_id, project_id, instanceName) } func testAccSqlDatabaseInstance_withPSCEnabled_withEmptyAllowedConsumerProjects(instanceName string) string { From 160a30777085de6ce8da0533fab2860e18a9f0bb Mon Sep 17 00:00:00 2001 From: Saurabh Uttam Date: Thu, 17 Aug 2023 17:10:33 +0000 Subject: [PATCH 10/14] Fixed test case failure --- .../services/sql/resource_sql_database_instance_test.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mmv1/third_party/terraform/services/sql/resource_sql_database_instance_test.go b/mmv1/third_party/terraform/services/sql/resource_sql_database_instance_test.go index 8d610c10d32c..0346b679251d 100644 --- a/mmv1/third_party/terraform/services/sql/resource_sql_database_instance_test.go +++ b/mmv1/third_party/terraform/services/sql/resource_sql_database_instance_test.go @@ -862,6 +862,7 @@ func TestAccSqlDatabaseInstance_withPSCEnabled_thenAddAllowedConsumerProjects_th t.Parallel() instanceName := "tf-test-" + acctest.RandString(t, 10) + project_id := "psctestproject" + acctest.RandString(t, 10) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -869,7 +870,7 @@ func TestAccSqlDatabaseInstance_withPSCEnabled_thenAddAllowedConsumerProjects_th CheckDestroy: testAccSqlDatabaseInstanceDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(instanceName), + Config: testAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(instanceName, project_id), Check: resource.ComposeTestCheckFunc(verifyPscOperation("google_sql_database_instance.instance", true, true, nil)), }, { @@ -889,7 +890,7 @@ func TestAccSqlDatabaseInstance_withPSCEnabled_thenAddAllowedConsumerProjects_th ImportStateVerifyIgnore: []string{"deletion_protection"}, }, { - Config: testAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(instanceName), + Config: testAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(instanceName, project_id), Check: resource.ComposeTestCheckFunc(verifyPscOperation("google_sql_database_instance.instance", true, true, []string{})), }, { @@ -906,6 +907,7 @@ func TestAccSqlDatabaseInstance_basicInstance_thenPSCEnabled(t *testing.T) { t.Parallel() instanceName := "tf-test-" + acctest.RandString(t, 10) + project_id := "psctestproject" + acctest.RandString(t, 10) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -922,7 +924,7 @@ func TestAccSqlDatabaseInstance_basicInstance_thenPSCEnabled(t *testing.T) { ImportStateVerifyIgnore: []string{"deletion_protection"}, }, { - Config: testAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(instanceName), + Config: testAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(instanceName, project_id), ExpectError: regexp.MustCompile("PSC connectivity can not be enabled"), }, }, From eba798cf97c86f8dc33ab3a77a43643a0b47ccf6 Mon Sep 17 00:00:00 2001 From: Saurabh Uttam Date: Fri, 18 Aug 2023 04:45:13 +0000 Subject: [PATCH 11/14] Added org_id in google_project resource --- .../sql/resource_sql_database_instance_test.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/mmv1/third_party/terraform/services/sql/resource_sql_database_instance_test.go b/mmv1/third_party/terraform/services/sql/resource_sql_database_instance_test.go index 0346b679251d..520c5e3efbb8 100644 --- a/mmv1/third_party/terraform/services/sql/resource_sql_database_instance_test.go +++ b/mmv1/third_party/terraform/services/sql/resource_sql_database_instance_test.go @@ -790,6 +790,7 @@ func TestAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(t instanceName := "tf-test-" + acctest.RandString(t, 10) project_id := "psctestproject" + acctest.RandString(t, 10) + org_id := envvar.GetTestOrgFromEnv(t) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -797,7 +798,7 @@ func TestAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(t CheckDestroy: testAccSqlDatabaseInstanceDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(instanceName, project_id), + Config: testAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(instanceName, project_id, org_id), Check: resource.ComposeTestCheckFunc(verifyPscOperation("google_sql_database_instance.instance", true, true, nil)), }, { @@ -863,6 +864,7 @@ func TestAccSqlDatabaseInstance_withPSCEnabled_thenAddAllowedConsumerProjects_th instanceName := "tf-test-" + acctest.RandString(t, 10) project_id := "psctestproject" + acctest.RandString(t, 10) + org_id := envvar.GetTestOrgFromEnv(t) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -870,7 +872,7 @@ func TestAccSqlDatabaseInstance_withPSCEnabled_thenAddAllowedConsumerProjects_th CheckDestroy: testAccSqlDatabaseInstanceDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(instanceName, project_id), + Config: testAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(instanceName, project_id, org_id), Check: resource.ComposeTestCheckFunc(verifyPscOperation("google_sql_database_instance.instance", true, true, nil)), }, { @@ -890,7 +892,7 @@ func TestAccSqlDatabaseInstance_withPSCEnabled_thenAddAllowedConsumerProjects_th ImportStateVerifyIgnore: []string{"deletion_protection"}, }, { - Config: testAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(instanceName, project_id), + Config: testAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(instanceName, project_id, org_id), Check: resource.ComposeTestCheckFunc(verifyPscOperation("google_sql_database_instance.instance", true, true, []string{})), }, { @@ -908,6 +910,7 @@ func TestAccSqlDatabaseInstance_basicInstance_thenPSCEnabled(t *testing.T) { instanceName := "tf-test-" + acctest.RandString(t, 10) project_id := "psctestproject" + acctest.RandString(t, 10) + org_id := envvar.GetTestOrgFromEnv(t) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -924,7 +927,7 @@ func TestAccSqlDatabaseInstance_basicInstance_thenPSCEnabled(t *testing.T) { ImportStateVerifyIgnore: []string{"deletion_protection"}, }, { - Config: testAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(instanceName, project_id), + Config: testAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(instanceName, project_id, org_id), ExpectError: regexp.MustCompile("PSC connectivity can not be enabled"), }, }, @@ -2604,11 +2607,12 @@ resource "google_sql_database_instance" "instance" { `, instanceName) } -func testAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(instanceName string, project_id string) string { +func testAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(instanceName string, project_id string, org_id string) string { return fmt.Sprintf(` resource "google_project" "testproject" { name = "%s" project_id = "%s" + org_id = "%s" } resource "google_sql_database_instance" "instance" { @@ -2632,7 +2636,7 @@ resource "google_sql_database_instance" "instance" { availability_type = "REGIONAL" } } -`, project_id, project_id, instanceName) +`, project_id, project_id, org_id, instanceName) } func testAccSqlDatabaseInstance_withPSCEnabled_withEmptyAllowedConsumerProjects(instanceName string) string { From f21800514ecf848e1bdf57cf34dd0821fce89e18 Mon Sep 17 00:00:00 2001 From: Saurabh Uttam Date: Fri, 18 Aug 2023 07:29:08 +0000 Subject: [PATCH 12/14] Introduces changes for creating project --- .../resource_sql_database_instance_test.go | 84 +++++++++++++------ 1 file changed, 58 insertions(+), 26 deletions(-) diff --git a/mmv1/third_party/terraform/services/sql/resource_sql_database_instance_test.go b/mmv1/third_party/terraform/services/sql/resource_sql_database_instance_test.go index 520c5e3efbb8..ca5ac0345ab2 100644 --- a/mmv1/third_party/terraform/services/sql/resource_sql_database_instance_test.go +++ b/mmv1/third_party/terraform/services/sql/resource_sql_database_instance_test.go @@ -789,8 +789,8 @@ func TestAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(t t.Parallel() instanceName := "tf-test-" + acctest.RandString(t, 10) - project_id := "psctestproject" + acctest.RandString(t, 10) - org_id := envvar.GetTestOrgFromEnv(t) + projectId := "psctestproject" + acctest.RandString(t, 10) + orgId := envvar.GetTestOrgFromEnv(t) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -798,7 +798,7 @@ func TestAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(t CheckDestroy: testAccSqlDatabaseInstanceDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(instanceName, project_id, org_id), + Config: testAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(instanceName, projectId, orgId), Check: resource.ComposeTestCheckFunc(verifyPscOperation("google_sql_database_instance.instance", true, true, nil)), }, { @@ -815,6 +815,8 @@ func TestAccSqlDatabaseInstance_withPSCEnabled_withEmptyAllowedConsumerProjects( t.Parallel() instanceName := "tf-test-" + acctest.RandString(t, 10) + projectId := "psctestproject" + acctest.RandString(t, 10) + orgId := envvar.GetTestOrgFromEnv(t) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -822,7 +824,7 @@ func TestAccSqlDatabaseInstance_withPSCEnabled_withEmptyAllowedConsumerProjects( CheckDestroy: testAccSqlDatabaseInstanceDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccSqlDatabaseInstance_withPSCEnabled_withEmptyAllowedConsumerProjects(instanceName), + Config: testAccSqlDatabaseInstance_withPSCEnabled_withEmptyAllowedConsumerProjects(instanceName, projectId, orgId), Check: resource.ComposeTestCheckFunc(verifyPscOperation("google_sql_database_instance.instance", true, true, []string{})), }, { @@ -839,6 +841,8 @@ func TestAccSqlDatabaseInstance_withPSCEnabled_withAllowedConsumerProjects(t *te t.Parallel() instanceName := "tf-test-" + acctest.RandString(t, 10) + projectId := "psctestproject" + acctest.RandString(t, 10) + orgId := envvar.GetTestOrgFromEnv(t) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -846,7 +850,7 @@ func TestAccSqlDatabaseInstance_withPSCEnabled_withAllowedConsumerProjects(t *te CheckDestroy: testAccSqlDatabaseInstanceDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccSqlDatabaseInstance_withPSCEnabled_withAllowedConsumerProjects(instanceName), + Config: testAccSqlDatabaseInstance_withPSCEnabled_withAllowedConsumerProjects(instanceName, projectId, orgId), Check: resource.ComposeTestCheckFunc(verifyPscOperation("google_sql_database_instance.instance", true, true, []string{envvar.GetTestProjectFromEnv()})), }, { @@ -863,8 +867,8 @@ func TestAccSqlDatabaseInstance_withPSCEnabled_thenAddAllowedConsumerProjects_th t.Parallel() instanceName := "tf-test-" + acctest.RandString(t, 10) - project_id := "psctestproject" + acctest.RandString(t, 10) - org_id := envvar.GetTestOrgFromEnv(t) + projectId := "psctestproject" + acctest.RandString(t, 10) + orgId := envvar.GetTestOrgFromEnv(t) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -872,7 +876,7 @@ func TestAccSqlDatabaseInstance_withPSCEnabled_thenAddAllowedConsumerProjects_th CheckDestroy: testAccSqlDatabaseInstanceDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(instanceName, project_id, org_id), + Config: testAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(instanceName, projectId, orgId), Check: resource.ComposeTestCheckFunc(verifyPscOperation("google_sql_database_instance.instance", true, true, nil)), }, { @@ -882,7 +886,7 @@ func TestAccSqlDatabaseInstance_withPSCEnabled_thenAddAllowedConsumerProjects_th ImportStateVerifyIgnore: []string{"deletion_protection"}, }, { - Config: testAccSqlDatabaseInstance_withPSCEnabled_withAllowedConsumerProjects(instanceName), + Config: testAccSqlDatabaseInstance_withPSCEnabled_withAllowedConsumerProjects(instanceName, projectId, orgId), Check: resource.ComposeTestCheckFunc(verifyPscOperation("google_sql_database_instance.instance", true, true, []string{envvar.GetTestProjectFromEnv()})), }, { @@ -892,7 +896,7 @@ func TestAccSqlDatabaseInstance_withPSCEnabled_thenAddAllowedConsumerProjects_th ImportStateVerifyIgnore: []string{"deletion_protection"}, }, { - Config: testAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(instanceName, project_id, org_id), + Config: testAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(instanceName, projectId, orgId), Check: resource.ComposeTestCheckFunc(verifyPscOperation("google_sql_database_instance.instance", true, true, []string{})), }, { @@ -909,8 +913,8 @@ func TestAccSqlDatabaseInstance_basicInstance_thenPSCEnabled(t *testing.T) { t.Parallel() instanceName := "tf-test-" + acctest.RandString(t, 10) - project_id := "psctestproject" + acctest.RandString(t, 10) - org_id := envvar.GetTestOrgFromEnv(t) + projectId := "psctestproject" + acctest.RandString(t, 10) + orgId := envvar.GetTestOrgFromEnv(t) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -918,7 +922,7 @@ func TestAccSqlDatabaseInstance_basicInstance_thenPSCEnabled(t *testing.T) { CheckDestroy: testAccSqlDatabaseInstanceDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccSqlDatabaseInstance_basicInstanceForPsc(instanceName), + Config: testAccSqlDatabaseInstance_basicInstanceForPsc(instanceName, projectId, orgId), }, { ResourceName: "google_sql_database_instance.instance", @@ -927,7 +931,7 @@ func TestAccSqlDatabaseInstance_basicInstance_thenPSCEnabled(t *testing.T) { ImportStateVerifyIgnore: []string{"deletion_protection"}, }, { - Config: testAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(instanceName, project_id, org_id), + Config: testAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(instanceName, projectId, orgId), ExpectError: regexp.MustCompile("PSC connectivity can not be enabled"), }, }, @@ -938,6 +942,8 @@ func TestAccSqlDatabaseInstance_withPSCEnabled_withIpV4Enabled(t *testing.T) { t.Parallel() instanceName := "tf-test-" + acctest.RandString(t, 10) + projectId := "psctestproject" + acctest.RandString(t, 10) + orgId := envvar.GetTestOrgFromEnv(t) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -945,7 +951,7 @@ func TestAccSqlDatabaseInstance_withPSCEnabled_withIpV4Enabled(t *testing.T) { CheckDestroy: testAccSqlDatabaseInstanceDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccSqlDatabaseInstance_withPSCEnabled_withIpV4Enable(instanceName), + Config: testAccSqlDatabaseInstance_withPSCEnabled_withIpV4Enable(instanceName, projectId, orgId), ExpectError: regexp.MustCompile("PSC connectivity cannot be enabled together with public IP"), }, }, @@ -2563,9 +2569,16 @@ resource "google_sql_database_instance" "instance-failover" { `, instanceName, failoverName) } -func testAccSqlDatabaseInstance_basicInstanceForPsc(instanceName string) string { +func testAccSqlDatabaseInstance_basicInstanceForPsc(instanceName string, projectId string, orgId string) string { return fmt.Sprintf(` +resource "google_project" "testproject" { + name = "%s" + project_id = "%s" + org_id = "%s" +} + resource "google_sql_database_instance" "instance" { + project = google_project.testproject.project_id name = "%s" region = "us-central1" database_version = "MYSQL_8_0" @@ -2579,12 +2592,19 @@ resource "google_sql_database_instance" "instance" { availability_type = "REGIONAL" } } -`, instanceName) +`, projectId, projectId, orgId, instanceName) } -func testAccSqlDatabaseInstance_withPSCEnabled_withIpV4Enable(instanceName string) string { +func testAccSqlDatabaseInstance_withPSCEnabled_withIpV4Enable(instanceName string, projectId string, orgId string) string { return fmt.Sprintf(` +resource "google_project" "testproject" { + name = "%s" + project_id = "%s" + org_id = "%s" +} + resource "google_sql_database_instance" "instance" { + project = google_project.testproject.project_id name = "%s" region = "us-central1" database_version = "MYSQL_8_0" @@ -2604,10 +2624,10 @@ resource "google_sql_database_instance" "instance" { availability_type = "REGIONAL" } } -`, instanceName) +`, projectId, projectId, orgId, instanceName) } -func testAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(instanceName string, project_id string, org_id string) string { +func testAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(instanceName string, projectId string, orgId string) string { return fmt.Sprintf(` resource "google_project" "testproject" { name = "%s" @@ -2636,12 +2656,19 @@ resource "google_sql_database_instance" "instance" { availability_type = "REGIONAL" } } -`, project_id, project_id, org_id, instanceName) +`, projectId, projectId, orgId, instanceName) } -func testAccSqlDatabaseInstance_withPSCEnabled_withEmptyAllowedConsumerProjects(instanceName string) string { +func testAccSqlDatabaseInstance_withPSCEnabled_withEmptyAllowedConsumerProjects(instanceName string, projectId string, orgId string) string { return fmt.Sprintf(` +resource "google_project" "testproject" { + name = "%s" + project_id = "%s" + org_id = "%s" +} + resource "google_sql_database_instance" "instance" { + project = google_project.testproject.project_id name = "%s" region = "us-central1" database_version = "MYSQL_8_0" @@ -2662,13 +2689,18 @@ resource "google_sql_database_instance" "instance" { availability_type = "REGIONAL" } } -`, instanceName) +`, projectId, projectId, orgId, instanceName) } -func testAccSqlDatabaseInstance_withPSCEnabled_withAllowedConsumerProjects(instanceName string) string { - project_id := envvar.GetTestProjectFromEnv() +func testAccSqlDatabaseInstance_withPSCEnabled_withAllowedConsumerProjects(instanceName string, projectId string, orgId string) string { return fmt.Sprintf(` +resource "google_project" "testproject" { + name = "%s" + project_id = "%s" + org_id = "%s" +} resource "google_sql_database_instance" "instance" { + project = google_project.testproject.project_id name = "%s" region = "us-central1" database_version = "MYSQL_8_0" @@ -2689,7 +2721,7 @@ resource "google_sql_database_instance" "instance" { availability_type = "REGIONAL" } } -`, instanceName, project_id) +`, projectId, projectId, orgId, instanceName, projectId) } func verifyPscOperation(resourceName string, isPscConfigExpected bool, expectedPscEnabled bool, expectedAllowedConsumerProjects []string) func(*terraform.State) error { From 49e8be8f3c909ddf83f416cd722f58d5ae7066eb Mon Sep 17 00:00:00 2001 From: Saurabh Uttam Date: Fri, 18 Aug 2023 09:37:49 +0000 Subject: [PATCH 13/14] Changes instance regions --- .../sql/resource_sql_database_instance_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mmv1/third_party/terraform/services/sql/resource_sql_database_instance_test.go b/mmv1/third_party/terraform/services/sql/resource_sql_database_instance_test.go index ca5ac0345ab2..9feac1d30dba 100644 --- a/mmv1/third_party/terraform/services/sql/resource_sql_database_instance_test.go +++ b/mmv1/third_party/terraform/services/sql/resource_sql_database_instance_test.go @@ -2580,7 +2580,7 @@ resource "google_project" "testproject" { resource "google_sql_database_instance" "instance" { project = google_project.testproject.project_id name = "%s" - region = "us-central1" + region = "us-south1" database_version = "MYSQL_8_0" deletion_protection = false settings { @@ -2606,7 +2606,7 @@ resource "google_project" "testproject" { resource "google_sql_database_instance" "instance" { project = google_project.testproject.project_id name = "%s" - region = "us-central1" + region = "us-south1" database_version = "MYSQL_8_0" deletion_protection = false settings { @@ -2638,7 +2638,7 @@ resource "google_project" "testproject" { resource "google_sql_database_instance" "instance" { project = google_project.testproject.project_id name = "%s" - region = "us-central1" + region = "us-south1" database_version = "MYSQL_8_0" deletion_protection = false settings { @@ -2670,7 +2670,7 @@ resource "google_project" "testproject" { resource "google_sql_database_instance" "instance" { project = google_project.testproject.project_id name = "%s" - region = "us-central1" + region = "us-south1" database_version = "MYSQL_8_0" deletion_protection = false settings { @@ -2702,7 +2702,7 @@ resource "google_project" "testproject" { resource "google_sql_database_instance" "instance" { project = google_project.testproject.project_id name = "%s" - region = "us-central1" + region = "us-south1" database_version = "MYSQL_8_0" deletion_protection = false settings { From bbb708bdc3ff137c7e2e2b588eed58a0dd024f0d Mon Sep 17 00:00:00 2001 From: Saurabh Uttam Date: Fri, 18 Aug 2023 12:24:52 +0000 Subject: [PATCH 14/14] Added import id prefix --- .../services/sql/resource_sql_database_instance_test.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mmv1/third_party/terraform/services/sql/resource_sql_database_instance_test.go b/mmv1/third_party/terraform/services/sql/resource_sql_database_instance_test.go index 9feac1d30dba..e3ad5a9070a5 100644 --- a/mmv1/third_party/terraform/services/sql/resource_sql_database_instance_test.go +++ b/mmv1/third_party/terraform/services/sql/resource_sql_database_instance_test.go @@ -805,6 +805,7 @@ func TestAccSqlDatabaseInstance_withPSCEnabled_withoutAllowedConsumerProjects(t ResourceName: "google_sql_database_instance.instance", ImportState: true, ImportStateVerify: true, + ImportStateIdPrefix: fmt.Sprintf("%s/", projectId), ImportStateVerifyIgnore: []string{"deletion_protection"}, }, }, @@ -831,6 +832,7 @@ func TestAccSqlDatabaseInstance_withPSCEnabled_withEmptyAllowedConsumerProjects( ResourceName: "google_sql_database_instance.instance", ImportState: true, ImportStateVerify: true, + ImportStateIdPrefix: fmt.Sprintf("%s/", projectId), ImportStateVerifyIgnore: []string{"deletion_protection"}, }, }, @@ -857,6 +859,7 @@ func TestAccSqlDatabaseInstance_withPSCEnabled_withAllowedConsumerProjects(t *te ResourceName: "google_sql_database_instance.instance", ImportState: true, ImportStateVerify: true, + ImportStateIdPrefix: fmt.Sprintf("%s/", projectId), ImportStateVerifyIgnore: []string{"deletion_protection"}, }, }, @@ -883,6 +886,7 @@ func TestAccSqlDatabaseInstance_withPSCEnabled_thenAddAllowedConsumerProjects_th ResourceName: "google_sql_database_instance.instance", ImportState: true, ImportStateVerify: true, + ImportStateIdPrefix: fmt.Sprintf("%s/", projectId), ImportStateVerifyIgnore: []string{"deletion_protection"}, }, { @@ -893,6 +897,7 @@ func TestAccSqlDatabaseInstance_withPSCEnabled_thenAddAllowedConsumerProjects_th ResourceName: "google_sql_database_instance.instance", ImportState: true, ImportStateVerify: true, + ImportStateIdPrefix: fmt.Sprintf("%s/", projectId), ImportStateVerifyIgnore: []string{"deletion_protection"}, }, { @@ -903,6 +908,7 @@ func TestAccSqlDatabaseInstance_withPSCEnabled_thenAddAllowedConsumerProjects_th ResourceName: "google_sql_database_instance.instance", ImportState: true, ImportStateVerify: true, + ImportStateIdPrefix: fmt.Sprintf("%s/", projectId), ImportStateVerifyIgnore: []string{"deletion_protection"}, }, }, @@ -928,6 +934,7 @@ func TestAccSqlDatabaseInstance_basicInstance_thenPSCEnabled(t *testing.T) { ResourceName: "google_sql_database_instance.instance", ImportState: true, ImportStateVerify: true, + ImportStateIdPrefix: fmt.Sprintf("%s/", projectId), ImportStateVerifyIgnore: []string{"deletion_protection"}, }, {