-
Notifications
You must be signed in to change notification settings - Fork 178
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: Enables mongodbatlas_encryption_at_rest
(Azure) tests to run in CI
#2551
Changes from 23 commits
fd8ba27
fab4d75
4bd71a8
4687f74
e525d5a
b601396
8eadad1
87f4d81
9a61029
dbe74c8
12c7243
7750fa0
241088a
d1d95cd
3e5c7ab
442d4b3
76ca07b
a9fa82b
dc561f9
175984e
3d30f00
88331ec
ffcde2a
0b41905
cbb97a1
db06804
1e75193
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -218,15 +218,12 @@ You must also configure the following environment variables before running the t | |
export AZURE_CLIENT_ID=<YOUR_CLIENT_ID> | ||
export AZURE_SUBSCRIPTION_ID=<YOUR_SUBSCRIPTION_ID> | ||
export AZURE_RESOURCE_GROUP_NAME=<YOUR_RESOURCE_GROUP_NAME> | ||
export AZURE_SECRET=<YOUR_SECRET> | ||
export AZURE_APP_SECRET=<YOUR_SECRET> | ||
export AZURE_KEY_VAULT_NAME=<YOUR_KEY_VAULT_NAME> | ||
export AZURE_KEY_IDENTIFIER=<YOUR_KEY_IDENTIFIER> | ||
export AZURE_TENANT_ID=<YOUR_TENANT_ID> | ||
export AZURE_DIRECTORY_ID=<YOUR_DIRECTORY_ID> | ||
|
||
export AZURE_CLIENT_ID_UPDATED=<YOUR_CLIENT_ID_UPDATED> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no longer being used |
||
export AZURE_RESOURCE_GROUP_NAME_UPDATED=<YOUR_RESOURCE_GROUP_NAME_UPDATED> | ||
export AZURE_SECRET_UPDATED=<YOUR_SECRET_UPDATED> | ||
export AZURE_KEY_VAULT_NAME_UPDATED=<YOUR_KEY_VAULT_NAME_UPDATED> | ||
export AZURE_KEY_IDENTIFIER_UPDATED=<YOUR_KEY_IDENTIFIER_UPDATED> | ||
``` | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,15 +3,17 @@ package encryptionatrest_test | |
import ( | ||
"fmt" | ||
"os" | ||
"strconv" | ||
"testing" | ||
|
||
"go.mongodb.org/atlas-sdk/v20240805003/admin" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-testing/plancheck" | ||
|
||
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" | ||
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" | ||
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/mig" | ||
"go.mongodb.org/atlas-sdk/v20240805003/admin" | ||
) | ||
|
||
func TestMigEncryptionAtRest_basicAWS(t *testing.T) { | ||
|
@@ -35,7 +37,7 @@ func TestMigEncryptionAtRest_basicAWS(t *testing.T) { | |
Steps: []resource.TestStep{ | ||
{ | ||
ExternalProviders: mig.ExternalProviders(), | ||
Config: testAccMongoDBAtlasEncryptionAtRestConfigAwsKms(projectID, &awsKms), | ||
Config: testAccMongoDBAtlasEncryptionAtRestConfigAwsKms(projectID, &awsKms, false), // not using data source as it was introduced in 1.19.0 | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
testAccCheckMongoDBAtlasEncryptionAtRestExists(resourceName), | ||
resource.TestCheckResourceAttr(resourceName, "project_id", projectID), | ||
|
@@ -46,7 +48,7 @@ func TestMigEncryptionAtRest_basicAWS(t *testing.T) { | |
}, | ||
{ | ||
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories, | ||
Config: testAccMongoDBAtlasEncryptionAtRestConfigAwsKms(projectID, &awsKms), | ||
Config: testAccMongoDBAtlasEncryptionAtRestConfigAwsKms(projectID, &awsKms, false), | ||
ConfigPlanChecks: resource.ConfigPlanChecks{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we better use mig.TestStepCheckEmptyPlan ? |
||
PreApply: []plancheck.PlanCheck{ | ||
acc.DebugPlan(), | ||
|
@@ -106,11 +108,9 @@ func TestMigEncryptionAtRest_withRole_basicAWS(t *testing.T) { | |
} | ||
|
||
func TestMigEncryptionAtRest_basicAzure(t *testing.T) { | ||
acc.SkipTestForCI(t) // needs Azure configuration | ||
|
||
var ( | ||
resourceName = "mongodbatlas_encryption_at_rest.test" | ||
projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") | ||
projectID = acc.ProjectIDExecution(t) | ||
|
||
azureKeyVault = admin.AzureKeyVault{ | ||
Enabled: conversion.Pointer(true), | ||
|
@@ -120,30 +120,38 @@ func TestMigEncryptionAtRest_basicAzure(t *testing.T) { | |
ResourceGroupName: conversion.StringPtr(os.Getenv("AZURE_RESOURCE_GROUP_NAME")), | ||
KeyVaultName: conversion.StringPtr(os.Getenv("AZURE_KEY_VAULT_NAME")), | ||
KeyIdentifier: conversion.StringPtr(os.Getenv("AZURE_KEY_IDENTIFIER")), | ||
Secret: conversion.StringPtr(os.Getenv("AZURE_SECRET")), | ||
Secret: conversion.StringPtr(os.Getenv("AZURE_APP_SECRET")), | ||
TenantID: conversion.StringPtr(os.Getenv("AZURE_TENANT_ID")), | ||
} | ||
|
||
attrMap = map[string]string{ | ||
"enabled": strconv.FormatBool(azureKeyVault.GetEnabled()), | ||
"azure_environment": azureKeyVault.GetAzureEnvironment(), | ||
"resource_group_name": azureKeyVault.GetResourceGroupName(), | ||
"key_vault_name": azureKeyVault.GetKeyVaultName(), | ||
"client_id": azureKeyVault.GetClientID(), | ||
"key_identifier": azureKeyVault.GetKeyIdentifier(), | ||
"subscription_id": azureKeyVault.GetSubscriptionID(), | ||
"tenant_id": azureKeyVault.GetTenantID(), | ||
} | ||
) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { mig.PreCheck(t); acc.PreCheckEncryptionAtRestEnvAzure(t) }, | ||
PreCheck: func() { mig.PreCheckBasic(t); acc.PreCheckEncryptionAtRestEnvAzure(t) }, | ||
CheckDestroy: testAccCheckMongoDBAtlasEncryptionAtRestDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
ExternalProviders: mig.ExternalProviders(), | ||
Config: acc.ConfigEARAzureKeyVault(projectID, &azureKeyVault, false), | ||
Config: acc.ConfigEARAzureKeyVault(projectID, &azureKeyVault, false, false), // not using data source as it was introduced in 1.19.0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. chose to not use data source for migration tests instead of skipping the tests for lower versions There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
Check: resource.ComposeAggregateTestCheckFunc( | ||
testAccCheckMongoDBAtlasEncryptionAtRestExists(resourceName), | ||
resource.TestCheckResourceAttr(resourceName, "project_id", projectID), | ||
resource.TestCheckResourceAttr(resourceName, "azure_key_vault_config.0.enabled", "true"), | ||
resource.TestCheckResourceAttr(resourceName, "azure_key_vault_config.0.azure_environment", azureKeyVault.GetAzureEnvironment()), | ||
resource.TestCheckResourceAttr(resourceName, "azure_key_vault_config.0.resource_group_name", azureKeyVault.GetResourceGroupName()), | ||
resource.TestCheckResourceAttr(resourceName, "azure_key_vault_config.0.key_vault_name", azureKeyVault.GetKeyVaultName()), | ||
testCheckResourceAttr(resourceName, "azure_key_vault_config.0", attrMap), | ||
), | ||
}, | ||
{ | ||
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories, | ||
Config: acc.ConfigEARAzureKeyVault(projectID, &azureKeyVault, false), | ||
Config: acc.ConfigEARAzureKeyVault(projectID, &azureKeyVault, false, false), | ||
ConfigPlanChecks: resource.ConfigPlanChecks{ | ||
PreApply: []plancheck.PlanCheck{ | ||
acc.DebugPlan(), | ||
|
@@ -175,16 +183,17 @@ func TestMigEncryptionAtRest_basicGCP(t *testing.T) { | |
Steps: []resource.TestStep{ | ||
{ | ||
ExternalProviders: mig.ExternalProviders(), | ||
Config: testAccMongoDBAtlasEncryptionAtRestConfigGoogleCloudKms(projectID, &googleCloudKms), | ||
Config: testAccMongoDBAtlasEncryptionAtRestConfigGoogleCloudKms(projectID, &googleCloudKms, false), // not using data source as it was introduced in 1.19.0 | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
testAccCheckMongoDBAtlasEncryptionAtRestExists(resourceName), | ||
resource.TestCheckResourceAttr(resourceName, "project_id", projectID), | ||
resource.TestCheckResourceAttr(resourceName, "google_cloud_kms_config.0.enabled", "true"), | ||
resource.TestCheckResourceAttrSet(resourceName, "google_cloud_kms_config.0.key_version_resource_id"), | ||
), | ||
}, | ||
{ | ||
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories, | ||
Config: testAccMongoDBAtlasEncryptionAtRestConfigGoogleCloudKms(projectID, &googleCloudKms), | ||
Config: testAccMongoDBAtlasEncryptionAtRestConfigGoogleCloudKms(projectID, &googleCloudKms, false), | ||
ConfigPlanChecks: resource.ConfigPlanChecks{ | ||
PreApply: []plancheck.PlanCheck{ | ||
acc.DebugPlan(), | ||
|
@@ -219,7 +228,7 @@ func TestMigEncryptionAtRest_basicAWS_from_v1_11_0(t *testing.T) { | |
Steps: []resource.TestStep{ | ||
{ | ||
ExternalProviders: acc.ExternalProvidersWithAWS("1.11.0"), | ||
Config: testAccMongoDBAtlasEncryptionAtRestConfigAwsKms(projectID, &awsKms), | ||
Config: testAccMongoDBAtlasEncryptionAtRestConfigAwsKms(projectID, &awsKms, false), // not using data source as it was introduced in 1.19.0 | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
testAccCheckMongoDBAtlasEncryptionAtRestExists(resourceName), | ||
resource.TestCheckResourceAttr(resourceName, "project_id", projectID), | ||
|
@@ -230,7 +239,7 @@ func TestMigEncryptionAtRest_basicAWS_from_v1_11_0(t *testing.T) { | |
}, | ||
{ | ||
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories, | ||
Config: testAccMongoDBAtlasEncryptionAtRestConfigAwsKms(projectID, &awsKms), | ||
Config: testAccMongoDBAtlasEncryptionAtRestConfigAwsKms(projectID, &awsKms, false), | ||
ConfigPlanChecks: resource.ConfigPlanChecks{ | ||
PreApply: []plancheck.PlanCheck{ | ||
acc.DebugPlan(), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we will likely need to create another project in QA with the FF enabled, after this adjustment we can to a run of the test group in QA to make sure we already support this correctly.