Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

chore: Uses ExternalProviders helper functions for tests #1773

Merged
merged 10 commits into from
Dec 20, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,8 @@ func TestAccConfigRSCloudProviderAccessAuthorizationAWS_basic(t *testing.T) {
)

resource.Test(t, resource.TestCase{
PreCheck: func() { acc.PreCheck(t) },
ExternalProviders: map[string]resource.ExternalProvider{
"aws": {
VersionConstraint: "5.1.0",
Source: "hashicorp/aws",
},
},
PreCheck: func() { acc.PreCheck(t) },
ExternalProviders: acc.ExternalProvidersOnlyAWS(),
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
// same as regular cloud provider access resource
CheckDestroy: testAccCheckMongoDBAtlasProviderAccessDestroy,
Expand Down
9 changes: 2 additions & 7 deletions internal/service/cluster/resource_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1436,13 +1436,8 @@ func TestAccClusterRSCluster_withDefaultBiConnectorAndAdvancedConfiguration_main
CheckDestroy: acc.CheckClusterDestroy,
Steps: []resource.TestStep{
{
ExternalProviders: map[string]resource.ExternalProvider{
"mongodbatlas": {
VersionConstraint: "1.11.0",
Source: "mongodb/mongodbatlas",
},
},
Config: cfg,
ExternalProviders: acc.ExternalProviders("1.11.0"),
Config: cfg,
Check: resource.ComposeTestCheckFunc(
testAccCheckMongoDBAtlasClusterExists(resourceName, &cluster),
testAccCheckMongoDBAtlasClusterAttributes(&cluster, name),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,11 @@ func TestAccMigrationAdvRS_EncryptionAtRest_WithRole_basicAWS(t *testing.T) {
CheckDestroy: testAccCheckMongoDBAtlasEncryptionAtRestDestroy,
Steps: []resource.TestStep{
{
ExternalProviders: mig.ExternalProvidersWithAWS("5.1.0"),
ExternalProviders: mig.ExternalProvidersWithAWS(),
Config: testAccMongoDBAtlasEncryptionAtRestConfigAwsKmsWithRole(awsKms.GetRegion(), accessKeyID, secretKey, projectID, policyName, roleName, false, &awsKms),
},
{
ExternalProviders: map[string]resource.ExternalProvider{
"aws": {
VersionConstraint: "5.1.0",
Source: "hashicorp/aws",
},
},
ExternalProviders: acc.ExternalProvidersOnlyAWS(),
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
Config: testAccMongoDBAtlasEncryptionAtRestConfigAwsKmsWithRole(awsKms.GetRegion(), accessKeyID, secretKey, projectID, policyName, roleName, false, &awsKms),
Check: resource.ComposeTestCheckFunc(
Expand Down Expand Up @@ -217,22 +212,12 @@ func TestAccMigrationAdvRS_EncryptionAtRest_basicAWS_from_v1_11_0(t *testing.T)
)

resource.Test(t, resource.TestCase{
PreCheck: func() { mig.PreCheck(t); acc.PreCheckAwsEnv(t) },
PreCheck: func() { acc.PreCheck(t); acc.PreCheckAwsEnv(t) },
CheckDestroy: testAccCheckMongoDBAtlasEncryptionAtRestDestroy,
Steps: []resource.TestStep{
{
ExternalProviders: map[string]resource.ExternalProvider{
"mongodbatlas": {
VersionConstraint: "1.11.0",
Source: "mongodb/mongodbatlas",
},
"aws": {
VersionConstraint: "5.1.0",
Source: "hashicorp/aws",
},
},

Config: testAccMongoDBAtlasEncryptionAtRestConfigAwsKms(projectID, &awsKms),
ExternalProviders: acc.ExternalProvidersWithAWS("1.11.0"),
Config: testAccMongoDBAtlasEncryptionAtRestConfigAwsKms(projectID, &awsKms),
Check: resource.ComposeTestCheckFunc(
testAccCheckMongoDBAtlasEncryptionAtRestExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "project_id", projectID),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,8 @@ func TestAccAdvRSEncryptionAtRestWithRole_basicAWS(t *testing.T) {
)

resource.Test(t, resource.TestCase{
PreCheck: func() { acc.PreCheck(t); acc.PreCheckAwsEnv(t) },
ExternalProviders: map[string]resource.ExternalProvider{
"aws": {
VersionConstraint: "5.1.0",
Source: "hashicorp/aws",
},
},
PreCheck: func() { acc.PreCheck(t); acc.PreCheckAwsEnv(t) },
ExternalProviders: acc.ExternalProvidersOnlyAWS(),
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
CheckDestroy: testAccCheckMongoDBAtlasEncryptionAtRestDestroy,
Steps: []resource.TestStep{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,7 @@ func TestAccDataSourceFederatedDatabaseInstance_basic(t *testing.T) {
CheckDestroy: acc.CheckDestroyFederatedDatabaseInstance,
Steps: []resource.TestStep{
{
ExternalProviders: map[string]resource.ExternalProvider{
"aws": {
VersionConstraint: "5.1.0",
Source: "hashicorp/aws",
},
},
ExternalProviders: acc.ExternalProvidersOnlyAWS(),
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
Config: testAccMongoDBAtlasFederatedDatabaseInstanceConfigDataSourceFirstSteps(name, projectName, orgID),
Check: resource.ComposeTestCheckFunc(
Expand Down Expand Up @@ -71,12 +66,7 @@ func TestAccDataSourceFederatedDatabaseInstance_S3Bucket(t *testing.T) {
CheckDestroy: acc.CheckDestroyFederatedDatabaseInstance,
Steps: []resource.TestStep{
{
ExternalProviders: map[string]resource.ExternalProvider{
"aws": {
VersionConstraint: "5.1.0",
Source: "hashicorp/aws",
},
},
ExternalProviders: acc.ExternalProvidersOnlyAWS(),
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
Config: testAccMongoDBAtlasFederatedDatabaseInstanceDataSourceConfigS3Bucket(policyName, roleName, projectName, orgID, name, testS3Bucket, region),
Check: resource.ComposeTestCheckFunc(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,7 @@ func TestAccDataSourceFederatedDatabaseInstances_basic(t *testing.T) {
CheckDestroy: acc.CheckDestroyFederatedDatabaseInstance,
Steps: []resource.TestStep{
{
ExternalProviders: map[string]resource.ExternalProvider{
"aws": {
VersionConstraint: "5.1.0",
Source: "hashicorp/aws",
},
},
ExternalProviders: acc.ExternalProvidersOnlyAWS(),
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
Config: testAccMongoDBAtlasFederatedDatabaseInstancesDataSourceConfig(policyName, roleName, projectName, orgID, firstName, secondName, testS3Bucket, region),
Check: resource.ComposeTestCheckFunc(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,7 @@ func TestAccFederatedDatabaseInstance_S3bucket(t *testing.T) {
CheckDestroy: acc.CheckDestroyFederatedDatabaseInstance,
Steps: []resource.TestStep{
{
ExternalProviders: map[string]resource.ExternalProvider{
"aws": {
VersionConstraint: "5.1.0",
Source: "hashicorp/aws",
},
},
ExternalProviders: acc.ExternalProvidersOnlyAWS(),
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
Config: testAccMongoDBAtlasFederatedDatabaseInstanceConfigS3Bucket(policyName, roleName, projectName, orgID, name, testS3Bucket, region),
Check: resource.ComposeTestCheckFunc(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,7 @@ func TestAccDataSourceFederatedDatabaseQueryLimit_basic(t *testing.T) {
CheckDestroy: testAccCheckMongoDBAtlasFederatedDatabaseQueryLimitDestroy,
Steps: []resource.TestStep{
{
ExternalProviders: map[string]resource.ExternalProvider{
"aws": {
VersionConstraint: "5.1.0",
Source: "hashicorp/aws",
},
},
ExternalProviders: acc.ExternalProvidersOnlyAWS(),
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
Config: testAccMongoDBAtlasFederatedDatabaseQueryLimitDataSourceConfig(policyName, roleName, projectName, orgID, tenantName, testS3Bucket, region),
Check: resource.ComposeTestCheckFunc(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,7 @@ func TestAccDataSourceFederatedDatabaseQueryLimits_basic(t *testing.T) {
CheckDestroy: testAccCheckMongoDBAtlasFederatedDatabaseQueryLimitDestroy,
Steps: []resource.TestStep{
{
ExternalProviders: map[string]resource.ExternalProvider{
"aws": {
VersionConstraint: "5.1.0",
Source: "hashicorp/aws",
},
},
ExternalProviders: acc.ExternalProvidersOnlyAWS(),
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
Config: testAccMongoDBAtlasFederatedDatabaseQueryLimitsDataSourceConfig(policyName, roleName, projectName, orgID, tenantName, testS3Bucket, region),
Check: resource.ComposeTestCheckFunc(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,7 @@ func TestAccFederatedDatabaseQueryLimit_basic(t *testing.T) {
CheckDestroy: testAccCheckMongoDBAtlasFederatedDatabaseQueryLimitDestroy,
Steps: []resource.TestStep{
{
ExternalProviders: map[string]resource.ExternalProvider{
"aws": {
VersionConstraint: "5.1.0",
Source: "hashicorp/aws",
},
},
ExternalProviders: acc.ExternalProvidersOnlyAWS(),
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
Config: testAccMongoDBAtlasFederatedDatabaseQueryLimitConfig(policyName, roleName, projectName, orgID, tenantName, testS3Bucket, region),
Check: resource.ComposeTestCheckFunc(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestAccMigrationNetworkRSPrivateLinkEndpointService_Complete(t *testing.T)
CheckDestroy: testAccCheckMongoDBAtlasPrivateLinkEndpointServiceDestroy,
Steps: []resource.TestStep{
{
ExternalProviders: mig.ExternalProvidersWithAWS("5.1.0"),
ExternalProviders: mig.ExternalProvidersWithAWS(),
Config: testAccMongoDBAtlasPrivateLinkEndpointServiceConfigCompleteAWS(
awsAccessKey, awsSecretKey, projectID, providerName, region, vpcID, subnetID, securityGroupID, resourceSuffix,
),
Expand All @@ -45,12 +45,7 @@ func TestAccMigrationNetworkRSPrivateLinkEndpointService_Complete(t *testing.T)
),
},
{
ExternalProviders: map[string]resource.ExternalProvider{
"aws": {
VersionConstraint: "5.1.0",
Source: "hashicorp/aws",
},
},
ExternalProviders: acc.ExternalProvidersOnlyAWS(),
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
Config: testAccMongoDBAtlasPrivateLinkEndpointServiceConfigCompleteAWS(
awsAccessKey, awsSecretKey, projectID, providerName, region, vpcID, subnetID, securityGroupID, resourceSuffix,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,7 @@ func TestAccNetworkRSPrivateLinkEndpointServiceAWS_Complete(t *testing.T) {
PreCheck: func() { acc.PreCheck(t); acc.PreCheckAwsEnv(t) },
CheckDestroy: testAccCheckMongoDBAtlasPrivateLinkEndpointServiceDestroy,
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
ExternalProviders: map[string]resource.ExternalProvider{
"aws": {
VersionConstraint: "5.1.0",
Source: "hashicorp/aws",
},
},
ExternalProviders: acc.ExternalProvidersOnlyAWS(),
Steps: []resource.TestStep{
{
Config: testAccMongoDBAtlasPrivateLinkEndpointServiceConfigCompleteAWS(
Expand Down Expand Up @@ -77,12 +72,7 @@ func TestAccNetworkRSPrivateLinkEndpointServiceAWS_import(t *testing.T) {
PreCheck: func() { acc.PreCheck(t); acc.PreCheckAwsEnv(t) },
CheckDestroy: testAccCheckMongoDBAtlasPrivateLinkEndpointServiceDestroy,
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
ExternalProviders: map[string]resource.ExternalProvider{
"aws": {
VersionConstraint: "5.1.0",
Source: "hashicorp/aws",
},
},
ExternalProviders: acc.ExternalProvidersOnlyAWS(),
Steps: []resource.TestStep{
{
Config: testAccMongoDBAtlasPrivateLinkEndpointServiceConfigCompleteAWS(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,8 @@ func TestAccMigrationConfigRSProjectAPIKey_RemovingOptionalRootProjectID(t *test
CheckDestroy: testAccCheckMongoDBAtlasProjectAPIKeyDestroy,
Steps: []resource.TestStep{
{
ExternalProviders: map[string]resource.ExternalProvider{
"mongodbatlas": {
VersionConstraint: "1.13.1", // fixed version as this is the last version where root project id was required.
Source: "mongodb/mongodbatlas",
},
},
Config: testAccMongoDBAtlasProjectAPIKeyConfigBasic(orgID, projectName, description, roleName, true),
ExternalProviders: acc.ExternalProviders("1.13.1"), // fixed version as this is the last version where root project id was required.
Config: testAccMongoDBAtlasProjectAPIKeyConfigBasic(orgID, projectName, description, roleName, true),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
resource.TestCheckResourceAttr(resourceName, "description", description),
Expand Down
38 changes: 38 additions & 0 deletions internal/testutil/acc/provider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package acc

import (
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

func ExternalProviders(versionAtlasProvider string) map[string]resource.ExternalProvider {
return map[string]resource.ExternalProvider{
"mongodbatlas": *providerAtlas(versionAtlasProvider),
}
}

func ExternalProvidersWithAWS(versionAtlasProvider string) map[string]resource.ExternalProvider {
return map[string]resource.ExternalProvider{
"mongodbatlas": *providerAtlas(versionAtlasProvider),
"aws": *providerAWS(),
}
}

func ExternalProvidersOnlyAWS() map[string]resource.ExternalProvider {
return map[string]resource.ExternalProvider{
"aws": *providerAWS(),
}
}

func providerAtlas(versionAtlasProvider string) *resource.ExternalProvider {
return &resource.ExternalProvider{
VersionConstraint: versionAtlasProvider,
Source: "mongodb/mongodbatlas",
}
}

func providerAWS() *resource.ExternalProvider {
return &resource.ExternalProvider{
VersionConstraint: "5.1.0",
Source: "hashicorp/aws",
}
}
31 changes: 9 additions & 22 deletions internal/testutil/mig/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,23 @@ import (

"github.com/hashicorp/go-version"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc"
)

func ExternalProviders() map[string]resource.ExternalProvider {
return map[string]resource.ExternalProvider{
"mongodbatlas": {
VersionConstraint: versionConstraint(),
Source: "mongodb/mongodbatlas",
},
}
}

func ExternalProvidersWithAWS(awsVersion string) map[string]resource.ExternalProvider {
return map[string]resource.ExternalProvider{
"mongodbatlas": {
VersionConstraint: versionConstraint(),
Source: "mongodb/mongodbatlas",
},
"aws": {
VersionConstraint: awsVersion,
Source: "hashicorp/aws",
},
}
}

func IsProviderVersionAtLeast(minVersion string) bool {
vProvider, errProvider := version.NewVersion(versionConstraint())
vMin, errMin := version.NewVersion(minVersion)
return errProvider == nil && errMin == nil && vProvider.GreaterThanOrEqual(vMin)
}

func ExternalProviders() map[string]resource.ExternalProvider {
return acc.ExternalProviders(versionConstraint())
}

func ExternalProvidersWithAWS() map[string]resource.ExternalProvider {
return acc.ExternalProvidersWithAWS(versionConstraint())
}

func checkLastVersion(tb testing.TB) {
tb.Helper()
if os.Getenv("MONGODB_ATLAS_LAST_VERSION") == "" {
Expand Down
Loading