diff --git a/.github/workflows/acceptance-tests-runner.yml b/.github/workflows/acceptance-tests-runner.yml index 2c570456b0..bfda7bfd11 100644 --- a/.github/workflows/acceptance-tests-runner.yml +++ b/.github/workflows/acceptance-tests-runner.yml @@ -648,6 +648,8 @@ jobs: AWS_ACCESS_KEY_ID: ${{ secrets.aws_access_key_id }} AWS_SECRET_ACCESS_KEY: ${{ secrets.aws_secret_access_key }} AWS_REGION: ${{ vars.AWS_REGION }} + AWS_REGION_UPPERCASE: ${{ vars.AWS_REGION_UPPERCASE }} + AWS_REGION_LOWERCASE: ${{ vars.AWS_REGION_LOWERCASE }} AWS_SECURITY_GROUP_1: ${{ vars.AWS_SECURITY_GROUP_1 }} AWS_SECURITY_GROUP_2: ${{ vars.AWS_SECURITY_GROUP_2 }} AWS_VPC_CIDR_BLOCK: ${{ vars.AWS_VPC_CIDR_BLOCK }} diff --git a/internal/service/privateendpointregionalmode/resource_private_endpoint_regional_mode_test.go b/internal/service/privateendpointregionalmode/resource_private_endpoint_regional_mode_test.go index bc89b6732f..a020aa6aa8 100644 --- a/internal/service/privateendpointregionalmode/resource_private_endpoint_regional_mode_test.go +++ b/internal/service/privateendpointregionalmode/resource_private_endpoint_regional_mode_test.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "os" - "strconv" "strings" "testing" @@ -18,31 +17,31 @@ func TestAccPrivateEndpointRegionalMode_basic(t *testing.T) { } func TestAccPrivateEndpointRegionalMode_conn(t *testing.T) { - acc.SkipTestForCI(t) // needs AWS configuration - var ( - endpointResourceSuffix = "atlasple" - resourceSuffix = "atlasrm" - resourceName = fmt.Sprintf("mongodbatlas_private_endpoint_regional_mode.%s", resourceSuffix) - awsAccessKey = os.Getenv("AWS_ACCESS_KEY_ID") - awsSecretKey = os.Getenv("AWS_SECRET_ACCESS_KEY") - providerName = "AWS" - region = os.Getenv("AWS_REGION") - projectID = acc.ProjectIDExecution(t) - orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") - projectName = acc.RandomProjectName() - clusterName = acc.RandomClusterName() - clusterResourceName = "test" - clusterResource = acc.ConfigClusterGlobal(orgID, projectName, clusterName) - clusterDataSource = modeClusterData(clusterResourceName, resourceSuffix, endpointResourceSuffix) - endpointResources = testConfigUnmanagedAWS( + endpointResourceSuffix = "atlasple" + resourceSuffix = "atlasrm" + resourceName = fmt.Sprintf("mongodbatlas_private_endpoint_regional_mode.%s", resourceSuffix) + awsAccessKey = os.Getenv("AWS_ACCESS_KEY_ID") + awsSecretKey = os.Getenv("AWS_SECRET_ACCESS_KEY") + providerName = "AWS" + region = os.Getenv("AWS_REGION_LOWERCASE") + privatelinkEndpointServiceResourceName = fmt.Sprintf("mongodbatlas_privatelink_endpoint_service.%s", endpointResourceSuffix) + spec1 = acc.ReplicationSpecRequest{Region: os.Getenv("AWS_REGION_UPPERCASE"), ProviderName: providerName, ZoneName: "Zone 1"} + spec2 = acc.ReplicationSpecRequest{Region: "US_WEST_2", ProviderName: providerName, ZoneName: "Zone 2"} + clusterInfo = acc.GetClusterInfo(t, &acc.ClusterRequest{Geosharded: true, DiskSizeGb: 80, ReplicationSpecs: []acc.ReplicationSpecRequest{spec1, spec2}}) + projectID = clusterInfo.ProjectID + clusterResourceName = clusterInfo.ClusterResourceName + clusterDataName = "data.mongodbatlas_advanced_cluster.test" + endpointResources = testConfigUnmanagedAWS( awsAccessKey, awsSecretKey, projectID, providerName, region, endpointResourceSuffix, ) - dependencies = []string{clusterResource, clusterDataSource, endpointResources} + clusterDataSource = modeClusterData(clusterResourceName, resourceName, privatelinkEndpointServiceResourceName) + dependencies = []string{clusterInfo.ClusterTerraformStr, clusterDataSource, endpointResources} ) resource.Test(t, resource.TestCase{ - PreCheck: func() { acc.PreCheck(t) }, + PreCheck: func() { acc.PreCheckAwsEnvBasic(t); acc.PreCheckAwsRegionCases(t) }, + ExternalProviders: acc.ExternalProvidersOnlyAWS(), ProtoV6ProviderFactories: acc.TestAccProviderV6Factories, CheckDestroy: checkDestroy, Steps: []resource.TestStep{ @@ -50,9 +49,8 @@ func TestAccPrivateEndpointRegionalMode_conn(t *testing.T) { Config: configWithDependencies(resourceSuffix, projectID, false, dependencies), Check: resource.ComposeAggregateTestCheckFunc( checkExists(resourceName), - checkModeClustersUpToDate(projectID, clusterName, clusterResourceName), + resource.TestCheckResourceAttr(clusterDataName, "connection_strings.0.private_endpoint.#", "0"), resource.TestCheckResourceAttrSet(resourceName, "project_id"), - resource.TestCheckResourceAttrSet(resourceName, "enabled"), resource.TestCheckResourceAttr(resourceName, "enabled", "false"), ), }, @@ -60,9 +58,8 @@ func TestAccPrivateEndpointRegionalMode_conn(t *testing.T) { Config: configWithDependencies(resourceSuffix, projectID, true, dependencies), Check: resource.ComposeAggregateTestCheckFunc( checkExists(resourceName), - checkModeClustersUpToDate(projectID, clusterName, clusterResourceName), + resource.TestCheckResourceAttr(clusterDataName, "connection_strings.0.private_endpoint.#", "1"), resource.TestCheckResourceAttrSet(resourceName, "project_id"), - resource.TestCheckResourceAttrSet(resourceName, "enabled"), resource.TestCheckResourceAttr(resourceName, "enabled", "true"), ), }, @@ -113,12 +110,12 @@ func basicTestCase(tb testing.TB) *resource.TestCase { func modeClusterData(clusterResourceName, regionalModeResourceName, privateLinkResourceName string) string { return fmt.Sprintf(` - data "mongodbatlas_cluster" %[1]q { - project_id = mongodbatlas_cluster.%[1]s.project_id - name = mongodbatlas_cluster.%[1]s.name + data "mongodbatlas_advanced_cluster" "test" { + project_id = %[1]s.project_id + name = %[1]s.name depends_on = [ - mongodbatlas_privatelink_endpoint_service.%[3]s, - mongodbatlas_private_endpoint_regional_mode.%[2]s + %[2]s, + %[3]s ] } `, clusterResourceName, regionalModeResourceName, privateLinkResourceName) @@ -179,32 +176,6 @@ func checkExists(resourceName string) resource.TestCheckFunc { } } -func checkModeClustersUpToDate(projectID, clusterName, clusterResourceName string) resource.TestCheckFunc { - resourceName := strings.Join([]string{"data", "mongodbatlas_cluster", clusterResourceName}, ".") - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[resourceName] - if !ok { - return fmt.Errorf("Could not find resource state for cluster (%s) on project (%s)", clusterName, projectID) - } - var rsPrivateEndpointCount int - var err error - if rsPrivateEndpointCount, err = strconv.Atoi(rs.Primary.Attributes["connection_strings.0.private_endpoint.#"]); err != nil { - return fmt.Errorf("Connection strings private endpoint count is not a number") - } - c, _, _ := acc.Conn().Clusters.Get(context.Background(), projectID, clusterName) - if rsPrivateEndpointCount != len(c.ConnectionStrings.PrivateEndpoint) { - return fmt.Errorf("Cluster PrivateEndpoint count does not match resource") - } - if rs.Primary.Attributes["connection_strings.0.standard"] != c.ConnectionStrings.Standard { - return fmt.Errorf("Cluster standard connection_string does not match resource") - } - if rs.Primary.Attributes["connection_strings.0.standard_srv"] != c.ConnectionStrings.StandardSrv { - return fmt.Errorf("Cluster standard connection_string does not match resource") - } - return nil - } -} - func checkDestroy(s *terraform.State) error { for _, rs := range s.RootModule().Resources { if rs.Type != "mongodbatlas_private_endpoint_regional_mode" { @@ -221,14 +192,14 @@ func checkDestroy(s *terraform.State) error { func testConfigUnmanagedAWS(awsAccessKey, awsSecretKey, projectID, providerName, region, serviceResourceName string) string { return fmt.Sprintf(` provider "aws" { - region = "%[5]s" - access_key = "%[1]s" - secret_key = "%[2]s" + region = %[5]q + access_key = %[1]q + secret_key = %[2]q } resource "mongodbatlas_privatelink_endpoint" "test" { - project_id = "%[3]s" - provider_name = "%[4]s" - region = "%[5]s" + project_id = %[3]q + provider_name = %[4]q + region = %[5]q } resource "aws_vpc_endpoint" "ptfe_service" { vpc_id = aws_vpc.primary.id diff --git a/internal/testutil/acc/pre_check.go b/internal/testutil/acc/pre_check.go index 97f91a1d7b..339f092e05 100644 --- a/internal/testutil/acc/pre_check.go +++ b/internal/testutil/acc/pre_check.go @@ -180,6 +180,14 @@ func PreCheckAwsEnv(tb testing.TB) { } } +func PreCheckAwsRegionCases(tb testing.TB) { + tb.Helper() + if os.Getenv("AWS_REGION_UPPERCASE") == "" || + os.Getenv("AWS_REGION_LOWERCASE") == "" { + tb.Fatal("`AWS_REGION_UPPERCASE`, `AWS_REGION_LOWERCASE` must be set for acceptance testing") + } +} + func PreCheckAwsEnvPrivateLinkEndpointService(tb testing.TB) { tb.Helper() if os.Getenv("AWS_ACCESS_KEY_ID") == "" ||