Skip to content

Commit 13bccfd

Browse files
authored
refactor: Migrate to new Atlas SDK - mongodbatlas_federated_database_instance resource (#1415)
1 parent 7b0646a commit 13bccfd

18 files changed

+427
-207
lines changed

.github/workflows/acceptance-tests.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ jobs:
2525
generic: ${{ steps.filter.outputs.generic }}
2626
backup_online_archive: ${{ steps.filter.outputs.backup_online_archive }}
2727
backup_snapshots: ${{ steps.filter.outputs.backup_snapshots }}
28+
federation: ${{ steps.filter.outputs.federation }}
2829
backup_schedule: ${{ steps.filter.outputs.backup_schedule }}
2930
project: ${{ steps.filter.outputs.project }}
3031
serverless: ${{ steps.filter.outputs.serverless }}
@@ -69,6 +70,8 @@ jobs:
6970
- 'mongodbatlas/**_network**.go'
7071
- 'mongodbatlas/**_privatelink**.go'
7172
- 'mongodbatlas/**_private_endpoint**.go'
73+
federation:
74+
- 'mongodbatlas/**_federated_database_instance**.go'
7275
config:
7376
- 'mongodbatlas/data_source_mongodbatlas_accesslist_api_key*.go'
7477
- 'mongodbatlas/data_source_mongodbatlas_alert_configuration*.go'
@@ -366,6 +369,33 @@ jobs:
366369
CI: true
367370
TEST_REGEX: "^TestAccNetwork"
368371
run: make testacc
372+
373+
federation:
374+
needs: [ change-detection ]
375+
if: ${{ needs.change-detection.outputs.federation == 'true' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' || github.event.label.name == 'run-testacc' || github.event.label.name == 'run-testacc-federation' || inputs.parent-event-name == 'release' }}
376+
runs-on: ubuntu-latest
377+
steps:
378+
- name: Checkout
379+
uses: actions/checkout@v3
380+
- name: Set up Go
381+
uses: actions/setup-go@v4
382+
with:
383+
go-version-file: 'go.mod'
384+
- name: Acceptance Tests
385+
env:
386+
MONGODB_ATLAS_PUBLIC_KEY: ${{ secrets.MONGODB_ATLAS_PUBLIC_KEY_CLOUD_DEV }}
387+
MONGODB_ATLAS_PRIVATE_KEY: ${{ secrets.MONGODB_ATLAS_PRIVATE_KEY_CLOUD_DEV }}
388+
MONGODB_ATLAS_ORG_ID: ${{ vars.MONGODB_ATLAS_ORG_ID_CLOUD_DEV }}
389+
MONGODB_ATLAS_BASE_URL: ${{ vars.MONGODB_ATLAS_BASE_URL }}
390+
SKIP_TEST_EXTERNAL_CREDENTIALS: ${{ vars.SKIP_TEST_EXTERNAL_CREDENTIALS }}
391+
ACCTEST_TIMEOUT: ${{ vars.ACCTEST_TIMEOUT }}
392+
TF_LOG: ${{ vars.LOG_LEVEL }}
393+
CI: true
394+
TF_ACC: 1
395+
PARALLEL_GO_TEST: 20
396+
TEST_REGEX: "^TestAccFederatedDatabaseInstance"
397+
run: make testacc
398+
369399
config:
370400
needs: [ change-detection ]
371401
if: ${{ needs.change-detection.outputs.config == 'true' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' || github.event.label.name == 'run-testacc' || github.event.label.name == 'run-testacc-config' || inputs.parent-event-name == 'release' }}

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ require (
88
github.com/gruntwork-io/terratest v0.43.13
99
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
1010
github.com/hashicorp/hcl/v2 v2.17.0
11+
github.com/hashicorp/terraform-plugin-log v0.9.0
1112
github.com/hashicorp/terraform-plugin-sdk/v2 v2.28.0
1213
github.com/hashicorp/terraform-plugin-testing v1.4.0
1314
github.com/mongodb-forks/digest v1.0.5
1415
github.com/mwielbut/pointy v1.1.0
1516
github.com/spf13/cast v1.5.1
1617
github.com/zclconf/go-cty v1.13.3
1718
go.mongodb.org/atlas v0.33.0
18-
go.mongodb.org/atlas-sdk/v20230201002 v20230201002.0.0
19+
go.mongodb.org/atlas-sdk/v20230201006 v20230201006.0.0
1920
go.mongodb.org/realm v0.1.0
2021
golang.org/x/exp v0.0.0-20221208152030-732eee02a75a
2122
)
@@ -68,7 +69,6 @@ require (
6869
github.com/hashicorp/terraform-exec v0.18.1 // indirect
6970
github.com/hashicorp/terraform-json v0.17.1 // indirect
7071
github.com/hashicorp/terraform-plugin-go v0.18.0 // indirect
71-
github.com/hashicorp/terraform-plugin-log v0.9.0 // indirect
7272
github.com/hashicorp/terraform-registry-address v0.2.1 // indirect
7373
github.com/hashicorp/terraform-svchost v0.1.1 // indirect
7474
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -602,8 +602,8 @@ github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRK
602602
go.mongodb.org/atlas v0.12.0/go.mod h1:wVCnHcm/7/IfTjEB6K8K35PLG70yGz8BdkRwX0oK9/M=
603603
go.mongodb.org/atlas v0.33.0 h1:qJhkEuJufh7sVDVHorTF/D7G7naQ1EJAzqf1aV29JWs=
604604
go.mongodb.org/atlas v0.33.0/go.mod h1:L4BKwVx/OeEhOVjCSdgo90KJm4469iv7ZLzQms/EPTg=
605-
go.mongodb.org/atlas-sdk/v20230201002 v20230201002.0.0 h1:ANYyIzbdxSdwwbragGKDuAg+3bmr940rbxCvZdIwnPk=
606-
go.mongodb.org/atlas-sdk/v20230201002 v20230201002.0.0/go.mod h1:SG7r2T7R595Z/+x/miXGR89ZsinqXG/P6k0p+CSNBPY=
605+
go.mongodb.org/atlas-sdk/v20230201006 v20230201006.0.0 h1:HaY0cmYAlqoC+7iRE0NTPEQyAr2nqdxE9gspMp8Pmyo=
606+
go.mongodb.org/atlas-sdk/v20230201006 v20230201006.0.0/go.mod h1:Lgqhl8h8m0iqTloSypmqt/Vi8ZIGvx3tXFuu07HPUyk=
607607
go.mongodb.org/realm v0.1.0 h1:zJiXyLaZrznQ+Pz947ziSrDKUep39DO4SfA0Fzx8M4M=
608608
go.mongodb.org/realm v0.1.0/go.mod h1:4Vj6iy+Puo1TDERcoh4XZ+pjtwbOzPpzqy3Cwe8ZmDM=
609609
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=

mongodbatlas/config.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@ import (
66
"fmt"
77
"net/http"
88

9+
atlasSDK "go.mongodb.org/atlas-sdk/v20230201006/admin"
10+
matlasClient "go.mongodb.org/atlas/mongodbatlas"
11+
realmAuth "go.mongodb.org/realm/auth"
12+
"go.mongodb.org/realm/realm"
13+
914
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1015
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/logging"
1116
"github.com/mongodb-forks/digest"
12-
"github.com/mongodb/terraform-provider-mongodbatlas/version"
1317
"github.com/spf13/cast"
14-
atlasSDK "go.mongodb.org/atlas-sdk/v20230201002/admin"
15-
matlasClient "go.mongodb.org/atlas/mongodbatlas"
16-
realmAuth "go.mongodb.org/realm/auth"
17-
"go.mongodb.org/realm/realm"
18+
19+
"github.com/mongodb/terraform-provider-mongodbatlas/version"
1820
)
1921

2022
const ToolName = "terraform-provider-mongodbatlas"

mongodbatlas/data_source_mongodbatlas_cloud_shared_tier_restore_jobs.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import (
44
"context"
55
"fmt"
66

7+
atlasSDK "go.mongodb.org/atlas-sdk/v20230201006/admin"
8+
79
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
810
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/id"
911
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
10-
atlasSDK "go.mongodb.org/atlas-sdk/v20230201002/admin"
1112
)
1213

1314
// This datasource does not have a resource: we tested it manually

mongodbatlas/data_source_mongodbatlas_federated_database_instance.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,9 @@ func schemaFederatedDatabaseInstanceStoresDataSource() *schema.Schema {
223223
Computed: true,
224224
},
225225
"cluster_id": {
226-
Type: schema.TypeString,
227-
Computed: true,
228-
},
226+
Type: schema.TypeString,
227+
Computed: true,
228+
Deprecated: fmt.Sprintf(DeprecationByDateMessageParameter, "September 2024")},
229229
"project_id": {
230230
Type: schema.TypeString,
231231
Computed: true,
@@ -304,12 +304,12 @@ func schemaFederatedDatabaseInstanceStoresDataSource() *schema.Schema {
304304
}
305305

306306
func dataSourceMongoDBAtlasFederatedDatabaseInstanceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
307-
conn := meta.(*MongoDBClient).Atlas
307+
connV2 := meta.(*MongoDBClient).AtlasV2
308308

309309
projectID := d.Get("project_id").(string)
310310
name := d.Get("name").(string)
311311

312-
dataFederationInstance, _, err := conn.DataFederation.Get(ctx, projectID, name)
312+
dataFederationInstance, _, err := connV2.DataFederationApi.GetFederatedDatabase(ctx, projectID, name).Execute()
313313
if err != nil {
314314
return diag.FromErr(fmt.Errorf("couldn't import data lake(%s) for project (%s), error: %s", name, projectID, err))
315315
}
@@ -352,7 +352,7 @@ func dataSourceMongoDBAtlasFederatedDatabaseInstanceRead(ctx context.Context, d
352352

353353
d.SetId(encodeStateID(map[string]string{
354354
"project_id": projectID,
355-
"name": dataFederationInstance.Name,
355+
"name": dataFederationInstance.GetName(),
356356
}))
357357

358358
return nil

mongodbatlas/data_source_mongodbatlas_federated_database_instance_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import (
77
"os"
88
"testing"
99

10+
matlas "go.mongodb.org/atlas/mongodbatlas"
11+
1012
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
1113
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
1214
"github.com/hashicorp/terraform-plugin-testing/terraform"
13-
matlas "go.mongodb.org/atlas/mongodbatlas"
1415
)
1516

1617
func TestAccDataSourceFederatedDatabaseInstance_basic(t *testing.T) {
17-
SkipTestExtCred(t)
1818
var (
1919
resourceName = "data.mongodbatlas_federated_database_instance.test"
2020
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
@@ -24,7 +24,7 @@ func TestAccDataSourceFederatedDatabaseInstance_basic(t *testing.T) {
2424
)
2525

2626
resource.ParallelTest(t, resource.TestCase{
27-
PreCheck: func() { testAccPreCheck(t) },
27+
PreCheck: func() { testAccPreCheckBasic(t) },
2828
CheckDestroy: testAccCheckMongoDBAtlasFederatedDatabaseInstanceDestroy,
2929
Steps: []resource.TestStep{
3030
{
@@ -62,7 +62,7 @@ func TestAccDataSourceFederatedDatabaseInstance_S3Bucket(t *testing.T) {
6262
)
6363

6464
resource.ParallelTest(t, resource.TestCase{
65-
PreCheck: func() { testAccPreCheck(t) },
65+
PreCheck: func() { testAccPreCheckBasic(t) },
6666
CheckDestroy: testAccCheckMongoDBAtlasFederatedDatabaseInstanceDestroy,
6767
Steps: []resource.TestStep{
6868
{

mongodbatlas/data_source_mongodbatlas_federated_database_instances.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import (
44
"context"
55
"fmt"
66

7+
"go.mongodb.org/atlas-sdk/v20230201006/admin"
8+
79
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
810
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/id"
911
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
10-
matlas "go.mongodb.org/atlas/mongodbatlas"
1112
)
1213

1314
func dataSourceMongoDBAtlasFederatedDatabaseInstances() *schema.Resource {
@@ -110,11 +111,11 @@ func dataSourceMongoDBAtlasFederatedDatabaseInstances() *schema.Resource {
110111
}
111112

112113
func dataSourceMongoDBAtlasFederatedDatabaseInstancesRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
113-
conn := meta.(*MongoDBClient).Atlas
114+
connV2 := meta.(*MongoDBClient).AtlasV2
114115

115116
projectID := d.Get("project_id").(string)
116117

117-
federatedDatabaseInstances, _, err := conn.DataFederation.List(ctx, projectID)
118+
federatedDatabaseInstances, _, err := connV2.DataFederationApi.ListFederatedDatabases(ctx, projectID).Execute()
118119
if err != nil {
119120
return diag.FromErr(fmt.Errorf("error getting MongoDB Atlas Federated Database Instances information: %s", err))
120121
}
@@ -130,7 +131,7 @@ func dataSourceMongoDBAtlasFederatedDatabaseInstancesRead(ctx context.Context, d
130131
return nil
131132
}
132133

133-
func flattenFederatedDatabaseInstances(d *schema.ResourceData, projectID string, federatedDatabaseInstances []*matlas.DataFederationInstance) []map[string]interface{} {
134+
func flattenFederatedDatabaseInstances(d *schema.ResourceData, projectID string, federatedDatabaseInstances []admin.DataLakeTenant) []map[string]interface{} {
134135
var federatedDatabaseInstancesMap []map[string]interface{}
135136

136137
if len(federatedDatabaseInstances) > 0 {
@@ -139,9 +140,9 @@ func flattenFederatedDatabaseInstances(d *schema.ResourceData, projectID string,
139140
for i := range federatedDatabaseInstances {
140141
federatedDatabaseInstancesMap[i] = map[string]interface{}{
141142
"project_id": projectID,
142-
"name": federatedDatabaseInstances[i].Name,
143-
"state": federatedDatabaseInstances[i].State,
144-
"hostnames": federatedDatabaseInstances[i].Hostnames,
143+
"name": federatedDatabaseInstances[i].GetName(),
144+
"state": federatedDatabaseInstances[i].GetState(),
145+
"hostnames": federatedDatabaseInstances[i].GetHostnames(),
145146
"cloud_provider_config": flattenCloudProviderConfig(d, federatedDatabaseInstances[i].CloudProviderConfig),
146147
"data_process_region": flattenDataProcessRegion(federatedDatabaseInstances[i].DataProcessRegion),
147148
"storage_databases": flattenDataFederationDatabase(federatedDatabaseInstances[i].Storage.Databases),

mongodbatlas/data_source_mongodbatlas_federated_database_instances_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func TestAccDataSourceFederatedDatabaseInstances_basic(t *testing.T) {
2424
)
2525

2626
resource.ParallelTest(t, resource.TestCase{
27-
PreCheck: func() { testAccPreCheck(t) },
27+
PreCheck: func() { testAccPreCheckBasic(t) },
2828
CheckDestroy: testAccCheckMongoDBAtlasFederatedDatabaseInstanceDestroy,
2929
Steps: []resource.TestStep{
3030
{

mongodbatlas/data_source_mongodbatlas_shared_tier_snapshots.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import (
44
"context"
55
"fmt"
66

7+
atlasSDK "go.mongodb.org/atlas-sdk/v20230201006/admin"
8+
79
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
810
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/id"
911
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
10-
atlasSDK "go.mongodb.org/atlas-sdk/v20230201002/admin"
1112
)
1213

1314
// This datasource does not have a resource: we tested it manually

0 commit comments

Comments
 (0)