Skip to content

Commit 83725e4

Browse files
add acceptance test transitioning for public to private network
1 parent 69ec0d1 commit 83725e4

File tree

2 files changed

+54
-9
lines changed

2 files changed

+54
-9
lines changed

internal/service/encryptionatrestprivateendpoint/resource.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ import (
99

1010
"github.com/hashicorp/terraform-plugin-framework/path"
1111
"github.com/hashicorp/terraform-plugin-framework/resource"
12+
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/retrystrategy"
1213
"github.com/mongodb/terraform-provider-mongodbatlas/internal/config"
1314
"go.mongodb.org/atlas-sdk/v20240805001/admin"
1415
)
1516

1617
const (
1718
encryptionAtRestPrivateEndpointName = "encryption_at_rest_private_endpoint"
1819
warnUnsupportedOperation = "Operation not supported"
19-
failedStatus = "FAILED"
2020
)
2121

2222
var _ resource.ResourceWithConfigure = &encryptionAtRestPrivateEndpointRS{}
@@ -45,11 +45,11 @@ func (r *encryptionAtRestPrivateEndpointRS) Create(ctx context.Context, req reso
4545
return
4646
}
4747

48-
encryptionAtRestPrivateEndpointReq := NewEarPrivateEndpointReq(&earPrivateEndpointPlan)
48+
privateEndpointReq := NewEarPrivateEndpointReq(&earPrivateEndpointPlan)
4949
connV2 := r.Client.AtlasV2
5050
projectID := earPrivateEndpointPlan.ProjectID.ValueString()
5151
cloudProvider := earPrivateEndpointPlan.CloudProvider.ValueString()
52-
createResp, _, err := connV2.EncryptionAtRestUsingCustomerKeyManagementApi.CreateEncryptionAtRestPrivateEndpoint(ctx, projectID, cloudProvider, encryptionAtRestPrivateEndpointReq).Execute()
52+
createResp, _, err := connV2.EncryptionAtRestUsingCustomerKeyManagementApi.CreateEncryptionAtRestPrivateEndpoint(ctx, projectID, cloudProvider, privateEndpointReq).Execute()
5353
if err != nil {
5454
resp.Diagnostics.AddError("error creating resource", err.Error())
5555
return
@@ -61,8 +61,8 @@ func (r *encryptionAtRestPrivateEndpointRS) Create(ctx context.Context, req reso
6161
return
6262
}
6363

64-
newencryptionAtRestPrivateEndpointModel := NewTFEarPrivateEndpoint(finalResp, projectID)
65-
resp.Diagnostics.Append(resp.State.Set(ctx, newencryptionAtRestPrivateEndpointModel)...)
64+
privateEndpointModel := NewTFEarPrivateEndpoint(finalResp, projectID)
65+
resp.Diagnostics.Append(resp.State.Set(ctx, privateEndpointModel)...)
6666
if err := getErrorForFailedStatus(finalResp); err != nil {
6767
resp.Diagnostics.AddError("failed status", err.Error())
6868
}
@@ -150,7 +150,7 @@ func splitEncryptionAtRestPrivateEndpointImportID(id string) (projectID, cloudPr
150150
}
151151

152152
func getErrorForFailedStatus(model *admin.EARPrivateEndpoint) error {
153-
if model.GetStatus() != failedStatus {
153+
if model.GetStatus() != retrystrategy.RetryStrategyFailedState {
154154
return nil
155155
}
156156
msg := model.GetErrorMessage()

internal/service/encryptionatrestprivateendpoint/resource_test.go

+48-3
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ func basicTestCase(tb testing.TB) *resource.TestCase {
4444
CheckDestroy: checkDestroy,
4545
Steps: []resource.TestStep{
4646
{
47-
Config: configAzureBasic(projectID, azureKeyVault, region),
47+
Config: configPrivateEndpointAzureBasic(projectID, azureKeyVault, region),
4848
Check: resource.ComposeAggregateTestCheckFunc(
4949
resource.TestCheckResourceAttrSet(resourceName, "id"),
5050
resource.TestCheckResourceAttr(resourceName, "status", "PENDING_ACCEPTANCE"),
5151
),
5252
},
5353
{
54-
Config: configAzureBasic(projectID, azureKeyVault, region),
54+
Config: configPrivateEndpointAzureBasic(projectID, azureKeyVault, region),
5555
ResourceName: resourceName,
5656
ImportStateIdFunc: importStateIDFunc(resourceName),
5757
ImportState: true,
@@ -61,6 +61,51 @@ func basicTestCase(tb testing.TB) *resource.TestCase {
6161
}
6262
}
6363

64+
func TestAccEncryptionAtRestPrivateEndpoint_transitionPublicToPrivateNetwork(t *testing.T) {
65+
acc.SkipTestForCI(t) // needs Azure configuration
66+
var (
67+
earResourceName = "mongodbatlas_encryption_at_rest.test"
68+
privateEndpointResourceName = "mongodbatlas_encryption_at_rest_private_endpoint.test"
69+
projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID")
70+
azureKeyVault = &admin.AzureKeyVault{
71+
Enabled: conversion.Pointer(true),
72+
RequirePrivateNetworking: conversion.Pointer(true),
73+
AzureEnvironment: conversion.StringPtr("AZURE"),
74+
ClientID: conversion.StringPtr(os.Getenv("AZURE_CLIENT_ID")),
75+
SubscriptionID: conversion.StringPtr(os.Getenv("AZURE_SUBSCRIPTION_ID")),
76+
ResourceGroupName: conversion.StringPtr(os.Getenv("AZURE_RESOURCE_GROUP_NAME")),
77+
KeyVaultName: conversion.StringPtr(os.Getenv("AZURE_KEY_VAULT_NAME")),
78+
KeyIdentifier: conversion.StringPtr(os.Getenv("AZURE_KEY_IDENTIFIER")),
79+
Secret: conversion.StringPtr(os.Getenv("AZURE_SECRET")),
80+
TenantID: conversion.StringPtr(os.Getenv("AZURE_TENANT_ID")),
81+
}
82+
region = os.Getenv("AZURE_PRIVATE_ENDPOINT_REGION")
83+
)
84+
85+
resource.ParallelTest(t, resource.TestCase{
86+
PreCheck: func() { acc.PreCheckBasic(t) },
87+
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
88+
CheckDestroy: checkDestroy,
89+
Steps: []resource.TestStep{
90+
{
91+
Config: acc.ConfigEARAzureKeyVault(projectID, azureKeyVault, false),
92+
Check: resource.ComposeAggregateTestCheckFunc(
93+
resource.TestCheckResourceAttr(earResourceName, "azure_key_vault_config.0.enabled", "true"),
94+
resource.TestCheckResourceAttr(earResourceName, "azure_key_vault_config.0.require_private_networking", "false"),
95+
),
96+
},
97+
{
98+
Config: configPrivateEndpointAzureBasic(projectID, azureKeyVault, region),
99+
Check: resource.ComposeAggregateTestCheckFunc(
100+
resource.TestCheckResourceAttr(earResourceName, "azure_key_vault_config.0.require_private_networking", "true"),
101+
resource.TestCheckResourceAttrSet(privateEndpointResourceName, "id"),
102+
resource.TestCheckResourceAttr(privateEndpointResourceName, "status", "PENDING_ACCEPTANCE"),
103+
),
104+
},
105+
},
106+
})
107+
}
108+
64109
func importStateIDFunc(resourceName string) resource.ImportStateIdFunc {
65110
return func(s *terraform.State) (string, error) {
66111
rs, ok := s.RootModule().Resources[resourceName]
@@ -71,7 +116,7 @@ func importStateIDFunc(resourceName string) resource.ImportStateIdFunc {
71116
}
72117
}
73118

74-
func configAzureBasic(projectID string, azure *admin.AzureKeyVault, region string) string {
119+
func configPrivateEndpointAzureBasic(projectID string, azure *admin.AzureKeyVault, region string) string {
75120
encryptionAtRestConfig := acc.ConfigEARAzureKeyVault(projectID, azure, true)
76121
return fmt.Sprintf(`
77122
%[1]s

0 commit comments

Comments
 (0)