Skip to content

Commit

Permalink
INTMDB-879: [Terraform] Improve acceptance test setup to run in paral…
Browse files Browse the repository at this point in the history
…lel & against cloud-dev - Config (#1263)
  • Loading branch information
andreaangiolillo authored Jun 23, 2023
1 parent 7ad9c42 commit 0861142
Show file tree
Hide file tree
Showing 44 changed files with 713 additions and 720 deletions.
98 changes: 71 additions & 27 deletions .github/workflows/acceptance-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
project: ${{ steps.filter.outputs.project }}
serverless: ${{ steps.filter.outputs.serverless }}
network: ${{ steps.filter.outputs.network }}
config: ${{ steps.filter.outputs.config }}
steps:
- uses: actions/checkout@v3
if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule'}}
Expand Down Expand Up @@ -57,7 +58,20 @@ jobs:
network:
- 'mongodbatlas/**_network**.go'
- 'mongodbatlas/**_privatelink**.go'
- 'mongodbatlas/**_private_endpoint**.go'
- 'mongodbatlas/**_private_endpoint**.go'
config:
- 'mongodbatlas/**_accesslist**.go'
- 'mongodbatlas/**_alert_configuration**.go'
- 'mongodbatlas/**_api_key**.go'
- 'mongodbatlas/**_cloud_provider**.go'
- 'mongodbatlas/**_custom_**.go'
- 'mongodbatlas/**_database_user**.go'
- 'mongodbatlas/**_maintenance**.go'
- 'mongodbatlas/**_org_**.go'
- 'mongodbatlas/**_organization**.go'
- 'mongodbatlas/**_project**.go'
- 'mongodbatlas/**_search_**.go'
- 'mongodbatlas/**_team_**.go'
cluster_outage_simulation:
needs: [ change-detection ]
Expand Down Expand Up @@ -236,35 +250,37 @@ jobs:
TF_LOG: ${{ vars.LOG_LEVEL }}
TF_ACC: 1
PARALLEL_GO_TEST: 20
CI: true
TEST_REGEX: "^TestAccBackupRSCloudBackupSchedule"
run: make testacc
project:
needs: [ change-detection ]
if: ${{ needs.change-detection.outputs.project == 'true' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.20"
- name: Acceptance Tests
env:
MONGODB_ATLAS_PUBLIC_KEY: ${{ secrets.MONGODB_ATLAS_PUBLIC_KEY_CLOUD_DEV }}
MONGODB_ATLAS_PRIVATE_KEY: ${{ secrets.MONGODB_ATLAS_PRIVATE_KEY_CLOUD_DEV }}
MONGODB_ATLAS_ORG_ID: ${{ vars.MONGODB_ATLAS_ORG_ID_CLOUD_DEV }}
MONGODB_ATLAS_BASE_URL: ${{ vars.MONGODB_ATLAS_BASE_URL }}
MONGODB_ATLAS_PROJECT_OWNER_ID: ${{ vars.MONGODB_ATLAS_PROJECT_OWNER_ID }}
MONGODB_ATLAS_API_KEYS_IDS: ${{ vars.MONGODB_ATLAS_API_KEYS_IDS }}
MONGODB_ATLAS_TEAMS_IDS: ${{ vars.MONGODB_ATLAS_TEAMS_IDS }}
SKIP_TEST_EXTERNAL_CREDENTIALS: ${{ vars.SKIP_TEST_EXTERNAL_CREDENTIALS }}
ACCTEST_TIMEOUT: ${{ vars.ACCTEST_TIMEOUT }}
TF_LOG: ${{ vars.LOG_LEVEL }}
TF_ACC: 1
PARALLEL_GO_TEST: 20
TEST_REGEX: "^TestAccProject"
run: make testacc
needs: [ change-detection ]
if: ${{ needs.change-detection.outputs.project == 'true' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.20"
- name: Acceptance Tests
env:
MONGODB_ATLAS_PUBLIC_KEY: ${{ secrets.MONGODB_ATLAS_PUBLIC_KEY_CLOUD_DEV }}
MONGODB_ATLAS_PRIVATE_KEY: ${{ secrets.MONGODB_ATLAS_PRIVATE_KEY_CLOUD_DEV }}
MONGODB_ATLAS_ORG_ID: ${{ vars.MONGODB_ATLAS_ORG_ID_CLOUD_DEV }}
MONGODB_ATLAS_BASE_URL: ${{ vars.MONGODB_ATLAS_BASE_URL }}
MONGODB_ATLAS_PROJECT_OWNER_ID: ${{ vars.MONGODB_ATLAS_PROJECT_OWNER_ID }}
MONGODB_ATLAS_API_KEYS_IDS: ${{ vars.MONGODB_ATLAS_API_KEYS_IDS }}
MONGODB_ATLAS_TEAMS_IDS: ${{ vars.MONGODB_ATLAS_TEAMS_IDS }}
SKIP_TEST_EXTERNAL_CREDENTIALS: ${{ vars.SKIP_TEST_EXTERNAL_CREDENTIALS }}
ACCTEST_TIMEOUT: ${{ vars.ACCTEST_TIMEOUT }}
TF_LOG: ${{ vars.LOG_LEVEL }}
TF_ACC: 1
PARALLEL_GO_TEST: 20
CI: true
TEST_REGEX: "^TestAccProject"
run: make testacc
serverless:
needs: [ change-detection ]
if: ${{ needs.change-detection.outputs.serverless == 'true' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' }}
Expand All @@ -287,6 +303,7 @@ jobs:
TF_LOG: ${{ vars.LOG_LEVEL }}
TF_ACC: 1
PARALLEL_GO_TEST: 20
CI: true
TEST_REGEX: "^TestAccServerless"
run: make testacc
network:
Expand Down Expand Up @@ -315,5 +332,32 @@ jobs:
TF_LOG: ${{ vars.LOG_LEVEL }}
TF_ACC: 1
PARALLEL_GO_TEST: 20
CI: true
TEST_REGEX: "^TestAccNetwork"
run: make testacc
config:
needs: [ change-detection ]
if: ${{ needs.change-detection.outputs.config == 'true' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.20"
- name: Acceptance Tests
env:
MONGODB_ATLAS_PUBLIC_KEY: ${{ secrets.MONGODB_ATLAS_PUBLIC_KEY_CLOUD_DEV_NETWORK }}
MONGODB_ATLAS_PRIVATE_KEY: ${{ secrets.MONGODB_ATLAS_PRIVATE_KEY_CLOUD_DEV_NETWORK }}
MONGODB_ATLAS_ORG_ID: ${{ vars.MONGODB_ATLAS_ORG_ID_CLOUD_DEV_NETWORK }}
MONGODB_ATLAS_BASE_URL: ${{ vars.MONGODB_ATLAS_BASE_URL }}
SKIP_TEST_EXTERNAL_CREDENTIALS: ${{ vars.SKIP_TEST_EXTERNAL_CREDENTIALS }}
MONGODB_ATLAS_USERNAME_CLOUD_DEV: ${{ vars.MONGODB_ATLAS_USERNAME_CLOUD_DEV }}
ACCTEST_TIMEOUT: ${{ vars.ACCTEST_TIMEOUT }}
TF_LOG: ${{ vars.LOG_LEVEL }}
TF_ACC: 1
PARALLEL_GO_TEST: 20
CI: true
TEST_REGEX: "^TestAccConfig"
run: make testacc
31 changes: 1 addition & 30 deletions .github/workflows/automated-test-acceptances.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,36 +55,6 @@ jobs:
TEST_REGEX: "^TestAccAdv"
run: make testacc

acceptance-tests-config:
if: ${{ github.event.label.name == 'run-testacc' || github.event.label.name == 'run-testacc-project-config' || github.ref == 'refs/heads/master' }}
needs: [ authorize ]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.20"
- name: Acceptance Tests
env:
MONGODB_ATLAS_PUBLIC_KEY: ${{ secrets.MONGODB_ATLAS_PUBLIC_KEY }}
MONGODB_ATLAS_PRIVATE_KEY: ${{ secrets.MONGODB_ATLAS_PRIVATE_KEY }}
MONGODB_ATLAS_PROJECT_ID: ${{ secrets.MONGODB_ATLAS_PROJECT_ID }}
MONGODB_ATLAS_ORG_ID: ${{ secrets.MONGODB_ATLAS_ORG_ID }}
MONGODB_ATLAS_DB_USERNAME: ${{ secrets.MONGODB_ATLAS_DB_USERNAME }}
MONGODB_ATLAS_TEAMS_IDS: ${{ secrets.MONGODB_ATLAS_TEAMS_IDS }}
CA_CERT: ${{ secrets.CA_CERT }}
MONGODB_ATLAS_API_KEYS_IDS: ${{ secrets.MONGODB_ATLAS_API_KEYS_IDS }}
MONGODB_ATLAS_NETWORK_PROJECT_ID: ${{ secrets.MONGODB_ATLAS_NETWORK_PROJECT_ID }}
SKIP_TEST_EXTERNAL_CREDENTIALS: ${{ vars.SKIP_TEST_EXTERNAL_CREDENTIALS }}
SKIP_TEST: ${{ vars.SKIP_TEST }}
AWS_REGION: ${{ vars.AWS_REGION }}
MONGODB_ATLAS_ENABLE_BETA: ${{ vars.MONGODB_ATLAS_ENABLE_BETA }}
ACCTEST_TIMEOUT: ${{ vars.ACCTEST_TIMEOUT }}
TEST_REGEX: "^TestAccConfig"
run: make testacc

acceptance-tests-gov:
if: ${{ github.event.label.name == 'run-testacc-gov' }}
needs: [ authorize ]
Expand All @@ -107,6 +77,7 @@ jobs:
CA_CERT: ${{ secrets.CA_CERT }}
MONGODB_ATLAS_API_KEYS_IDS: ${{ secrets.MONGODB_ATLAS_API_KEYS_IDS }}
MONGODB_ATLAS_PROJECT_OWNER_ID_GOV: ${{ secrets.MONGODB_ATLAS_PROJECT_OWNER_ID_GOV }}
MONGODB_ATLAS_USERNAME_CLOUD_DEV: ${{ vars.MONGODB_ATLAS_USERNAME_CLOUD_DEV }}
SKIP_TEST_EXTERNAL_CREDENTIALS: ${{ vars.SKIP_TEST_EXTERNAL_CREDENTIALS }}
SKIP_TEST: ${{ vars.SKIP_TEST }}
AWS_REGION: ${{ vars.AWS_REGION_GOV }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ func TestAccConfigDSAccesslistAPIKey_basic(t *testing.T) {
description := fmt.Sprintf("test-acc-accesslist-api_key-%s", acctest.RandString(5))
ipAddress := fmt.Sprintf("179.154.226.%d", acctest.RandIntRange(0, 255))

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheckBasic(t) },
ProviderFactories: testAccProviderFactories,
//CheckDestroy: testAccCheckMongoDBAtlasNetworkPeeringDestroy,
CheckDestroy: testAccCheckMongoDBAtlasAccessListAPIKeyDestroy,
Steps: []resource.TestStep{
{
Config: testAccDSMongoDBAtlasAccesslistAPIKeyConfig(orgID, description, ipAddress),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ func TestAccConfigDSAccesslistAPIKeys_basic(t *testing.T) {
description := fmt.Sprintf("test-acc-accesslist-api_keys-%s", acctest.RandString(5))
ipAddress := fmt.Sprintf("179.154.226.%d", acctest.RandIntRange(0, 255))

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheckBasic(t) },
ProviderFactories: testAccProviderFactories,
//CheckDestroy: testAccCheckMongoDBAtlasNetworkPeeringDestroy,
CheckDestroy: testAccCheckMongoDBAtlasAccessListAPIKeyDestroy,
Steps: []resource.TestStep{
{
Config: testAccDSMongoDBAtlasAccesslistAPIKeysConfig(orgID, description, ipAddress),
Expand Down
43 changes: 27 additions & 16 deletions mongodbatlas/data_source_mongodbatlas_alert_configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
matlas "go.mongodb.org/atlas/mongodbatlas"
)
Expand All @@ -13,16 +14,17 @@ func TestAccConfigDSAlertConfiguration_basic(t *testing.T) {
var (
alert = &matlas.AlertConfiguration{}
dataSourceName = "data.mongodbatlas_alert_configuration.test"
projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID")
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acctest.RandomWithPrefix("test-acc")
)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheckBasic(t) },
ProviderFactories: testAccProviderFactories,
CheckDestroy: testAccCheckMongoDBAtlasAlertConfigurationDestroy,
Steps: []resource.TestStep{
{
Config: testAccDSMongoDBAtlasAlertConfiguration(projectID),
Config: testAccDSMongoDBAtlasAlertConfiguration(orgID, projectName),
Check: resource.ComposeTestCheckFunc(
testAccCheckMongoDBAtlasAlertConfigurationExists(dataSourceName, alert),
resource.TestCheckResourceAttrSet(dataSourceName, "project_id"),
Expand All @@ -36,16 +38,17 @@ func TestAccConfigDSAlertConfiguration_withThreshold(t *testing.T) {
var (
alert = &matlas.AlertConfiguration{}
dataSourceName = "data.mongodbatlas_alert_configuration.test"
projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID")
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acctest.RandomWithPrefix("test-acc")
)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheckBasic(t) },
ProviderFactories: testAccProviderFactories,
CheckDestroy: testAccCheckMongoDBAtlasAlertConfigurationDestroy,
Steps: []resource.TestStep{
{
Config: testAccDSMongoDBAtlasAlertConfigurationConfigWithThreshold(projectID, true, 1),
Config: testAccDSMongoDBAtlasAlertConfigurationConfigWithThreshold(orgID, projectName, true, 1),
Check: resource.ComposeTestCheckFunc(
testAccCheckMongoDBAtlasAlertConfigurationExists(dataSourceName, alert),
resource.TestCheckResourceAttrSet(dataSourceName, "project_id"),
Expand Down Expand Up @@ -80,10 +83,14 @@ func TestAccConfigDSAlertConfiguration_withPagerDuty(t *testing.T) {
})
}

func testAccDSMongoDBAtlasAlertConfiguration(projectID string) string {
func testAccDSMongoDBAtlasAlertConfiguration(orgID, projectName string) string {
return fmt.Sprintf(`
resource "mongodbatlas_project" "test" {
name = %[2]q
org_id = %[1]q
}
resource "mongodbatlas_alert_configuration" "test" {
project_id = "%s"
project_id = mongodbatlas_project.test.id
event_type = "OUTSIDE_METRIC_THRESHOLD"
enabled = true
Expand Down Expand Up @@ -114,15 +121,19 @@ func testAccDSMongoDBAtlasAlertConfiguration(projectID string) string {
project_id = "${mongodbatlas_alert_configuration.test.project_id}"
alert_configuration_id = "${mongodbatlas_alert_configuration.test.id}"
}
`, projectID)
`, orgID, projectName)
}

func testAccDSMongoDBAtlasAlertConfigurationConfigWithThreshold(projectID string, enabled bool, threshold float64) string {
func testAccDSMongoDBAtlasAlertConfigurationConfigWithThreshold(orgID, projectName string, enabled bool, threshold float64) string {
return fmt.Sprintf(`
resource "mongodbatlas_project" "test" {
name = %[2]q
org_id = %[1]q
}
resource "mongodbatlas_alert_configuration" "test" {
project_id = "%s"
project_id = mongodbatlas_project.test.id
event_type = "REPLICATION_OPLOG_WINDOW_RUNNING_OUT"
enabled = "%t"
enabled = "%[3]t"
notification {
type_name = "GROUP"
Expand All @@ -142,15 +153,15 @@ func testAccDSMongoDBAtlasAlertConfigurationConfigWithThreshold(projectID string
threshold_config {
operator = "LESS_THAN"
units = "HOURS"
threshold = %f
threshold = %[4]f
}
}
data "mongodbatlas_alert_configuration" "test" {
project_id = "${mongodbatlas_alert_configuration.test.project_id}"
alert_configuration_id = "${mongodbatlas_alert_configuration.test.id}"
}
`, projectID, enabled, threshold)
`, orgID, projectName, enabled, threshold)
}

func testAccDSMongoDBAtlasAlertConfigurationConfigWithPagerDuty(projectID, serviceKey string, enabled bool) string {
Expand Down
20 changes: 13 additions & 7 deletions mongodbatlas/data_source_mongodbatlas_alert_configurations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strconv"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
matlas "go.mongodb.org/atlas/mongodbatlas"
Expand All @@ -15,15 +16,16 @@ import (
func TestAccConfigDSAlertConfigurations_basic(t *testing.T) {
var (
dataSourceName = "data.mongodbatlas_alert_configurations.test"
projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID")
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acctest.RandomWithPrefix("test-acc")
)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheckBasic(t) },
ProviderFactories: testAccProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccDSMongoDBAtlasAlertConfigurations(projectID),
Config: testAccDSMongoDBAtlasAlertConfigurations(orgID, projectName),
Check: resource.ComposeTestCheckFunc(
testAccCheckMongoDBAtlasAlertConfigurationsCount(dataSourceName),
resource.TestCheckResourceAttrSet(dataSourceName, "project_id"),
Expand All @@ -33,16 +35,20 @@ func TestAccConfigDSAlertConfigurations_basic(t *testing.T) {
})
}

func testAccDSMongoDBAtlasAlertConfigurations(projectID string) string {
func testAccDSMongoDBAtlasAlertConfigurations(orgID, projectName string) string {
return fmt.Sprintf(`
resource "mongodbatlas_project" "test" {
name = %[2]q
org_id = %[1]q
}
data "mongodbatlas_alert_configurations" "test" {
project_id = "%s"
project_id = mongodbatlas_project.test.id
list_options {
page_num = 0
}
}
`, projectID)
`, orgID, projectName)
}

func testAccCheckMongoDBAtlasAlertConfigurationsCount(resourceName string) resource.TestCheckFunc {
Expand Down
6 changes: 3 additions & 3 deletions mongodbatlas/data_source_mongodbatlas_api_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ func TestAccConfigDSAPIKey_basic(t *testing.T) {
description := fmt.Sprintf("test-acc-api_key-%s", acctest.RandString(5))
roleName := "ORG_MEMBER"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheckBasic(t) },
ProviderFactories: testAccProviderFactories,
//CheckDestroy: testAccCheckMongoDBAtlasNetworkPeeringDestroy,
CheckDestroy: testAccCheckMongoDBAtlasAPIKeyDestroy,
Steps: []resource.TestStep{
{
Config: testAccDSMongoDBAtlasAPIKeyConfig(orgID, description, roleName),
Expand Down
6 changes: 3 additions & 3 deletions mongodbatlas/data_source_mongodbatlas_api_keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ func TestAccConfigDSAPIKeys_basic(t *testing.T) {
description := fmt.Sprintf("test-acc-api_key-%s", acctest.RandString(5))
roleName := "ORG_MEMBER"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheckBasic(t) },
ProviderFactories: testAccProviderFactories,
//CheckDestroy: testAccCheckMongoDBAtlasNetworkPeeringDestroy,
CheckDestroy: testAccCheckMongoDBAtlasAPIKeyDestroy,
Steps: []resource.TestStep{
{
Config: testAccDSMongoDBAtlasAPIKeysConfig(orgID, description, roleName),
Expand Down
Loading

0 comments on commit 0861142

Please sign in to comment.