Skip to content

Commit c3ff8a0

Browse files
authored
feat: Updates migration tests to run separately and use last released version of provider for plan checks (#1565)
1 parent 7ba7282 commit c3ff8a0

9 files changed

+423
-169
lines changed

.github/workflows/code-health.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ jobs:
8888
- uses: actions/checkout@v4
8989
- name: Run ShellCheck
9090
uses: bewuethr/shellcheck-action@v2
91-
call-accettance-tests-workflow:
91+
call-acceptance-tests-workflow:
9292
needs: [build, lint, shellcheck, unit-test, website-lint]
9393
secrets: inherit
9494
permissions:
@@ -98,4 +98,14 @@ jobs:
9898
uses: ./.github/workflows/acceptance-tests.yml
9999
with:
100100
parent-event-name: ${{ github.event_name }}
101+
call-migration-tests-workflow:
102+
needs: [build, lint, shellcheck, unit-test, website-lint]
103+
secrets: inherit
104+
permissions:
105+
contents: write
106+
pull-requests: read
107+
repository-projects: read
108+
uses: ./.github/workflows/migration-tests.yml
109+
with:
110+
parent-event-name: ${{ github.event_name }}
101111

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
name: 'Migration Tests'
2+
3+
on:
4+
workflow_dispatch: {}
5+
workflow_call: # workflow runs after code-health
6+
inputs:
7+
parent-event-name:
8+
required: true
9+
type: string
10+
pull_request:
11+
types: [ labeled ]
12+
13+
jobs:
14+
set-output:
15+
runs-on: ubuntu-latest
16+
outputs:
17+
condition: ${{ steps.set-condition.outputs.condition }}
18+
steps:
19+
- name: Set Event Condition
20+
id: set-condition
21+
run: |
22+
if [ "${{ github.event_name }}" = "push" ] || [ "${{ github.event_name }}" = "workflow_dispatch" ] || [ "${{ github.event_name }}" = "schedule" ] || [ "${{ inputs.parent-event-name }}" = "release" ] || [ "${{ github.event.label.name }}" = "run-testacc-migration" ]; then
23+
echo "::set-output name=condition::true"
24+
else
25+
echo "::set-output name=condition::false"
26+
fi
27+
change-detection:
28+
runs-on: ubuntu-latest
29+
permissions:
30+
pull-requests: read
31+
repository-projects: read
32+
outputs:
33+
project: ${{ steps.filter.outputs.project }}
34+
config: ${{ steps.filter.outputs.config }}
35+
steps:
36+
- uses: actions/checkout@v4
37+
if: ${{ needs.set-output.outputs.condition == 'true' }}
38+
- uses: dorny/paths-filter@v2
39+
id: filter
40+
with:
41+
filters: |
42+
project:
43+
- 'mongodbatlas/fw_data_source_mongodbatlas_project_ip_access_list*.go'
44+
- 'mongodbatlas/fw_resource_mongodbatlas_project_ip_access_list*.go'
45+
config:
46+
- 'mongodbatlas/fw_data_source_mongodbatlas_alert_configuration*.go'
47+
- 'mongodbatlas/fw_data_source_mongodbatlas_database_user*.go'
48+
- 'mongodbatlas/fw_data_source_mongodbatlas_atlas_user*.go'
49+
- 'mongodbatlas/fw_resource_mongodbatlas_alert_configuration*.go'
50+
- 'mongodbatlas/fw_resource_mongodbatlas_database_user*.go'
51+
52+
project:
53+
needs: [ change-detection ]
54+
if: ${{ needs.set-output.outputs.condition == 'true' || needs.change-detection.outputs.project == 'true' || github.event.label.name == 'run-testacc-project-migration'}}
55+
runs-on: ubuntu-latest
56+
steps:
57+
- name: Checkout
58+
uses: actions/checkout@v4
59+
- name: Get Last Release
60+
id: get_last_release
61+
run: |
62+
LAST_RELEASE=$(curl -sSfL -X GET https://api.github.com/repos/mongodb/terraform-provider-mongodbatlas/releases/latest | jq -r '.tag_name | ltrimstr("v")')
63+
echo "Last release: $LAST_RELEASE"
64+
echo "MONGODB_ATLAS_LAST_VERSION=$LAST_RELEASE" >> $GITHUB_ENV
65+
shell: bash
66+
- name: Set up Go
67+
uses: actions/setup-go@v4
68+
with:
69+
go-version-file: 'go.mod'
70+
- name: Migration Tests
71+
env:
72+
MONGODB_ATLAS_PUBLIC_KEY: ${{ secrets.MONGODB_ATLAS_PUBLIC_KEY_CLOUD_DEV }}
73+
MONGODB_ATLAS_PRIVATE_KEY: ${{ secrets.MONGODB_ATLAS_PRIVATE_KEY_CLOUD_DEV }}
74+
MONGODB_ATLAS_ORG_ID: ${{ vars.MONGODB_ATLAS_ORG_ID_CLOUD_DEV }}
75+
MONGODB_ATLAS_BASE_URL: ${{ vars.MONGODB_ATLAS_BASE_URL }}
76+
MONGODB_ATLAS_PROJECT_OWNER_ID: ${{ vars.MONGODB_ATLAS_PROJECT_OWNER_ID }}
77+
MONGODB_ATLAS_API_KEYS_IDS: ${{ vars.MONGODB_ATLAS_API_KEYS_IDS }}
78+
MONGODB_ATLAS_TEAMS_IDS: ${{ vars.MONGODB_ATLAS_TEAMS_IDS }}
79+
SKIP_TEST_EXTERNAL_CREDENTIALS: ${{ vars.SKIP_TEST_EXTERNAL_CREDENTIALS }}
80+
ACCTEST_TIMEOUT: ${{ vars.ACCTEST_TIMEOUT }}
81+
TF_LOG: ${{ vars.LOG_LEVEL }}
82+
TF_ACC: 1
83+
PARALLEL_GO_TEST: 20
84+
CI: true
85+
TEST_REGEX: "^TestAccMigrationProject"
86+
run: make testacc
87+
88+
config:
89+
needs: [ change-detection ]
90+
if: ${{ needs.set-output.outputs.condition == 'true' || needs.change-detection.outputs.config == 'true' || github.event.label.name == 'run-testacc-config-migration'}}
91+
runs-on: ubuntu-latest
92+
steps:
93+
- name: Checkout
94+
uses: actions/checkout@v4
95+
- name: Get Last Release
96+
id: get_last_release
97+
run: |
98+
LAST_RELEASE=$(curl -sSfL -X GET https://api.github.com/repos/mongodb/terraform-provider-mongodbatlas/releases/latest | jq -r '.tag_name | ltrimstr("v")')
99+
echo "Last release: $LAST_RELEASE"
100+
echo "MONGODB_ATLAS_LAST_VERSION=$LAST_RELEASE" >> $GITHUB_ENV
101+
shell: bash
102+
- name: Set up Go
103+
uses: actions/setup-go@v4
104+
with:
105+
go-version-file: 'go.mod'
106+
- name: Migration Tests
107+
env:
108+
MONGODB_ATLAS_PUBLIC_KEY: ${{ secrets.MONGODB_ATLAS_PUBLIC_KEY_CLOUD_DEV_NETWORK }}
109+
MONGODB_ATLAS_PRIVATE_KEY: ${{ secrets.MONGODB_ATLAS_PRIVATE_KEY_CLOUD_DEV_NETWORK }}
110+
MONGODB_ATLAS_ORG_ID: ${{ vars.MONGODB_ATLAS_ORG_ID_CLOUD_DEV_NETWORK }}
111+
MONGODB_ATLAS_BASE_URL: ${{ vars.MONGODB_ATLAS_BASE_URL }}
112+
MONGODB_ATLAS_PROJECT_OWNER_ID: ${{ vars.MONGODB_ATLAS_PROJECT_OWNER_ID }}
113+
SKIP_TEST_EXTERNAL_CREDENTIALS: ${{ vars.SKIP_TEST_EXTERNAL_CREDENTIALS }}
114+
MONGODB_ATLAS_USERNAME_CLOUD_DEV: ${{ vars.MONGODB_ATLAS_USERNAME_CLOUD_DEV }}
115+
AZURE_ATLAS_APP_ID: ${{vars.AZURE_ATLAS_APP_ID}}
116+
AZURE_SERVICE_PRINCIPAL_ID: ${{vars.AZURE_SERVICE_PRINCIPAL_ID}}
117+
AZURE_TENANT_ID: ${{vars.AZURE_TENANT_ID}}
118+
ACCTEST_TIMEOUT: ${{ vars.ACCTEST_TIMEOUT }}
119+
TF_LOG: ${{ vars.LOG_LEVEL }}
120+
TF_ACC: 1
121+
PARALLEL_GO_TEST: 20
122+
CI: true
123+
TEST_REGEX: "^TestAccMigrationConfig"
124+
run: make testacc

mongodbatlas/fw_data_source_mongodbatlas_project_ip_access_list_migration_test.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,21 @@ import (
1010
"github.com/hashicorp/terraform-plugin-testing/plancheck"
1111
)
1212

13-
func TestAccProjectDSProjectIPAccessList_Migration_SettingIPAddress(t *testing.T) {
13+
func TestAccMigrationProjectDSProjectIPAccessList_SettingIPAddress(t *testing.T) {
1414
dataSourceName := "data.mongodbatlas_project_ip_access_list.test"
1515
orgID := os.Getenv("MONGODB_ATLAS_ORG_ID")
1616
projectName := acctest.RandomWithPrefix("test-acc")
1717
ipAddress := fmt.Sprintf("179.154.226.%d", acctest.RandIntRange(0, 255))
1818
comment := fmt.Sprintf("TestAcc for ipAddress (%s)", ipAddress)
19+
lastVersionConstraint := os.Getenv("MONGODB_ATLAS_LAST_VERSION")
1920

2021
resource.Test(t, resource.TestCase{
21-
PreCheck: func() { testAccPreCheckBasic(t) },
22+
PreCheck: func() { testAccMigrationPreCheckBasic(t) },
2223
Steps: []resource.TestStep{
2324
{
2425
ExternalProviders: map[string]resource.ExternalProvider{
2526
"mongodbatlas": {
26-
VersionConstraint: "1.11.0",
27+
VersionConstraint: lastVersionConstraint,
2728
Source: "mongodb/mongodbatlas",
2829
},
2930
},
@@ -50,20 +51,21 @@ func TestAccProjectDSProjectIPAccessList_Migration_SettingIPAddress(t *testing.T
5051
})
5152
}
5253

53-
func TestAccProjectDSProjectIPAccessList_Migration_SettingCIDRBlock(t *testing.T) {
54+
func TestAccMigrationProjectDSProjectIPAccessList_SettingCIDRBlock(t *testing.T) {
5455
dataSourceName := "data.mongodbatlas_project_ip_access_list.test"
5556
orgID := os.Getenv("MONGODB_ATLAS_ORG_ID")
5657
projectName := acctest.RandomWithPrefix("test-acc")
5758
cidrBlock := fmt.Sprintf("179.154.226.%d/32", acctest.RandIntRange(0, 255))
5859
comment := fmt.Sprintf("TestAcc for cidrBlock (%s)", cidrBlock)
60+
lastVersionConstraint := os.Getenv("MONGODB_ATLAS_LAST_VERSION")
5961

6062
resource.Test(t, resource.TestCase{
61-
PreCheck: func() { testAccPreCheckBasic(t) },
63+
PreCheck: func() { testAccMigrationPreCheckBasic(t) },
6264
Steps: []resource.TestStep{
6365
{
6466
ExternalProviders: map[string]resource.ExternalProvider{
6567
"mongodbatlas": {
66-
VersionConstraint: "1.11.0",
68+
VersionConstraint: lastVersionConstraint,
6769
Source: "mongodb/mongodbatlas",
6870
},
6971
},
@@ -90,7 +92,7 @@ func TestAccProjectDSProjectIPAccessList_Migration_SettingCIDRBlock(t *testing.T
9092
})
9193
}
9294

93-
func TestAccProjectDSProjectIPAccessList_Migration_SettingAWSSecurityGroup(t *testing.T) {
95+
func TestAccMigrationProjectDSProjectIPAccessList_SettingAWSSecurityGroup(t *testing.T) {
9496
SkipTestExtCred(t)
9597
dataSourceName := "data.mongodbatlas_project_ip_access_list.test"
9698
vpcID := os.Getenv("AWS_VPC_ID")
@@ -102,14 +104,15 @@ func TestAccProjectDSProjectIPAccessList_Migration_SettingAWSSecurityGroup(t *te
102104
projectID := os.Getenv("MONGODB_ATLAS_PROJECT_ID")
103105
awsSGroup := os.Getenv("AWS_SECURITY_GROUP_ID")
104106
comment := fmt.Sprintf("TestAcc for awsSecurityGroup (%s)", awsSGroup)
107+
lastVersionConstraint := os.Getenv("MONGODB_ATLAS_LAST_VERSION")
105108

106109
resource.Test(t, resource.TestCase{
107110
PreCheck: func() { testAccPreCheck(t) },
108111
Steps: []resource.TestStep{
109112
{
110113
ExternalProviders: map[string]resource.ExternalProvider{
111114
"mongodbatlas": {
112-
VersionConstraint: "1.11.0",
115+
VersionConstraint: lastVersionConstraint,
113116
Source: "mongodb/mongodbatlas",
114117
},
115118
},

mongodbatlas/fw_resource_mongodbatlas_alert_configuration_migration_test.go

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,31 @@ import (
55
"os"
66
"testing"
77

8+
matlas "go.mongodb.org/atlas/mongodbatlas"
9+
810
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
911
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
1012
"github.com/hashicorp/terraform-plugin-testing/plancheck"
11-
matlas "go.mongodb.org/atlas/mongodbatlas"
1213
)
1314

14-
func TestAccConfigRSAlertConfiguration_Migration_NotificationsWithMetricThreshold(t *testing.T) {
15+
func TestAccMigrationConfigRSAlertConfiguration_NotificationsWithMetricThreshold(t *testing.T) {
1516
var (
16-
resourceName = "mongodbatlas_alert_configuration.test"
17-
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
18-
projectName = acctest.RandomWithPrefix("test-acc")
19-
alert = &matlas.AlertConfiguration{}
20-
config = testAccMongoDBAtlasAlertConfigurationConfig(orgID, projectName, true)
17+
resourceName = "mongodbatlas_alert_configuration.test"
18+
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
19+
projectName = acctest.RandomWithPrefix("test-acc")
20+
alert = &matlas.AlertConfiguration{}
21+
config = testAccMongoDBAtlasAlertConfigurationConfig(orgID, projectName, true)
22+
lastVersionConstraint = os.Getenv("MONGODB_ATLAS_LAST_VERSION")
2123
)
2224

2325
resource.ParallelTest(t, resource.TestCase{
24-
PreCheck: func() { testAccPreCheckBasic(t) },
26+
PreCheck: func() { testAccMigrationPreCheckBasic(t) },
2527
CheckDestroy: testAccCheckMongoDBAtlasAlertConfigurationDestroy,
2628
Steps: []resource.TestStep{
2729
{
2830
ExternalProviders: map[string]resource.ExternalProvider{
2931
"mongodbatlas": {
30-
VersionConstraint: "1.11.0",
32+
VersionConstraint: lastVersionConstraint,
3133
Source: "mongodb/mongodbatlas",
3234
},
3335
},
@@ -52,23 +54,24 @@ func TestAccConfigRSAlertConfiguration_Migration_NotificationsWithMetricThreshol
5254
})
5355
}
5456

55-
func TestAccConfigRSAlertConfiguration_Migration_WithThreshold(t *testing.T) {
57+
func TestAccMigrationConfigRSAlertConfiguration_WithThreshold(t *testing.T) {
5658
var (
57-
resourceName = "mongodbatlas_alert_configuration.test"
58-
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
59-
projectName = acctest.RandomWithPrefix("test-acc")
60-
alert = &matlas.AlertConfiguration{}
61-
config = testAccMongoDBAtlasAlertConfigurationConfigWithThresholdUpdated(orgID, projectName, true, 1)
59+
resourceName = "mongodbatlas_alert_configuration.test"
60+
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
61+
projectName = acctest.RandomWithPrefix("test-acc")
62+
alert = &matlas.AlertConfiguration{}
63+
config = testAccMongoDBAtlasAlertConfigurationConfigWithThresholdUpdated(orgID, projectName, true, 1)
64+
lastVersionConstraint = os.Getenv("MONGODB_ATLAS_LAST_VERSION")
6265
)
6366

6467
resource.ParallelTest(t, resource.TestCase{
65-
PreCheck: func() { testAccPreCheckBasic(t) },
68+
PreCheck: func() { testAccMigrationPreCheckBasic(t) },
6669
CheckDestroy: testAccCheckMongoDBAtlasAlertConfigurationDestroy,
6770
Steps: []resource.TestStep{
6871
{
6972
ExternalProviders: map[string]resource.ExternalProvider{
7073
"mongodbatlas": {
71-
VersionConstraint: "1.11.0",
74+
VersionConstraint: lastVersionConstraint,
7275
Source: "mongodb/mongodbatlas",
7376
},
7477
},
@@ -95,23 +98,24 @@ func TestAccConfigRSAlertConfiguration_Migration_WithThreshold(t *testing.T) {
9598
})
9699
}
97100

98-
func TestAccConfigRSAlertConfiguration_Migration_EmptyOptionalBlocks(t *testing.T) {
101+
func TestAccMigrationConfigRSAlertConfiguration_EmptyOptionalBlocks(t *testing.T) {
99102
var (
100-
resourceName = "mongodbatlas_alert_configuration.test"
101-
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
102-
projectName = acctest.RandomWithPrefix("test-acc")
103-
alert = &matlas.AlertConfiguration{}
104-
config = testAccMongoDBAtlasAlertConfigurationConfigEmptyOptionalBlocks(orgID, projectName)
103+
resourceName = "mongodbatlas_alert_configuration.test"
104+
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
105+
projectName = acctest.RandomWithPrefix("test-acc")
106+
alert = &matlas.AlertConfiguration{}
107+
config = testAccMongoDBAtlasAlertConfigurationConfigEmptyOptionalBlocks(orgID, projectName)
108+
lastVersionConstraint = os.Getenv("MONGODB_ATLAS_LAST_VERSION")
105109
)
106110

107111
resource.ParallelTest(t, resource.TestCase{
108-
PreCheck: func() { testAccPreCheckBasic(t) },
112+
PreCheck: func() { testAccMigrationPreCheckBasic(t) },
109113
CheckDestroy: testAccCheckMongoDBAtlasAlertConfigurationDestroy,
110114
Steps: []resource.TestStep{
111115
{
112116
ExternalProviders: map[string]resource.ExternalProvider{
113117
"mongodbatlas": {
114-
VersionConstraint: "1.11.0",
118+
VersionConstraint: lastVersionConstraint,
115119
Source: "mongodb/mongodbatlas",
116120
},
117121
},
@@ -139,7 +143,7 @@ func TestAccConfigRSAlertConfiguration_Migration_EmptyOptionalBlocks(t *testing.
139143
})
140144
}
141145

142-
func TestAccConfigRSAlertConfiguration_Migration_MultipleMatchers(t *testing.T) {
146+
func TestAccMigrationConfigRSAlertConfiguration_MultipleMatchers(t *testing.T) {
143147
var (
144148
resourceName = "mongodbatlas_alert_configuration.test"
145149
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
@@ -156,16 +160,17 @@ func TestAccConfigRSAlertConfiguration_Migration_MultipleMatchers(t *testing.T)
156160
Operator: "CONTAINS",
157161
Value: "MONGOS",
158162
})
163+
lastVersionConstraint = os.Getenv("MONGODB_ATLAS_LAST_VERSION")
159164
)
160165

161166
resource.ParallelTest(t, resource.TestCase{
162-
PreCheck: func() { testAccPreCheckBasic(t) },
167+
PreCheck: func() { testAccMigrationPreCheckBasic(t) },
163168
CheckDestroy: testAccCheckMongoDBAtlasAlertConfigurationDestroy,
164169
Steps: []resource.TestStep{
165170
{
166171
ExternalProviders: map[string]resource.ExternalProvider{
167172
"mongodbatlas": {
168-
VersionConstraint: "1.11.0",
173+
VersionConstraint: lastVersionConstraint,
169174
Source: "mongodb/mongodbatlas",
170175
},
171176
},
@@ -190,23 +195,24 @@ func TestAccConfigRSAlertConfiguration_Migration_MultipleMatchers(t *testing.T)
190195
})
191196
}
192197

193-
func TestAccConfigRSAlertConfiguration_Migration_EmptyOptionalAttributes(t *testing.T) {
198+
func TestAccMigrationConfigRSAlertConfiguration_EmptyOptionalAttributes(t *testing.T) {
194199
var (
195-
resourceName = "mongodbatlas_alert_configuration.test"
196-
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
197-
projectName = acctest.RandomWithPrefix("test-acc")
198-
alert = &matlas.AlertConfiguration{}
199-
config = testAccMongoDBAtlasAlertConfigurationConfigWithEmptyOptionalAttributes(orgID, projectName)
200+
resourceName = "mongodbatlas_alert_configuration.test"
201+
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
202+
projectName = acctest.RandomWithPrefix("test-acc")
203+
alert = &matlas.AlertConfiguration{}
204+
config = testAccMongoDBAtlasAlertConfigurationConfigWithEmptyOptionalAttributes(orgID, projectName)
205+
lastVersionConstraint = os.Getenv("MONGODB_ATLAS_LAST_VERSION")
200206
)
201207

202208
resource.ParallelTest(t, resource.TestCase{
203-
PreCheck: func() { testAccPreCheckBasic(t) },
209+
PreCheck: func() { testAccMigrationPreCheckBasic(t) },
204210
CheckDestroy: testAccCheckMongoDBAtlasAlertConfigurationDestroy,
205211
Steps: []resource.TestStep{
206212
{
207213
ExternalProviders: map[string]resource.ExternalProvider{
208214
"mongodbatlas": {
209-
VersionConstraint: "1.11.0",
215+
VersionConstraint: lastVersionConstraint,
210216
Source: "mongodb/mongodbatlas",
211217
},
212218
},

0 commit comments

Comments
 (0)