Skip to content
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

azurerm_mongo_cluster - Supports connection_strings #28880

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

magodo
Copy link
Collaborator

@magodo magodo commented Feb 26, 2025

Community Note

  • Please vote on this PR by adding a 👍 reaction to the original PR to help the community and maintainers prioritize for review
  • Please do not leave comments along the lines of "+1", "me too" or "any updates", they generate extra noise for PR followers and do not help prioritize for review

Description

azurerm_mongo_cluster - Supports connection_strings.

Note that the connection_string returned from API is a template, with <user>:<password> place holders. This PR replace them with the real user name and password, to make it directly usable for users. Since the password is only available in the state/config, this replacement won't occur during importing.

PR Checklist

  • I have followed the guidelines in our Contributing Documentation.
  • I have checked to ensure there aren't other open Pull Requests for the same update/change.
  • I have checked if my changes close any open issues. If so please include appropriate closing keywords below.
  • I have updated/added Documentation as required written in a helpful and kind way to assist users that may be unfamiliar with the resource / data source.
  • I have used a meaningful PR title to help maintainers and other users understand this change and help prevent duplicate work.
    For example: “resource_name_here - description of change e.g. adding property new_property_name_here

Changes to existing Resource / Data Source

  • I have added an explanation of what my changes do and why I'd like you to include them (This may be covered by linking to an issue above, but may benefit from additional explanation).
  • I have written new tests for my resource or datasource changes & updated any relevant documentation.
  • I have successfully run tests with my changes locally. If not, please provide details on testing challenges that prevented you running the tests.
  • (For changes that include a state migration only). I have manually tested the migration path between relevant versions of the provider.

Testing

  • My submission includes Test coverage as described in the Contribution Guide and the tests pass. (if this is not possible for any reason, please include details of why you did or could not add test coverage)
💢  TF_ACC=1 go test -v -timeout=20h -parallel=20 -run=TestAccMongoCluster_basic ./internal/services/mongocluster
=== RUN   TestAccMongoCluster_basic
--- PASS: TestAccMongoCluster_basic (1181.18s)
PASS
ok      github.com/hashicorp/terraform-provider-azurerm/internal/services/mongocluster  1181.195s

Change Log

Below please provide what should go into the changelog (if anything) conforming to the Changelog Format documented here.

  • azurerm_mongo_cluster - Supports connection_strings [GH-00000]

This is a (please select all that apply):

  • Bug Fix
  • New Feature (ie adding a service, resource, or data source)
  • Enhancement
  • Breaking Change

Related Issue(s)

Fixes #28841

Note

If this PR changes meaningfully during the course of review please update the title and description as required.

Copy link
Member

@mbfrahry mbfrahry left a comment

Choose a reason for hiding this comment

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

Hey @magodo, thanks for this PR. It looks mostly good but I've left some comments that I'd appreciate if you could address.

return map[string]*schema.Schema{}
func (r MongoClusterResource) Attributes() map[string]*pluginsdk.Schema {
return map[string]*pluginsdk.Schema{
"connection_strings": {
Copy link
Member

Choose a reason for hiding this comment

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

We should change this to connection_string because otherwise it'll look like the following in state as

  connection_strings {
    //connection string 1 info
  }
 
  connection_strings {
    //connection string 2 info
  }

A plural connection_strings signifies multiple connection strings in a single block rather than one connection string per block.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@mbfrahry This one is a read only attribute, I assume we shall keep it plural as the user can only reference them like: azurerm_mongo_cluster.example.connection_strings.x?

Copy link
Member

Choose a reason for hiding this comment

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

Ahhh good call! That makes sense to me! Thank you for walking me through that

Type: pluginsdk.TypeString,
Computed: true,
},
"connection_string": {
Copy link
Member

Choose a reason for hiding this comment

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

To avoid confusion around connection_string.x.connection_string we should change this to value.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

@@ -452,6 +481,14 @@ func (r MongoClusterResource) Read() sdk.ResourceFunc {
state.Tags = pointer.From(model.Tags)
}

csResp, err := client.ListConnectionStrings(ctx, *id)
if err != nil {
return fmt.Errorf("listing connection string for %s: %+v", *id, err)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return fmt.Errorf("listing connection string for %s: %+v", *id, err)
return fmt.Errorf("listing connection strings for %s: %+v", *id, err)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

Comment on lines 618 to 621
var name string
if cs.Name != nil {
name = *cs.Name
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
var name string
if cs.Name != nil {
name = *cs.Name
}
name := pointer.From(cs.Name)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

Comment on lines 612 to 616
if input == nil {
return nil
}

results := make([]MongoClusterConnectionString, 0)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if input == nil {
return nil
}
results := make([]MongoClusterConnectionString, 0)
results := make([]MongoClusterConnectionString, 0)
if input == nil {
return results
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

Comment on lines 623 to 626
var description string
if cs.Description != nil {
description = *cs.Description
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
var description string
if cs.Description != nil {
description = *cs.Description
}
description := pointer.From(cs.Description)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

Comment on lines 628 to 631
var connectionString string
if cs.ConnectionString != nil {
connectionString = *cs.ConnectionString
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
var connectionString string
if cs.ConnectionString != nil {
connectionString = *cs.ConnectionString
}
connectionString := pointer.From(cs.ConnectionString)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done


* `description` - The description of the connection string.

* `connection_string` - The Mongo Cluster connection string. The `<user>:<password>` place holder returned from API will be replaced by the real `administrator_username` and `administrator_password` if available in the state.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* `connection_string` - The Mongo Cluster connection string. The `<user>:<password>` place holder returned from API will be replaced by the real `administrator_username` and `administrator_password` if available in the state.
* `connection_string` - The Mongo Cluster connection string. The `<user>:<password>` placeholder returned from API will be replaced by the real `administrator_username` and `administrator_password` if available in the state.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

),
},
data.ImportStep("administrator_password", "create_mode"),
data.ImportStep("administrator_password", "create_mode", "connection_strings.0.connection_string"),
Copy link
Member

Choose a reason for hiding this comment

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

We'll need to add "connection_strings.0.connection_string" to all data.ImportSteps in this test file

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

@magodo
Copy link
Collaborator Author

magodo commented Feb 28, 2025

Thanks @mbfrahry! I've resolved all the comments except the 1st one, please take another look!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support exposing connection_strings for azurerm_mongo_cluster
3 participants