Skip to content

INTMDB-290: Added advanced configuration for datasource/resource of advanced cluster #658

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

Merged
merged 5 commits into from
Jan 20, 2022

Conversation

coderGo93
Copy link
Contributor

Description

  • Added parameter advanced_configuration for resource and datasource of advanced_cluster
  • Added docs and tests

Results of tests

Resource
Advanced cluster

make testacc TESTARGS='-run=TestAccResourceMongoDBAtlasAdvancedCluster_advancedConf'   [15:28:46]
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test $(go list ./... | grep -v /integrationtesting) -v -parallel 20 -run=TestAccResourceMongoDBAtlasAdvancedCluster_advancedConf -timeout 300m -cover -ldflags="-s -w -X 'github.com/mongodb/terraform-provider-mongodbatlas/version.ProviderVersion=acc'"
?       github.com/mongodb/terraform-provider-mongodbatlas      [no test files]
=== RUN   TestAccResourceMongoDBAtlasAdvancedCluster_advancedConf
=== PAUSE TestAccResourceMongoDBAtlasAdvancedCluster_advancedConf
=== CONT  TestAccResourceMongoDBAtlasAdvancedCluster_advancedConf
--- PASS: TestAccResourceMongoDBAtlasAdvancedCluster_advancedConf (1401.44s)
PASS
coverage: 5.6% of statements
ok      github.com/mongodb/terraform-provider-mongodbatlas/mongodbatlas 1404.113s       coverage: 5.6% of statements
?       github.com/mongodb/terraform-provider-mongodbatlas/version      [no test files]

Datasource
Advanced cluster

make testacc TESTARGS='-run=TestAccDataSourceMongoDBAtlasAdvancedCluster_advancedConf'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test $(go list ./... | grep -v /integrationtesting) -v -parallel 20 -run=TestAccDataSourceMongoDBAtlasAdvancedCluster_advancedConf -timeout 300m -cover -ldflags="-s -w -X 'github.com/mongodb/terraform-provider-mongodbatlas/version.ProviderVersion=acc'"
?       github.com/mongodb/terraform-provider-mongodbatlas      [no test files]
=== RUN   TestAccDataSourceMongoDBAtlasAdvancedCluster_advancedConf
=== PAUSE TestAccDataSourceMongoDBAtlasAdvancedCluster_advancedConf
=== CONT  TestAccDataSourceMongoDBAtlasAdvancedCluster_advancedConf
--- PASS: TestAccDataSourceMongoDBAtlasAdvancedCluster_advancedConf (746.11s)
PASS
coverage: 6.3% of statements
ok      github.com/mongodb/terraform-provider-mongodbatlas/mongodbatlas 750.576s        coverage: 6.3% of statements
?       github.com/mongodb/terraform-provider-mongodbatlas/version      [no test files]

Advanced clusters

make testacc TESTARGS='-run=TestAccDataSourceMongoDBAtlasAdvancedClusters_advancedConf'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test $(go list ./... | grep -v /integrationtesting) -v -parallel 20 -run=TestAccDataSourceMongoDBAtlasAdvancedClusters_advancedConf -timeout 300m -cover -ldflags="-s -w -X 'github.com/mongodb/terraform-provider-mongodbatlas/version.ProviderVersion=acc'"
?       github.com/mongodb/terraform-provider-mongodbatlas      [no test files]
=== RUN   TestAccDataSourceMongoDBAtlasAdvancedClusters_advancedConf
=== PAUSE TestAccDataSourceMongoDBAtlasAdvancedClusters_advancedConf
=== CONT  TestAccDataSourceMongoDBAtlasAdvancedClusters_advancedConf
--- PASS: TestAccDataSourceMongoDBAtlasAdvancedClusters_advancedConf (682.70s)
PASS
coverage: 6.2% of statements
ok      github.com/mongodb/terraform-provider-mongodbatlas/mongodbatlas 689.151s        coverage: 6.2% of statements
?       github.com/mongodb/terraform-provider-mongodbatlas/version      [no test files]

Link to any related issue(s):

Type of change:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Documentation fix/enhancement

Required Checklist:

  • I have signed the MongoDB CLA
  • I have read the Terraform contribution guidelines
  • I have added tests that prove my fix is effective or that my feature works per HashiCorp requirements
  • I have added any necessary documentation (if appropriate)
  • I have run make fmt and formatted my code

Further comments

@coderGo93 coderGo93 changed the title added advanced configuration for datasource(s) and resource of adavan… INTMDB-290: Added advanced configuration for datasource/resource of advanced cluster Jan 14, 2022
Copy link
Contributor

@thetonymaster thetonymaster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

advancedConfReq := expandProcessArgs(d, aclist[0].(map[string]interface{}))

if ok {
_, _, err := conn.Clusters.UpdateProcessArgs(ctx, projectID, cluster.Name, advancedConfReq)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this NL

Copy link
Collaborator

@themantissa themantissa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One questions about tests coverage difference between cluster and advanced cluster but that's it. Thank you!

@@ -247,6 +248,70 @@ func TestAccResourceMongoDBAtlasAdvancedCluster_Paused(t *testing.T) {
})
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we added the new read/write concern options to advanced configuration we added another test:
https://github.com/mongodb/terraform-provider-mongodbatlas/blob/master/mongodbatlas/resource_mongodbatlas_cluster_test.go#L160
Should we add that here? Or at least add the additional parameters to these tests? DefaultReadConcern
& DefaultWriteConcern ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, will add those parameters in the same test and see whether it passes or not

@@ -24,6 +25,7 @@ func dataSourceMongoDBAtlasAdvancedClusters() *schema.Resource {
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"advanced_configuration": clusterAdvancedConfigurationSchemaComputed(),
"backup_enabled": {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not related to this change but I see that this schema has

						"name": {
							Type:     schema.TypeString,
							Computed: true,
						},

where we are using Required: true for the name in data_source_mongodbatlas_advanced_cluster.go.
Is this correct or both should be Computed: true?

Copy link
Contributor Author

@coderGo93 coderGo93 Jan 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the singular datasource is required to get a specific advanced cluster along the project ID, in the plural datasource, it will get all the advanced clusters from the project ID provided and then list it with all computed parameters. Also, you cannot use Computed if you are using Required at the same time.

Comment on lines 227 to 228
log.Printf("[WARN] Error setting `advanced_configuration` for the cluster(%s): %s", clusters[i].ID, err)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[q] Shouldn’t we check that err != nil before printing the log message?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, will add the validation, thank you

@@ -221,7 +223,11 @@ func flattenAdvancedClusters(ctx context.Context, d *schema.ResourceData, conn *
results := make([]map[string]interface{}, 0)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[q] why d *schema.ResourceData is an argument of this function if it is not used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good eye, will remove the argument since is not necessary this time

*/
if d.HasChange("advanced_configuration") {
ac := d.Get("advanced_configuration")
if aclist, ok1 := ac.([]interface{}); ok1 && len(aclist) > 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[q] any reason why you are defining ok1 instead ok?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No reason at all and good eye, will update the naming, thank you.

@@ -540,6 +579,22 @@ func resourceMongoDBAtlasAdvancedClusterUpdate(ctx context.Context, d *schema.Re
}
}

/*
Check if advanced configuration option has a changes to update it
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this comment is not clear. Maybe something like "update advanced configuration options if needed" would be better

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood, will update the comment, thank you

Copy link
Collaborator

@andreaangiolillo andreaangiolillo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for all the changes

Copy link
Collaborator

@themantissa themantissa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you!

@coderGo93 coderGo93 added the run-testacc To run acceptance tests label Jan 19, 2022
@coderGo93 coderGo93 merged commit eac7d92 into master Jan 20, 2022
@coderGo93 coderGo93 deleted the INTMDB-290 branch January 20, 2022 03:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
run-testacc To run acceptance tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants