Skip to content

Commit c2dd5db

Browse files
authored
refactor: Removes deprecation messages for is_slow_operation_thresholding_enabled and unreachable code (#2922)
* refactor: remove deprecations * remove unreachable code * feat: add support for additional MongoDB Atlas public and private keys to use for testing limited access * fix: update MongoDB Atlas key references for QA and DEV environments in acceptance tests * refactor: Renames keys from PUBLIC_KEY2 to PUBLIC_KEY_READ_ONLY
1 parent a3f7e43 commit c2dd5db

9 files changed

+92
-14
lines changed

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

+6
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ on:
103103
required: true
104104
mongodb_atlas_private_key:
105105
required: true
106+
mongodb_atlas_public_key_read_only:
107+
required: true
108+
mongodb_atlas_private_key_read_only:
109+
required: true
106110
ca_cert:
107111
required: true
108112
aws_account_id:
@@ -175,6 +179,8 @@ env:
175179
MONGODB_ATLAS_ORG_ID: ${{ inputs.mongodb_atlas_org_id }}
176180
MONGODB_ATLAS_PUBLIC_KEY: ${{ secrets.mongodb_atlas_public_key }}
177181
MONGODB_ATLAS_PRIVATE_KEY: ${{ secrets.mongodb_atlas_private_key }}
182+
MONGODB_ATLAS_PUBLIC_KEY_READ_ONLY: ${{ secrets.mongodb_atlas_public_key_read_only }}
183+
MONGODB_ATLAS_PRIVATE_KEY_READ_ONLY: ${{ secrets.mongodb_atlas_private_key_read_only }}
178184
MONGODB_ATLAS_GOV_PUBLIC_KEY: ${{ secrets.mongodb_atlas_gov_public_key }}
179185
MONGODB_ATLAS_GOV_PRIVATE_KEY: ${{ secrets.mongodb_atlas_gov_private_key }}
180186
MONGODB_ATLAS_GOV_BASE_URL: ${{ inputs.mongodb_atlas_gov_base_url }}

.github/workflows/acceptance-tests.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ jobs:
5555
secrets:
5656
mongodb_atlas_public_key: ${{ inputs.atlas_cloud_env == 'qa' && secrets.MONGODB_ATLAS_PUBLIC_KEY_CLOUD_QA || secrets.MONGODB_ATLAS_PUBLIC_KEY_CLOUD_DEV }}
5757
mongodb_atlas_private_key: ${{ inputs.atlas_cloud_env == 'qa' && secrets.MONGODB_ATLAS_PRIVATE_KEY_CLOUD_QA || secrets.MONGODB_ATLAS_PRIVATE_KEY_CLOUD_DEV }}
58-
mongodb_atlas_gov_public_key: ${{ inputs.atlas_cloud_env == 'qa' && secrets.MONGODB_ATLAS_GOV_PUBLIC_KEY_QA || secrets.MONGODB_ATLAS_GOV_PUBLIC_KEY_DEV }}
58+
mongodb_atlas_public_key_read_only: ${{ inputs.atlas_cloud_env == 'qa' && secrets.MONGODB_ATLAS_PUBLIC_KEY_READ_ONLY_QA || secrets.MONGODB_ATLAS_PUBLIC_KEY_READ_ONLY_DEV }}
59+
mongodb_atlas_private_key_read_only: ${{ inputs.atlas_cloud_env == 'qa' && secrets.MONGODB_ATLAS_PRIVATE_KEY_READ_ONLY_QA || secrets.MONGODB_ATLAS_PRIVATE_KEY_READ_ONLY_DEV }}
60+
mongodb_atlas_gov_public_key: ${{ inputs.atlas_cloud_env == 'qa' && secrets.MONGODB_ATLAS_GOV_PUBLIC_KEY_QA || secrets.MONGODB_ATLAS_GOV_PUBLIC_KEY_DEV }}
5961
mongodb_atlas_gov_private_key: ${{ inputs.atlas_cloud_env == 'qa' && secrets.MONGODB_ATLAS_GOV_PRIVATE_KEY_QA || secrets.MONGODB_ATLAS_GOV_PRIVATE_KEY_DEV }}
6062
mongodb_atlas_rp_public_key: ${{ inputs.atlas_cloud_env == 'qa' && secrets.MONGODB_ATLAS_RP_PUBLIC_KEY_QA || secrets.MONGODB_ATLAS_RP_PUBLIC_KEY_DEV }}
6163
mongodb_atlas_rp_private_key: ${{ inputs.atlas_cloud_env == 'qa' && secrets.MONGODB_ATLAS_RP_PRIVATE_KEY_QA || secrets.MONGODB_ATLAS_RP_PRIVATE_KEY_DEV }}

internal/service/project/data_source_project.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ func (d *projectDS) Schema(ctx context.Context, req datasource.SchemaRequest, re
104104
Computed: true,
105105
},
106106
"is_slow_operation_thresholding_enabled": schema.BoolAttribute{
107-
Computed: true,
108-
DeprecationMessage: fmt.Sprintf(constant.DeprecationParamByVersion, "1.24.0"),
107+
Computed: true,
109108
},
110109
"region_usage_restrictions": schema.StringAttribute{
111110
Computed: true,

internal/service/project/data_source_projects.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ func (d *ProjectsDS) Schema(ctx context.Context, req datasource.SchemaRequest, r
9898
Computed: true,
9999
},
100100
"is_slow_operation_thresholding_enabled": schema.BoolAttribute{
101-
Computed: true,
102-
DeprecationMessage: fmt.Sprintf(constant.DeprecationParamByVersion, "1.24.0"),
101+
Computed: true,
103102
},
104103
"region_usage_restrictions": schema.StringAttribute{
105104
Computed: true,

internal/service/project/resource_project.go

-6
Original file line numberDiff line numberDiff line change
@@ -420,12 +420,6 @@ func SetSlowOperationThresholding(ctx context.Context, performanceAdvisorAPI adm
420420
func ReadIsSlowMsThresholdingEnabled(ctx context.Context, api admin.PerformanceAdvisorApi, projectID string, warnings *diag.Diagnostics) (bool, error) {
421421
response, err := api.GetManagedSlowMs(ctx, projectID).Execute()
422422
if err != nil {
423-
if admin.IsErrorCode(err, "USER_UNAUTHORIZED") {
424-
if warnings != nil {
425-
warnings.AddWarning("user does not have permission to read is_slow_operation_thresholding_enabled. Please read our documentation for more information.", fmt.Sprintf(ErrorProjectRead, projectID, err.Error()))
426-
}
427-
return false, nil
428-
}
429423
return false, err
430424
}
431425
var isEnabled bool

internal/service/project/resource_project_schema.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,8 @@ func ResourceSchema(ctx context.Context) schema.Schema {
101101
},
102102
},
103103
"is_slow_operation_thresholding_enabled": schema.BoolAttribute{
104-
Computed: true,
105-
Optional: true,
106-
DeprecationMessage: fmt.Sprintf(constant.DeprecationParamByVersion, "1.24.0"),
104+
Computed: true,
105+
Optional: true,
107106
PlanModifiers: []planmodifier.Bool{
108107
boolplanmodifier.UseStateForUnknown(),
109108
},

internal/service/project/resource_project_test.go

+68
Original file line numberDiff line numberDiff line change
@@ -1080,6 +1080,74 @@ func TestAccProject_withTags(t *testing.T) {
10801080
})
10811081
}
10821082

1083+
func TestAccProject_slowOperationReadOnly(t *testing.T) {
1084+
var (
1085+
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
1086+
projectName = acc.RandomProjectName()
1087+
config = configBasic(orgID, projectName, "", false, nil, conversion.Pointer(false))
1088+
providerConfigReadOnly = acc.ConfigReadOnlyProvider()
1089+
)
1090+
resource.ParallelTest(t, resource.TestCase{
1091+
PreCheck: func() { acc.PreCheckBasic(t); acc.PreCheckPublicKey2(t) },
1092+
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
1093+
CheckDestroy: acc.CheckDestroyProject,
1094+
Steps: []resource.TestStep{
1095+
{
1096+
Config: config,
1097+
Check: resource.ComposeAggregateTestCheckFunc(
1098+
resource.TestCheckResourceAttr(resourceName, "is_slow_operation_thresholding_enabled", "false"),
1099+
),
1100+
},
1101+
{
1102+
PreConfig: func() { changeRoles(t, orgID, projectName, "GROUP_READ_ONLY") },
1103+
Config: providerConfigReadOnly + config,
1104+
Check: resource.ComposeAggregateTestCheckFunc(
1105+
resource.TestCheckResourceAttr(resourceName, "is_slow_operation_thresholding_enabled", "false"),
1106+
),
1107+
},
1108+
// Validate the API Key has a different role
1109+
{
1110+
Config: providerConfigReadOnly + configBasic(orgID, projectName, "", false, nil, conversion.Pointer(true)),
1111+
ExpectError: regexp.MustCompile("error in project settings update"),
1112+
},
1113+
// read back again to ensure no changes, and allow deletion to work
1114+
{
1115+
Config: config,
1116+
Check: resource.ComposeAggregateTestCheckFunc(
1117+
resource.TestCheckResourceAttr(resourceName, "is_slow_operation_thresholding_enabled", "false"),
1118+
),
1119+
},
1120+
},
1121+
})
1122+
}
1123+
1124+
func changeRoles(t *testing.T, orgID, projectName, roleName string) {
1125+
t.Helper()
1126+
ctx := context.Background()
1127+
respProject, _, _ := acc.ConnV2().ProjectsApi.GetProjectByName(ctx, projectName).Execute()
1128+
projectID := respProject.GetId()
1129+
if projectID == "" {
1130+
t.Errorf("PreConfig: error finding project %s", projectName)
1131+
}
1132+
api := acc.ConnV2().ProgrammaticAPIKeysApi
1133+
respList, _, _ := api.ListApiKeys(ctx, orgID).Execute()
1134+
publicKey := os.Getenv("MONGODB_ATLAS_PUBLIC_KEY_READ_ONLY")
1135+
keys := respList.GetResults()
1136+
for _, result := range keys {
1137+
if result.GetPublicKey() != publicKey {
1138+
continue
1139+
}
1140+
apiKeyID := result.GetId()
1141+
assignment := admin.UpdateAtlasProjectApiKey{Roles: &[]string{roleName}}
1142+
_, _, err := api.UpdateApiKeyRoles(ctx, projectID, apiKeyID, &assignment).Execute()
1143+
if err != nil {
1144+
t.Errorf("PreConfig: error updating key %s", err)
1145+
}
1146+
return
1147+
}
1148+
t.Error("PreConfig: key not found")
1149+
}
1150+
10831151
func createDataFederationLimit(limitName string) admin.DataFederationLimit {
10841152
return admin.DataFederationLimit{
10851153
Name: limitName,

internal/testutil/acc/pre_check.go

+7
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,13 @@ func PreCheckGovBasic(tb testing.TB) {
148148
tb.Fatal("`MONGODB_ATLAS_GOV_BASE_URL`, `MONGODB_ATLAS_GOV_PUBLIC_KEY`, `MONGODB_ATLAS_GOV_PRIVATE_KEY`and `MONGODB_ATLAS_GOV_ORG_ID` must be set for acceptance testing")
149149
}
150150
}
151+
func PreCheckPublicKey2(tb testing.TB) {
152+
tb.Helper()
153+
if os.Getenv("MONGODB_ATLAS_PUBLIC_KEY_READ_ONLY") == "" ||
154+
os.Getenv("MONGODB_ATLAS_PRIVATE_KEY_READ_ONLY") == "" {
155+
tb.Fatal("`MONGODB_ATLAS_PUBLIC_KEY_READ_ONLY`, `MONGODB_ATLAS_PRIVATE_KEY_READ_ONLY` must be set for acceptance testing")
156+
}
157+
}
151158

152159
func PreCheckGPCEnv(tb testing.TB) {
153160
tb.Helper()

internal/testutil/acc/provider.go

+4
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ func ConfigGovProvider() string {
7676
return configProvider(os.Getenv("MONGODB_ATLAS_GOV_PUBLIC_KEY"), os.Getenv("MONGODB_ATLAS_GOV_PRIVATE_KEY"), os.Getenv("MONGODB_ATLAS_GOV_BASE_URL"))
7777
}
7878

79+
func ConfigReadOnlyProvider() string {
80+
return configProvider(os.Getenv("MONGODB_ATLAS_PUBLIC_KEY_READ_ONLY"), os.Getenv("MONGODB_ATLAS_PRIVATE_KEY_READ_ONLY"), os.Getenv("MONGODB_ATLAS_BASE_URL"))
81+
}
82+
7983
// configAzapiProvider creates a new azure/azapi provider with credentials explicit in config.
8084
// This will authorize the provider for a client
8185
func ConfigAzapiProvider(subscriptionID, clientID, clientSecret, tenantID string) string {

0 commit comments

Comments
 (0)