Skip to content

Commit bdde468

Browse files
authored
chore: Uses ExternalProviders helper functions for tests (#1773)
* ExternalProviders functions for AWS only provider * use mig.ExternalProvidersOnlyAWS * use ExternalProviders * project_api_key * test if passing for all recent provider versions * use ExternalProvidersWithAWS * move provider functions independent of versionConstraint to acc * use acc cluster test * keep version at 1.11.0 * fix version in project_api_key_migration test
1 parent a3f638a commit bdde468

15 files changed

+71
-131
lines changed

internal/service/cloudprovideraccess/resource_cloud_provider_access_authorization_test.go

+2-7
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,8 @@ func TestAccConfigRSCloudProviderAccessAuthorizationAWS_basic(t *testing.T) {
2020
)
2121

2222
resource.Test(t, resource.TestCase{
23-
PreCheck: func() { acc.PreCheck(t) },
24-
ExternalProviders: map[string]resource.ExternalProvider{
25-
"aws": {
26-
VersionConstraint: "5.1.0",
27-
Source: "hashicorp/aws",
28-
},
29-
},
23+
PreCheck: func() { acc.PreCheck(t) },
24+
ExternalProviders: acc.ExternalProvidersOnlyAWS(),
3025
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
3126
// same as regular cloud provider access resource
3227
CheckDestroy: testAccCheckMongoDBAtlasProviderAccessDestroy,

internal/service/cluster/resource_cluster_test.go

+2-7
Original file line numberDiff line numberDiff line change
@@ -1436,13 +1436,8 @@ func TestAccClusterRSCluster_withDefaultBiConnectorAndAdvancedConfiguration_main
14361436
CheckDestroy: acc.CheckClusterDestroy,
14371437
Steps: []resource.TestStep{
14381438
{
1439-
ExternalProviders: map[string]resource.ExternalProvider{
1440-
"mongodbatlas": {
1441-
VersionConstraint: "1.11.0",
1442-
Source: "mongodb/mongodbatlas",
1443-
},
1444-
},
1445-
Config: cfg,
1439+
ExternalProviders: acc.ExternalProviders("1.11.0"),
1440+
Config: cfg,
14461441
Check: resource.ComposeTestCheckFunc(
14471442
testAccCheckMongoDBAtlasClusterExists(resourceName, &cluster),
14481443
testAccCheckMongoDBAtlasClusterAttributes(&cluster, name),

internal/service/encryptionatrest/resource_encryption_at_rest_migration_test.go

+5-20
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,11 @@ func TestAccMigrationAdvRS_EncryptionAtRest_WithRole_basicAWS(t *testing.T) {
8181
CheckDestroy: testAccCheckMongoDBAtlasEncryptionAtRestDestroy,
8282
Steps: []resource.TestStep{
8383
{
84-
ExternalProviders: mig.ExternalProvidersWithAWS("5.1.0"),
84+
ExternalProviders: mig.ExternalProvidersWithAWS(),
8585
Config: testAccMongoDBAtlasEncryptionAtRestConfigAwsKmsWithRole(awsKms.GetRegion(), accessKeyID, secretKey, projectID, policyName, roleName, false, &awsKms),
8686
},
8787
{
88-
ExternalProviders: map[string]resource.ExternalProvider{
89-
"aws": {
90-
VersionConstraint: "5.1.0",
91-
Source: "hashicorp/aws",
92-
},
93-
},
88+
ExternalProviders: acc.ExternalProvidersOnlyAWS(),
9489
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
9590
Config: testAccMongoDBAtlasEncryptionAtRestConfigAwsKmsWithRole(awsKms.GetRegion(), accessKeyID, secretKey, projectID, policyName, roleName, false, &awsKms),
9691
Check: resource.ComposeTestCheckFunc(
@@ -217,22 +212,12 @@ func TestAccMigrationAdvRS_EncryptionAtRest_basicAWS_from_v1_11_0(t *testing.T)
217212
)
218213

219214
resource.Test(t, resource.TestCase{
220-
PreCheck: func() { mig.PreCheck(t); acc.PreCheckAwsEnv(t) },
215+
PreCheck: func() { acc.PreCheck(t); acc.PreCheckAwsEnv(t) },
221216
CheckDestroy: testAccCheckMongoDBAtlasEncryptionAtRestDestroy,
222217
Steps: []resource.TestStep{
223218
{
224-
ExternalProviders: map[string]resource.ExternalProvider{
225-
"mongodbatlas": {
226-
VersionConstraint: "1.11.0",
227-
Source: "mongodb/mongodbatlas",
228-
},
229-
"aws": {
230-
VersionConstraint: "5.1.0",
231-
Source: "hashicorp/aws",
232-
},
233-
},
234-
235-
Config: testAccMongoDBAtlasEncryptionAtRestConfigAwsKms(projectID, &awsKms),
219+
ExternalProviders: acc.ExternalProvidersWithAWS("1.11.0"),
220+
Config: testAccMongoDBAtlasEncryptionAtRestConfigAwsKms(projectID, &awsKms),
236221
Check: resource.ComposeTestCheckFunc(
237222
testAccCheckMongoDBAtlasEncryptionAtRestExists(resourceName),
238223
resource.TestCheckResourceAttr(resourceName, "project_id", projectID),

internal/service/encryptionatrest/resource_encryption_at_rest_test.go

+2-7
Original file line numberDiff line numberDiff line change
@@ -308,13 +308,8 @@ func TestAccAdvRSEncryptionAtRestWithRole_basicAWS(t *testing.T) {
308308
)
309309

310310
resource.Test(t, resource.TestCase{
311-
PreCheck: func() { acc.PreCheck(t); acc.PreCheckAwsEnv(t) },
312-
ExternalProviders: map[string]resource.ExternalProvider{
313-
"aws": {
314-
VersionConstraint: "5.1.0",
315-
Source: "hashicorp/aws",
316-
},
317-
},
311+
PreCheck: func() { acc.PreCheck(t); acc.PreCheckAwsEnv(t) },
312+
ExternalProviders: acc.ExternalProvidersOnlyAWS(),
318313
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
319314
CheckDestroy: testAccCheckMongoDBAtlasEncryptionAtRestDestroy,
320315
Steps: []resource.TestStep{

internal/service/federateddatabaseinstance/data_source_federated_database_instance_test.go

+2-12
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,7 @@ func TestAccDataSourceFederatedDatabaseInstance_basic(t *testing.T) {
3030
CheckDestroy: acc.CheckDestroyFederatedDatabaseInstance,
3131
Steps: []resource.TestStep{
3232
{
33-
ExternalProviders: map[string]resource.ExternalProvider{
34-
"aws": {
35-
VersionConstraint: "5.1.0",
36-
Source: "hashicorp/aws",
37-
},
38-
},
33+
ExternalProviders: acc.ExternalProvidersOnlyAWS(),
3934
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
4035
Config: testAccMongoDBAtlasFederatedDatabaseInstanceConfigDataSourceFirstSteps(name, projectName, orgID),
4136
Check: resource.ComposeTestCheckFunc(
@@ -71,12 +66,7 @@ func TestAccDataSourceFederatedDatabaseInstance_S3Bucket(t *testing.T) {
7166
CheckDestroy: acc.CheckDestroyFederatedDatabaseInstance,
7267
Steps: []resource.TestStep{
7368
{
74-
ExternalProviders: map[string]resource.ExternalProvider{
75-
"aws": {
76-
VersionConstraint: "5.1.0",
77-
Source: "hashicorp/aws",
78-
},
79-
},
69+
ExternalProviders: acc.ExternalProvidersOnlyAWS(),
8070
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
8171
Config: testAccMongoDBAtlasFederatedDatabaseInstanceDataSourceConfigS3Bucket(policyName, roleName, projectName, orgID, name, testS3Bucket, region),
8272
Check: resource.ComposeTestCheckFunc(

internal/service/federateddatabaseinstance/data_source_federated_database_instances_test.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,7 @@ func TestAccDataSourceFederatedDatabaseInstances_basic(t *testing.T) {
2929
CheckDestroy: acc.CheckDestroyFederatedDatabaseInstance,
3030
Steps: []resource.TestStep{
3131
{
32-
ExternalProviders: map[string]resource.ExternalProvider{
33-
"aws": {
34-
VersionConstraint: "5.1.0",
35-
Source: "hashicorp/aws",
36-
},
37-
},
32+
ExternalProviders: acc.ExternalProvidersOnlyAWS(),
3833
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
3934
Config: testAccMongoDBAtlasFederatedDatabaseInstancesDataSourceConfig(policyName, roleName, projectName, orgID, firstName, secondName, testS3Bucket, region),
4035
Check: resource.ComposeTestCheckFunc(

internal/service/federateddatabaseinstance/resource_federated_database_instance_test.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,7 @@ func TestAccFederatedDatabaseInstance_S3bucket(t *testing.T) {
7777
CheckDestroy: acc.CheckDestroyFederatedDatabaseInstance,
7878
Steps: []resource.TestStep{
7979
{
80-
ExternalProviders: map[string]resource.ExternalProvider{
81-
"aws": {
82-
VersionConstraint: "5.1.0",
83-
Source: "hashicorp/aws",
84-
},
85-
},
80+
ExternalProviders: acc.ExternalProvidersOnlyAWS(),
8681
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
8782
Config: testAccMongoDBAtlasFederatedDatabaseInstanceConfigS3Bucket(policyName, roleName, projectName, orgID, name, testS3Bucket, region),
8883
Check: resource.ComposeTestCheckFunc(

internal/service/federatedquerylimit/data_source_federated_query_limit_test.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,7 @@ func TestAccDataSourceFederatedDatabaseQueryLimit_basic(t *testing.T) {
3737
CheckDestroy: testAccCheckMongoDBAtlasFederatedDatabaseQueryLimitDestroy,
3838
Steps: []resource.TestStep{
3939
{
40-
ExternalProviders: map[string]resource.ExternalProvider{
41-
"aws": {
42-
VersionConstraint: "5.1.0",
43-
Source: "hashicorp/aws",
44-
},
45-
},
40+
ExternalProviders: acc.ExternalProvidersOnlyAWS(),
4641
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
4742
Config: testAccMongoDBAtlasFederatedDatabaseQueryLimitDataSourceConfig(policyName, roleName, projectName, orgID, tenantName, testS3Bucket, region),
4843
Check: resource.ComposeTestCheckFunc(

internal/service/federatedquerylimit/data_source_federated_query_limits_test.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,7 @@ func TestAccDataSourceFederatedDatabaseQueryLimits_basic(t *testing.T) {
2828
CheckDestroy: testAccCheckMongoDBAtlasFederatedDatabaseQueryLimitDestroy,
2929
Steps: []resource.TestStep{
3030
{
31-
ExternalProviders: map[string]resource.ExternalProvider{
32-
"aws": {
33-
VersionConstraint: "5.1.0",
34-
Source: "hashicorp/aws",
35-
},
36-
},
31+
ExternalProviders: acc.ExternalProvidersOnlyAWS(),
3732
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
3833
Config: testAccMongoDBAtlasFederatedDatabaseQueryLimitsDataSourceConfig(policyName, roleName, projectName, orgID, tenantName, testS3Bucket, region),
3934
Check: resource.ComposeTestCheckFunc(

internal/service/federatedquerylimit/resource_federated_query_limit_test.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,7 @@ func TestAccFederatedDatabaseQueryLimit_basic(t *testing.T) {
3333
CheckDestroy: testAccCheckMongoDBAtlasFederatedDatabaseQueryLimitDestroy,
3434
Steps: []resource.TestStep{
3535
{
36-
ExternalProviders: map[string]resource.ExternalProvider{
37-
"aws": {
38-
VersionConstraint: "5.1.0",
39-
Source: "hashicorp/aws",
40-
},
41-
},
36+
ExternalProviders: acc.ExternalProvidersOnlyAWS(),
4237
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
4338
Config: testAccMongoDBAtlasFederatedDatabaseQueryLimitConfig(policyName, roleName, projectName, orgID, tenantName, testS3Bucket, region),
4439
Check: resource.ComposeTestCheckFunc(

internal/service/privatelinkendpointservice/resource_privatelink_endpoint_service_migration_test.go

+2-7
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func TestAccMigrationNetworkRSPrivateLinkEndpointService_Complete(t *testing.T)
3333
CheckDestroy: testAccCheckMongoDBAtlasPrivateLinkEndpointServiceDestroy,
3434
Steps: []resource.TestStep{
3535
{
36-
ExternalProviders: mig.ExternalProvidersWithAWS("5.1.0"),
36+
ExternalProviders: mig.ExternalProvidersWithAWS(),
3737
Config: testAccMongoDBAtlasPrivateLinkEndpointServiceConfigCompleteAWS(
3838
awsAccessKey, awsSecretKey, projectID, providerName, region, vpcID, subnetID, securityGroupID, resourceSuffix,
3939
),
@@ -45,12 +45,7 @@ func TestAccMigrationNetworkRSPrivateLinkEndpointService_Complete(t *testing.T)
4545
),
4646
},
4747
{
48-
ExternalProviders: map[string]resource.ExternalProvider{
49-
"aws": {
50-
VersionConstraint: "5.1.0",
51-
Source: "hashicorp/aws",
52-
},
53-
},
48+
ExternalProviders: acc.ExternalProvidersOnlyAWS(),
5449
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
5550
Config: testAccMongoDBAtlasPrivateLinkEndpointServiceConfigCompleteAWS(
5651
awsAccessKey, awsSecretKey, projectID, providerName, region, vpcID, subnetID, securityGroupID, resourceSuffix,

internal/service/privatelinkendpointservice/resource_privatelink_endpoint_service_test.go

+2-12
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,7 @@ func TestAccNetworkRSPrivateLinkEndpointServiceAWS_Complete(t *testing.T) {
3434
PreCheck: func() { acc.PreCheck(t); acc.PreCheckAwsEnv(t) },
3535
CheckDestroy: testAccCheckMongoDBAtlasPrivateLinkEndpointServiceDestroy,
3636
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
37-
ExternalProviders: map[string]resource.ExternalProvider{
38-
"aws": {
39-
VersionConstraint: "5.1.0",
40-
Source: "hashicorp/aws",
41-
},
42-
},
37+
ExternalProviders: acc.ExternalProvidersOnlyAWS(),
4338
Steps: []resource.TestStep{
4439
{
4540
Config: testAccMongoDBAtlasPrivateLinkEndpointServiceConfigCompleteAWS(
@@ -77,12 +72,7 @@ func TestAccNetworkRSPrivateLinkEndpointServiceAWS_import(t *testing.T) {
7772
PreCheck: func() { acc.PreCheck(t); acc.PreCheckAwsEnv(t) },
7873
CheckDestroy: testAccCheckMongoDBAtlasPrivateLinkEndpointServiceDestroy,
7974
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
80-
ExternalProviders: map[string]resource.ExternalProvider{
81-
"aws": {
82-
VersionConstraint: "5.1.0",
83-
Source: "hashicorp/aws",
84-
},
85-
},
75+
ExternalProviders: acc.ExternalProvidersOnlyAWS(),
8676
Steps: []resource.TestStep{
8777
{
8878
Config: testAccMongoDBAtlasPrivateLinkEndpointServiceConfigCompleteAWS(

internal/service/projectapikey/resource_project_api_key_migration_test.go

+2-7
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,8 @@ func TestAccMigrationConfigRSProjectAPIKey_RemovingOptionalRootProjectID(t *test
2424
CheckDestroy: testAccCheckMongoDBAtlasProjectAPIKeyDestroy,
2525
Steps: []resource.TestStep{
2626
{
27-
ExternalProviders: map[string]resource.ExternalProvider{
28-
"mongodbatlas": {
29-
VersionConstraint: "1.13.1", // fixed version as this is the last version where root project id was required.
30-
Source: "mongodb/mongodbatlas",
31-
},
32-
},
33-
Config: testAccMongoDBAtlasProjectAPIKeyConfigBasic(orgID, projectName, description, roleName, true),
27+
ExternalProviders: acc.ExternalProviders("1.13.1"), // fixed version as this is the last version where root project id was required.
28+
Config: testAccMongoDBAtlasProjectAPIKeyConfigBasic(orgID, projectName, description, roleName, true),
3429
Check: resource.ComposeTestCheckFunc(
3530
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
3631
resource.TestCheckResourceAttr(resourceName, "description", description),

internal/testutil/acc/provider.go

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package acc
2+
3+
import (
4+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
5+
)
6+
7+
func ExternalProviders(versionAtlasProvider string) map[string]resource.ExternalProvider {
8+
return map[string]resource.ExternalProvider{
9+
"mongodbatlas": *providerAtlas(versionAtlasProvider),
10+
}
11+
}
12+
13+
func ExternalProvidersWithAWS(versionAtlasProvider string) map[string]resource.ExternalProvider {
14+
return map[string]resource.ExternalProvider{
15+
"mongodbatlas": *providerAtlas(versionAtlasProvider),
16+
"aws": *providerAWS(),
17+
}
18+
}
19+
20+
func ExternalProvidersOnlyAWS() map[string]resource.ExternalProvider {
21+
return map[string]resource.ExternalProvider{
22+
"aws": *providerAWS(),
23+
}
24+
}
25+
26+
func providerAtlas(versionAtlasProvider string) *resource.ExternalProvider {
27+
return &resource.ExternalProvider{
28+
VersionConstraint: versionAtlasProvider,
29+
Source: "mongodb/mongodbatlas",
30+
}
31+
}
32+
33+
func providerAWS() *resource.ExternalProvider {
34+
return &resource.ExternalProvider{
35+
VersionConstraint: "5.1.0",
36+
Source: "hashicorp/aws",
37+
}
38+
}

internal/testutil/mig/provider.go

+9-22
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,23 @@ import (
66

77
"github.com/hashicorp/go-version"
88
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
9+
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc"
910
)
1011

11-
func ExternalProviders() map[string]resource.ExternalProvider {
12-
return map[string]resource.ExternalProvider{
13-
"mongodbatlas": {
14-
VersionConstraint: versionConstraint(),
15-
Source: "mongodb/mongodbatlas",
16-
},
17-
}
18-
}
19-
20-
func ExternalProvidersWithAWS(awsVersion string) map[string]resource.ExternalProvider {
21-
return map[string]resource.ExternalProvider{
22-
"mongodbatlas": {
23-
VersionConstraint: versionConstraint(),
24-
Source: "mongodb/mongodbatlas",
25-
},
26-
"aws": {
27-
VersionConstraint: awsVersion,
28-
Source: "hashicorp/aws",
29-
},
30-
}
31-
}
32-
3312
func IsProviderVersionAtLeast(minVersion string) bool {
3413
vProvider, errProvider := version.NewVersion(versionConstraint())
3514
vMin, errMin := version.NewVersion(minVersion)
3615
return errProvider == nil && errMin == nil && vProvider.GreaterThanOrEqual(vMin)
3716
}
3817

18+
func ExternalProviders() map[string]resource.ExternalProvider {
19+
return acc.ExternalProviders(versionConstraint())
20+
}
21+
22+
func ExternalProvidersWithAWS() map[string]resource.ExternalProvider {
23+
return acc.ExternalProvidersWithAWS(versionConstraint())
24+
}
25+
3926
func checkLastVersion(tb testing.TB) {
4027
tb.Helper()
4128
if os.Getenv("MONGODB_ATLAS_LAST_VERSION") == "" {

0 commit comments

Comments
 (0)