Skip to content

Commit f46bf9f

Browse files
authored
chore: Fix some tests in PAK and SA executions (#3765)
1 parent 8aa6d8a commit f46bf9f

File tree

5 files changed

+69
-74
lines changed

5 files changed

+69
-74
lines changed

.github/workflows/acceptance-tests-runner.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,8 @@ jobs:
11501150

11511151
resource_policy:
11521152
needs: [ change-detection, get-provider-version ]
1153-
if: ${{ needs.change-detection.outputs.resource_policy == 'true' || inputs.test_group == 'resource_policy' }}
1153+
# Skip in SA as it uses a different org and credentials.
1154+
if: ${{ inputs.use_sa == false && (needs.change-detection.outputs.resource_policy == 'true' || inputs.test_group == 'resource_policy') }}
11541155
runs-on: ubuntu-latest
11551156
permissions: {}
11561157
steps:
@@ -1170,8 +1171,7 @@ jobs:
11701171
MONGODB_ATLAS_PUBLIC_KEY: ${{ secrets.mongodb_atlas_rp_public_key }}
11711172
MONGODB_ATLAS_PRIVATE_KEY: ${{ secrets.mongodb_atlas_rp_private_key }}
11721173
MONGODB_ATLAS_LAST_VERSION: ${{ needs.get-provider-version.outputs.provider_version }}
1173-
ACCTEST_PACKAGES: |
1174-
./internal/service/resourcepolicy
1174+
ACCTEST_PACKAGES: ./internal/service/resourcepolicy
11751175
run: make testacc
11761176

11771177
search_deployment:

internal/config/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ func (r *RealmClient) Get(ctx context.Context) (*realm.Client, error) {
220220
if r.realmBaseURL != "" {
221221
adminURL := r.realmBaseURL + "/api/admin/v3.0/"
222222
optsRealm = append(optsRealm, realm.SetBaseURL(adminURL))
223-
authConfig.AuthURL, _ = url.Parse(adminURL + "/auth/providers/mongodb-cloud/login")
223+
authConfig.AuthURL, _ = url.Parse(adminURL + "auth/providers/mongodb-cloud/login")
224224
}
225225

226226
token, err := authConfig.NewTokenFromCredentials(ctx, r.publicKey, r.privateKey)

internal/provider/provider.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ import (
5050
)
5151

5252
const (
53-
govURL = "https://cloud.mongodbgov.com"
54-
MongodbGovCloudDevURL = "https://cloud-dev.mongodbgov.com"
5553
ProviderConfigError = "error in configuring the provider."
5654
MissingAuthAttrError = "either AWS Secrets Manager, Service Accounts or Atlas Programmatic API Keys attributes must be set"
5755
ProviderMetaUserAgentExtra = "user_agent_extra"
@@ -62,13 +60,6 @@ const (
6260
ProviderMetaModuleVersionDesc = "The version of the module using the provider"
6361
)
6462

65-
var (
66-
govAdditionalURLs = []string{
67-
"https://cloud-dev.mongodbgov.com",
68-
"https://cloud-qa.mongodbgov.com",
69-
}
70-
)
71-
7263
type MongodbtlasProvider struct {
7364
}
7465

@@ -230,10 +221,7 @@ func getProviderVars(ctx context.Context, req provider.ConfigureRequest, resp *p
230221
if len(data.AssumeRole) > 0 {
231222
assumeRoleARN = data.AssumeRole[0].RoleARN.ValueString()
232223
}
233-
baseURL := data.BaseURL.ValueString()
234-
if data.IsMongodbGovCloud.ValueBool() && !slices.Contains(govAdditionalURLs, baseURL) {
235-
baseURL = govURL
236-
}
224+
baseURL := applyGovBaseURLIfNeeded(data.BaseURL.ValueString(), data.IsMongodbGovCloud.ValueBool())
237225
return &config.Vars{
238226
AccessToken: data.AccessToken.ValueString(),
239227
ClientID: data.ClientID.ValueString(),
@@ -252,6 +240,18 @@ func getProviderVars(ctx context.Context, req provider.ConfigureRequest, resp *p
252240
}
253241
}
254242

243+
func applyGovBaseURLIfNeeded(providerBaseURL string, providerIsMongodbGovCloud bool) string {
244+
const govURL = "https://cloud.mongodbgov.com"
245+
govAdditionalURLs := []string{
246+
"https://cloud-dev.mongodbgov.com",
247+
"https://cloud-qa.mongodbgov.com",
248+
}
249+
if providerIsMongodbGovCloud && !slices.Contains(govAdditionalURLs, config.NormalizeBaseURL(providerBaseURL)) {
250+
return govURL
251+
}
252+
return providerBaseURL
253+
}
254+
255255
func (p *MongodbtlasProvider) DataSources(context.Context) []func() datasource.DataSource {
256256
dataSources := []func() datasource.DataSource{
257257
project.DataSource,

internal/provider/provider_sdk2.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package provider
33
import (
44
"context"
55
"fmt"
6-
"slices"
76

87
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
98
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -319,10 +318,7 @@ func getSDKv2ProviderVars(d *schema.ResourceData) *config.Vars {
319318
assumeRoleARN = assumeRole["role_arn"].(string)
320319
}
321320
}
322-
baseURL := d.Get("base_url").(string)
323-
if d.Get("is_mongodbgov_cloud").(bool) && !slices.Contains(govAdditionalURLs, baseURL) {
324-
baseURL = govURL
325-
}
321+
baseURL := applyGovBaseURLIfNeeded(d.Get("base_url").(string), d.Get("is_mongodbgov_cloud").(bool))
326322
return &config.Vars{
327323
AccessToken: d.Get("access_token").(string),
328324
ClientID: d.Get("client_id").(string),

internal/service/advancedcluster/resource_test.go

Lines changed: 51 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,7 @@ func TestAccClusterAdvancedCluster_pausedToUnpaused(t *testing.T) {
287287
func TestAccClusterAdvancedCluster_advancedConfig_oldMongoDBVersion(t *testing.T) {
288288
var (
289289
projectID, clusterName = acc.ProjectIDExecutionWithCluster(t, 4)
290-
processArgs = &admin.ClusterDescriptionProcessArgs20240805{
291-
ChangeStreamOptionsPreAndPostImagesExpireAfterSeconds: conversion.IntPtr(-1), // this will not be set in the TF configuration
292-
DefaultMaxTimeMS: conversion.IntPtr(65),
290+
processArgsCommon = &admin.ClusterDescriptionProcessArgs20240805{
293291
DefaultWriteConcern: conversion.StringPtr("1"),
294292
JavascriptEnabled: conversion.Pointer(true),
295293
MinimumEnabledTlsProtocol: conversion.StringPtr("TLS1_2"),
@@ -299,24 +297,26 @@ func TestAccClusterAdvancedCluster_advancedConfig_oldMongoDBVersion(t *testing.T
299297
SampleSizeBIConnector: conversion.Pointer(110),
300298
TransactionLifetimeLimitSeconds: conversion.Pointer[int64](300),
301299
}
302-
processArgsCipherConfig = &admin.ClusterDescriptionProcessArgs20240805{
303-
TlsCipherConfigMode: conversion.StringPtr("CUSTOM"),
304-
CustomOpensslCipherConfigTls12: &[]string{"TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384"},
305-
}
306300
)
301+
processArgs := *processArgsCommon
302+
processArgs.DefaultMaxTimeMS = conversion.IntPtr(65)
303+
304+
processArgsCipherConfig := *processArgsCommon
305+
processArgsCipherConfig.TlsCipherConfigMode = conversion.StringPtr("CUSTOM")
306+
processArgsCipherConfig.CustomOpensslCipherConfigTls12 = &[]string{"TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384"}
307307

308308
resource.ParallelTest(t, resource.TestCase{
309309
PreCheck: acc.PreCheckBasicSleep(t, nil, projectID, clusterName),
310310
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
311311
CheckDestroy: acc.CheckDestroyCluster,
312312
Steps: []resource.TestStep{
313313
{
314-
Config: configAdvanced(t, projectID, clusterName, "7.0", processArgs),
314+
Config: configAdvanced(t, projectID, clusterName, "7.0", &processArgs),
315315
ExpectError: regexp.MustCompile(errDefaultMaxTimeMinVersion),
316316
},
317317
{
318-
Config: configAdvanced(t, projectID, clusterName, "7.0", processArgsCipherConfig),
319-
Check: checkAdvanced(clusterName, "TLS1_2", processArgsCipherConfig),
318+
Config: configAdvanced(t, projectID, clusterName, "7.0", &processArgsCipherConfig),
319+
Check: checkAdvanced(clusterName, "TLS1_2", &processArgsCipherConfig),
320320
},
321321
acc.TestStepImportCluster(resourceName),
322322
},
@@ -1108,7 +1108,7 @@ func TestAccAdvancedCluster_createTimeoutWithDeleteOnCreateReplicaset(t *testing
11081108
Timeout: 60 * time.Second,
11091109
IsDelete: true,
11101110
}, "waiting for cluster to be deleted after cleanup in create timeout", diags)
1111-
time.Sleep(1 * time.Minute) // decrease the chance of `CONTAINER_WAITING_FOR_FAST_RECORD_CLEAN_UP`: "A transient error occurred. Please try again in a minute or use a different name"
1111+
time.Sleep(2 * time.Minute) // decrease the chance of `CONTAINER_WAITING_FOR_FAST_RECORD_CLEAN_UP`: "A transient error occurred. Please try again in a minute or use a different name"
11121112
}
11131113
)
11141114
resource.ParallelTest(t, *createCleanupTest(t, configCall, waitOnClusterDeleteDone, true))
@@ -1895,40 +1895,51 @@ func checkSingleProviderPaused(name string, paused bool) resource.TestCheckFunc
18951895

18961896
func configAdvanced(t *testing.T, projectID, clusterName, mongoDBMajorVersion string, p *admin.ClusterDescriptionProcessArgs20240805) string {
18971897
t.Helper()
1898-
changeStreamOptionsStr := ""
1899-
defaultMaxTimeStr := ""
1900-
tlsCipherConfigModeStr := ""
1901-
customOpensslCipherConfigTLS12Str := ""
1898+
advancedConfig := ""
19021899
mongoDBMajorVersionStr := ""
1903-
1904-
if p != nil {
1905-
if p.ChangeStreamOptionsPreAndPostImagesExpireAfterSeconds != nil && p.ChangeStreamOptionsPreAndPostImagesExpireAfterSeconds != conversion.IntPtr(-1) {
1906-
changeStreamOptionsStr = fmt.Sprintf(`change_stream_options_pre_and_post_images_expire_after_seconds = %[1]d`, *p.ChangeStreamOptionsPreAndPostImagesExpireAfterSeconds)
1907-
}
1908-
if p.DefaultMaxTimeMS != nil {
1909-
defaultMaxTimeStr = fmt.Sprintf(`default_max_time_ms = %[1]d`, *p.DefaultMaxTimeMS)
1910-
}
1911-
if p.TlsCipherConfigMode != nil {
1912-
tlsCipherConfigModeStr = fmt.Sprintf(`tls_cipher_config_mode = %[1]q`, *p.TlsCipherConfigMode)
1913-
if p.CustomOpensslCipherConfigTls12 != nil && len(*p.CustomOpensslCipherConfigTls12) > 0 {
1914-
customOpensslCipherConfigTLS12Str = fmt.Sprintf(
1915-
`custom_openssl_cipher_config_tls12 = [%s]`,
1916-
acc.JoinQuotedStrings(*p.CustomOpensslCipherConfigTls12),
1917-
)
1918-
}
1900+
if mongoDBMajorVersion != "" {
1901+
mongoDBMajorVersionStr = fmt.Sprintf("mongo_db_major_version = %[1]q\n", mongoDBMajorVersion)
1902+
}
1903+
if p.JavascriptEnabled != nil {
1904+
advancedConfig += fmt.Sprintf("javascript_enabled = %[1]t\n", *p.JavascriptEnabled)
1905+
}
1906+
if p.NoTableScan != nil {
1907+
advancedConfig += fmt.Sprintf("no_table_scan = %[1]t\n", *p.NoTableScan)
1908+
}
1909+
if p.OplogSizeMB != nil {
1910+
advancedConfig += fmt.Sprintf("oplog_size_mb = %[1]d\n", *p.OplogSizeMB)
1911+
}
1912+
if p.SampleRefreshIntervalBIConnector != nil {
1913+
advancedConfig += fmt.Sprintf("sample_refresh_interval_bi_connector = %[1]d\n", *p.SampleRefreshIntervalBIConnector)
1914+
}
1915+
if p.SampleSizeBIConnector != nil {
1916+
advancedConfig += fmt.Sprintf("sample_size_bi_connector = %[1]d\n", *p.SampleSizeBIConnector)
1917+
}
1918+
if p.TransactionLifetimeLimitSeconds != nil {
1919+
advancedConfig += fmt.Sprintf("transaction_lifetime_limit_seconds = %[1]d\n", *p.TransactionLifetimeLimitSeconds)
1920+
}
1921+
if p.ChangeStreamOptionsPreAndPostImagesExpireAfterSeconds != nil && *p.ChangeStreamOptionsPreAndPostImagesExpireAfterSeconds != -1 {
1922+
advancedConfig += fmt.Sprintf("change_stream_options_pre_and_post_images_expire_after_seconds = %[1]d\n", *p.ChangeStreamOptionsPreAndPostImagesExpireAfterSeconds)
1923+
}
1924+
if p.DefaultMaxTimeMS != nil {
1925+
advancedConfig += fmt.Sprintf("default_max_time_ms = %[1]d\n", *p.DefaultMaxTimeMS)
1926+
}
1927+
if p.TlsCipherConfigMode != nil {
1928+
advancedConfig += fmt.Sprintf("tls_cipher_config_mode = %[1]q\n", *p.TlsCipherConfigMode)
1929+
if p.CustomOpensslCipherConfigTls12 != nil && len(*p.CustomOpensslCipherConfigTls12) > 0 {
1930+
advancedConfig += fmt.Sprintf("custom_openssl_cipher_config_tls12 = [%s]\n", acc.JoinQuotedStrings(*p.CustomOpensslCipherConfigTls12))
19191931
}
19201932
}
1921-
if mongoDBMajorVersion != "" {
1922-
mongoDBMajorVersionStr = fmt.Sprintf(`mongo_db_major_version = %[1]q`, mongoDBMajorVersion)
1933+
if p.MinimumEnabledTlsProtocol != nil {
1934+
advancedConfig += fmt.Sprintf("minimum_enabled_tls_protocol = %[1]q\n", *p.MinimumEnabledTlsProtocol)
19231935
}
19241936

19251937
return fmt.Sprintf(`
19261938
resource "mongodbatlas_advanced_cluster" "test" {
19271939
project_id = %[1]q
19281940
name = %[2]q
19291941
cluster_type = "REPLICASET"
1930-
%[12]s
1931-
1942+
%[3]s
19321943
replication_specs = [{
19331944
region_configs = [{
19341945
electable_specs = {
@@ -1946,22 +1957,10 @@ func configAdvanced(t *testing.T, projectID, clusterName, mongoDBMajorVersion st
19461957
}]
19471958
19481959
advanced_configuration = {
1949-
javascript_enabled = %[3]t
1950-
minimum_enabled_tls_protocol = %[4]q
1951-
no_table_scan = %[5]t
1952-
oplog_size_mb = %[6]d
1953-
sample_size_bi_connector = %[7]d
1954-
sample_refresh_interval_bi_connector = %[8]d
1955-
transaction_lifetime_limit_seconds = %[9]d
1956-
%[10]s
1957-
%[11]s
1958-
%[13]s
1959-
%[14]s
1960+
%[4]s
19601961
}
19611962
}
1962-
`, projectID, clusterName, p.GetJavascriptEnabled(), p.GetMinimumEnabledTlsProtocol(), p.GetNoTableScan(),
1963-
p.GetOplogSizeMB(), p.GetSampleSizeBIConnector(), p.GetSampleRefreshIntervalBIConnector(), p.GetTransactionLifetimeLimitSeconds(),
1964-
changeStreamOptionsStr, defaultMaxTimeStr, mongoDBMajorVersionStr, tlsCipherConfigModeStr, customOpensslCipherConfigTLS12Str) + dataSourcesConfig
1963+
`, projectID, clusterName, mongoDBMajorVersionStr, advancedConfig) + dataSourcesConfig
19651964
}
19661965

19671966
func checkAdvanced(name, tls string, processArgs *admin.ClusterDescriptionProcessArgs20240805) resource.TestCheckFunc {
@@ -2689,13 +2688,13 @@ func configPriority(t *testing.T, projectID, clusterName string, swapPriorities
26892688

26902689
func configBiConnectorConfig(t *testing.T, projectID, name string, enabled bool) string {
26912690
t.Helper()
2692-
additionalConfig := `
2691+
advancedConfig := `
26932692
bi_connector_config = {
26942693
enabled = false
26952694
}
26962695
`
26972696
if enabled {
2698-
additionalConfig = `
2697+
advancedConfig = `
26992698
bi_connector_config = {
27002699
enabled = true
27012700
read_preference = "secondary"
@@ -2727,7 +2726,7 @@ func configBiConnectorConfig(t *testing.T, projectID, name string, enabled bool)
27272726
27282727
%[3]s
27292728
}
2730-
`, projectID, name, additionalConfig) + dataSourcesConfig
2729+
`, projectID, name, advancedConfig) + dataSourcesConfig
27312730
}
27322731

27332732
func checkTenantBiConnectorConfig(projectID, name string, enabled bool) resource.TestCheckFunc {

0 commit comments

Comments
 (0)