Skip to content

Commit

Permalink
chore: Upgrades cluster_outage_simulation resource to auto-generate…
Browse files Browse the repository at this point in the history
…d SDK (#1935)

* rename resource methods

* test rename methods

* rename data source method

* add migration test

* migrate to new SDK

* run migration test in CI

* add missing env variable

* time to string for start_request_date

* fix migration tests variables

* fix mig variables

* change to SHA instead of version

* change to TimePtrToStringPtr

* change to numeric params in configs
  • Loading branch information
oarbusi authored Feb 13, 2024
1 parent d5c7ea8 commit f1da07e
Show file tree
Hide file tree
Showing 6 changed files with 187 additions and 91 deletions.
69 changes: 48 additions & 21 deletions .github/workflows/migration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ jobs:
encryption: ${{ steps.filter.outputs.encryption == 'true' || env.mustTrigger == 'true' }}
serverless: ${{ steps.filter.outputs.serverless == 'true' || env.mustTrigger == 'true' }}
data_lake: ${{ steps.filter.outputs.data_lake == 'true' || env.mustTrigger == 'true' }}
cluster_outage_simulation: ${{ steps.filter.outputs.cluster_outage_simulation == 'true' || env.mustTrigger == 'true' }}
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- uses: dorny/paths-filter@0bc4621a3135347011ad047f9ecf449bf72ce2bd
Expand Down Expand Up @@ -132,6 +133,8 @@ jobs:
- 'internal/service/privatelinkendpointserviceserverless/*.go'
data_lake:
- 'internal/service/datalakepipeline/*.go'
cluster_outage_simulation:
- 'internal/service/clusteroutagesimulation/*.go'
project:
needs: [ change-detection, get-provider-version ]
Expand Down Expand Up @@ -281,12 +284,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- name: Set up Go
uses: actions/setup-go@v5
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491
with:
go-version-file: 'go.mod'
- uses: hashicorp/setup-terraform@v3
- uses: hashicorp/setup-terraform@a1502cd9e758c50496cc9ac5308c4843bcd56d36
with:
terraform_version: ${{ env.terraform_version }}
terraform_wrapper: false
Expand All @@ -310,12 +313,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- name: Set up Go
uses: actions/setup-go@v5
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491
with:
go-version-file: 'go.mod'
- uses: hashicorp/setup-terraform@v3
- uses: hashicorp/setup-terraform@a1502cd9e758c50496cc9ac5308c4843bcd56d36
with:
terraform_version: ${{ env.terraform_version }}
terraform_wrapper: false
Expand All @@ -335,12 +338,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- name: Set up Go
uses: actions/setup-go@v5
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491
with:
go-version-file: 'go.mod'
- uses: hashicorp/setup-terraform@v3
- uses: hashicorp/setup-terraform@a1502cd9e758c50496cc9ac5308c4843bcd56d36
with:
terraform_version: ${{ env.terraform_version }}
terraform_wrapper: false
Expand All @@ -362,12 +365,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- name: Set up Go
uses: actions/setup-go@v5
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491
with:
go-version-file: 'go.mod'
- uses: hashicorp/setup-terraform@v3
- uses: hashicorp/setup-terraform@a1502cd9e758c50496cc9ac5308c4843bcd56d36
with:
terraform_version: ${{ env.terraform_version }}
terraform_wrapper: false
Expand Down Expand Up @@ -395,12 +398,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- name: Set up Go
uses: actions/setup-go@v5
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491
with:
go-version-file: 'go.mod'
- uses: hashicorp/setup-terraform@v3
- uses: hashicorp/setup-terraform@a1502cd9e758c50496cc9ac5308c4843bcd56d36
with:
terraform_version: ${{ env.terraform_version }}
terraform_wrapper: false
Expand All @@ -419,12 +422,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- name: Set up Go
uses: actions/setup-go@v5
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491
with:
go-version-file: 'go.mod'
- uses: hashicorp/setup-terraform@v3
- uses: hashicorp/setup-terraform@a1502cd9e758c50496cc9ac5308c4843bcd56d36
with:
terraform_version: ${{ env.terraform_version }}
terraform_wrapper: false
Expand All @@ -443,12 +446,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- name: Set up Go
uses: actions/setup-go@v5
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491
with:
go-version-file: 'go.mod'
- uses: hashicorp/setup-terraform@v3
- uses: hashicorp/setup-terraform@a1502cd9e758c50496cc9ac5308c4843bcd56d36
with:
terraform_version: ${{ env.terraform_version }}
terraform_wrapper: false
Expand All @@ -461,3 +464,27 @@ jobs:
MONGODB_ATLAS_LAST_VERSION: ${{ needs.get-provider-version.outputs.provider_version }}
TEST_REGEX: "^TestAccMigrationcDataLake"
run: make testacc
cluster_outage_simulation:
needs: [ change-detection, get-provider-version ]
if: ${{ needs.change-detection.outputs.cluster_outage_simulation == 'true' || inputs.test_group == 'cluster_outage_simulation' }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- name: Set up Go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491
with:
go-version-file: 'go.mod'
- uses: hashicorp/setup-terraform@a1502cd9e758c50496cc9ac5308c4843bcd56d36
with:
terraform_version: ${{ env.terraform_version }}
terraform_wrapper: false
- name: Migration 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_LAST_VERSION: ${{ needs.get-provider-version.outputs.provider_version }}
TEST_REGEX: "^TestAccMigrationOutageSimulationCluster"
run: make testacc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

func DataSource() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceMongoDBAtlasClusterOutageSimulationRead,
ReadContext: dataSourceRead,
Schema: map[string]*schema.Schema{
"project_id": {
Type: schema.TypeString,
Expand Down Expand Up @@ -58,8 +58,8 @@ func DataSource() *schema.Resource {
}
}

func dataSourceMongoDBAtlasClusterOutageSimulationRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
conn := meta.(*config.MongoDBClient).Atlas
func dataSourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
connV2 := meta.(*config.MongoDBClient).AtlasV2

projectID, projectIDOk := d.GetOk("project_id")
clusterName, clusterNameOk := d.GetOk("cluster_name")
Expand All @@ -68,7 +68,7 @@ func dataSourceMongoDBAtlasClusterOutageSimulationRead(ctx context.Context, d *s
return diag.Errorf("project_id and cluster_name must be configured")
}

outageSimulation, _, err := conn.ClusterOutageSimulation.GetOutageSimulation(ctx, projectID.(string), clusterName.(string))
outageSimulation, _, err := connV2.ClusterOutageSimulationApi.GetOutageSimulation(ctx, projectID.(string), clusterName.(string)).Execute()
if err != nil {
return diag.FromErr(fmt.Errorf(errorClusterOutageSimulationRead, projectID, clusterName, err))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ func TestAccOutageSimulationClusterDS_SingleRegion_basic(t *testing.T) {
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acc.PreCheckBasic(t) },
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
CheckDestroy: testAccCheckMongoDBAtlasClusterOutageSimulationDestroy,
CheckDestroy: checkDestroy,
Steps: []resource.TestStep{
{
Config: testAccDataSourceMongoDBAtlasClusterOutageSimulationConfigDSSingleRegion(projectName, orgID, clusterName),
Config: dataSourceConfigSingleRegion(projectName, orgID, clusterName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(dataSourceName, "cluster_name", clusterName),
resource.TestCheckResourceAttrSet(dataSourceName, "project_id"),
Expand All @@ -49,10 +49,10 @@ func TestAccOutageSimulationClusterDS_MultiRegion_basic(t *testing.T) {
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acc.PreCheckBasic(t) },
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
CheckDestroy: testAccCheckMongoDBAtlasClusterOutageSimulationDestroy,
CheckDestroy: checkDestroy,
Steps: []resource.TestStep{
{
Config: testAccDataSourceMongoDBAtlasClusterOutageSimulationConfigDSMultiRegion(projectName, orgID, clusterName),
Config: dataSourceConfigMultiRegion(projectName, orgID, clusterName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(dataSourceName, "cluster_name", clusterName),
resource.TestCheckResourceAttrSet(dataSourceName, "project_id"),
Expand All @@ -66,17 +66,17 @@ func TestAccOutageSimulationClusterDS_MultiRegion_basic(t *testing.T) {
})
}

func testAccDataSourceMongoDBAtlasClusterOutageSimulationConfigDSSingleRegion(projectName, orgID, clusterName string) string {
func dataSourceConfigSingleRegion(projectName, orgID, clusterName string) string {
return fmt.Sprintf(`
resource "mongodbatlas_project" "outage_project" {
name = "%s"
org_id = "%s"
name = %[1]q
org_id = %[2]q
}
resource "mongodbatlas_cluster" "atlas_cluster" {
project_id = mongodbatlas_project.outage_project.id
provider_name = "AWS"
name = "%s"
name = %[3]q
backing_provider_name = "AWS"
provider_region_name = "US_EAST_1"
provider_instance_size_name = "M10"
Expand All @@ -101,16 +101,16 @@ func testAccDataSourceMongoDBAtlasClusterOutageSimulationConfigDSSingleRegion(pr
`, projectName, orgID, clusterName)
}

func testAccDataSourceMongoDBAtlasClusterOutageSimulationConfigDSMultiRegion(projectName, orgID, clusterName string) string {
func dataSourceConfigMultiRegion(projectName, orgID, clusterName string) string {
return fmt.Sprintf(`
resource "mongodbatlas_project" "outage_project" {
name = "%s"
org_id = "%s"
name = %[1]q
org_id = %[2]q
}
resource "mongodbatlas_cluster" "atlas_cluster" {
project_id = mongodbatlas_project.outage_project.id
name = "%s"
name = %[3]q
cluster_type = "REPLICASET"
provider_name = "AWS"
Expand Down
Loading

0 comments on commit f1da07e

Please sign in to comment.