-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
New Resource : azurerm_mongo_cluster
#27636
base: main
Are you sure you want to change the base?
New Resource : azurerm_mongo_cluster
#27636
Conversation
0f36d96
to
e721f8a
Compare
e721f8a
to
f313acb
Compare
f313acb
to
24d24cf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @sinbai,
Thanks for this PR - I've taken a look through and left some comments inline. If we can fix those up, this should be good to go 👍
ValidateFunc: validation.All( | ||
validation.StringLenBetween(3, 40), | ||
validation.StringMatch( | ||
regexp.MustCompile(`^[a-z0-9]+(-[a-z0-9]+)*$`), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems the name
cannot start with a hyphen but can end with a hyphen?
maybe you can refer to this code to combine these 2 validations?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be regexp.MustCompile(
^[a-z\d][-a-z\d]{1,38}[a-z\d]$)
because the name
should have at least 3 characters.
Properties: &mongoclusters.MongoClusterProperties{}, | ||
} | ||
|
||
if _, ok := metadata.ResourceData.GetOk("administrator_login"); ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shall we use AdministratorLogin != ""
instead of metadata.ResourceData.GetOk
like other existing typed resources did? please also update other places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
if _, ok := metadata.ResourceData.GetOk("administrator_login"); ok { | ||
parameter.Properties.Administrator = &mongoclusters.AdministratorProperties{ | ||
UserName: pointer.To(state.AdministratorLogin), | ||
Password: pointer.To(state.AdministratorLoginPassword), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since administrator_login_password
is optional, do you need to judge whether it exists?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added RequiredWith: []string{"administrator_username", "administrator_password"}
for administrator_username
and administrator_password
properties. That's means once administrator_username
is specified, the administrator_password
is required. So, I assume that administrator_password
doesn't need to be judged whether it exists here, what do you think?
}) | ||
} | ||
|
||
func TestAccMongoCluster_update(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shall we also test a scenario that the elements of preview_features
are changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume that ForceNew
property preview_features
is not needed to test changes, right?
|
||
switch state.CreateMode { | ||
case string(mongoclusters.CreateModeDefault): | ||
if _, ok := metadata.ResourceDiff.GetOk("administrator_login"); !ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shall we use state,AdministratorLogin != ""
instead of metadata.ResourceDiff.GetOk
? Please also confirm other places below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
|
||
* `administrator_login` - (Optional) The administrator username of the Azure Cosmos DB for MongoDB vCore. Changing this forces a new resource to be created. | ||
|
||
* `create_mode` - (Optional) The creation mode for the Azure Cosmos DB for MongoDB vCore. Possibles values are `Default` and `GeoReplica`. Defaults to 'Default'. Changing this forces a new resource to be created. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* `create_mode` - (Optional) The creation mode for the Azure Cosmos DB for MongoDB vCore. Possibles values are `Default` and `GeoReplica`. Defaults to 'Default'. Changing this forces a new resource to be created. | |
* `create_mode` - (Optional) The creation mode for the Azure Cosmos DB for MongoDB vCore. Possibles values are `Default` and `GeoReplica`. Defaults to `Default`. Changing this forces a new resource to be created. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
|
||
* `create_mode` - (Optional) The creation mode for the Azure Cosmos DB for MongoDB vCore. Possibles values are `Default` and `GeoReplica`. Defaults to 'Default'. Changing this forces a new resource to be created. | ||
|
||
-> **Note** The creation mode "GeoReplica" is currently in preview. It is only available when specified via `preview_features`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-> **Note** The creation mode "GeoReplica" is currently in preview. It is only available when specified via `preview_features`. | |
-> **Note** The creation mode `GeoReplica` is currently in preview. It is only available when `preview_features` is set. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
|
||
* `source_location` - (Optional) The location of the source Azure Cosmos DB for MongoDB vCore. Changing this forces a new resource to be created. | ||
|
||
* `source_resource_id` - (Optional) The ID of the replication source Azure Cosmos DB for MongoDB vCore. Changing this forces a new resource to be created. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be source_server_id
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
|
||
* `high_availability_mode` - (Optional) The high availability mode for the Azure Cosmos DB for MongoDB vCore. Possibles values are `Disabled` and `ZoneRedundantPreferred`. | ||
|
||
* `public_network_access_enabled` - (Optional) Whether public network access is allowed for the Azure Cosmos DB for MongoDB vCore. Defaults to 'true'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* `public_network_access_enabled` - (Optional) Whether public network access is allowed for the Azure Cosmos DB for MongoDB vCore. Defaults to 'true'. | |
* `public_network_access_enabled` - (Optional) Whether public network access is allowed for the Azure Cosmos DB for MongoDB vCore. Defaults to `true`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
}, false), | ||
}, | ||
|
||
"preview_features": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Elements in list can be duplicated. What will happen if duplicated elements are sent to Azure?
Will Azure reorder the element sequence in response if more than 1 elements are sent to Azure?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If duplicated elements are sent to Azure, the API returns a 400 Bad Request with an error message for duplicate array value.
Since there is currently only one possible value for preview_features
(it could not be deleted once specified). I am not sure whether the API would reorder the elements.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add the validation for the duplicated values in the customizeDiff
function so that such error can be found in plan stage?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
Hi @ms-zhenhua thanks for your time and your feedback. I have fixed/replied to the comments. Could you please take another look? |
parameter.Properties.CreateMode = pointer.To(mongoclusters.CreateMode(state.CreateMode)) | ||
} | ||
|
||
if v, ok := metadata.ResourceData.GetOk("preview_features"); ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shall we use PreviewFeatures
instead of metadata.ResourceData.GetOk("preview_features")
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
parameter.Properties.PreviewFeatures = expandPreviewFeatures(v.([]interface{})) | ||
} | ||
|
||
if _, ok := metadata.ResourceData.GetOk("shard_count"); ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since shard_count
is non-zero, you may use ShardCount != 0
instead of metadata.ResourceData.GetOk("shard_count")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
parameter.Properties.PublicNetworkAccess = pointer.To(mongoclusters.PublicNetworkAccessDisabled) | ||
} | ||
|
||
if _, ok := metadata.ResourceData.GetOk("storage_size_in_gb"); ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
} | ||
} | ||
|
||
if _, ok := metadata.ResourceData.GetOk("tags"); ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use Tags
instead of metadata.ResourceData.GetOk("tags")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
Hi @ms-zhenhua , thanks for your feedback again. I have fixed the comments. Could you please take another look? |
} | ||
} | ||
|
||
if len(state.Tags) > 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if len(state.Tags) > 0 { | |
if state.Tags != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
parameter.Properties.CreateMode = pointer.To(mongoclusters.CreateMode(state.CreateMode)) | ||
} | ||
|
||
if len(state.PreviewFeatures) > 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shall we put len(state.PreviewFeatures) > 0
into the expand
function as other resources did?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @sinbai, thank you for your updates. LGTM~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @sinbai, I left some comments and questions in-line that would be good to have fixed up. Furthermore looking at the Azure documentation and how this resource is referred to in there, I'm wondering if this should actually be part of the cosmosdb service package instead of being separated into it's own mongocluster
service package.
Optional: true, | ||
ForceNew: true, | ||
ValidateFunc: validation.StringIsNotEmpty, | ||
RequiredWith: []string{"administrator_username", "administrator_password"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to specify the property name that the RequiredWith
is applied to
RequiredWith: []string{"administrator_username", "administrator_password"}, | |
RequiredWith: []string{"administrator_password"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
Type: schema.TypeString, | ||
Optional: true, | ||
ForceNew: true, | ||
ValidateFunc: validation.StringIsNotEmpty, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should have a stricter validation
ValidateFunc: validation.StringIsNotEmpty, | |
ValidateFunc: mongoclusters.ValidateMongoClusterID, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
Optional: true, | ||
Sensitive: true, | ||
ValidateFunc: validation.StringIsNotEmpty, | ||
RequiredWith: []string{"administrator_username", "administrator_password"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RequiredWith: []string{"administrator_username", "administrator_password"}, | |
RequiredWith: []string{"administrator_username"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
} | ||
|
||
parameter := mongoclusters.MongoCluster{ | ||
Location: azure.NormalizeLocation(state.Location), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is deprecated, please use location.Normalize
Location: azure.NormalizeLocation(state.Location), | |
Location: location.Normalize(state.Location), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
metadata.Logger.Info("Decoding state...") | ||
var state MongoClusterResourceModel | ||
if err := metadata.Decode(&state); err != nil { | ||
return err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error should be wrapped like we do in the create
return err | |
return fmt.Errorf("decoding: %+v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
Manages an Azure Cosmos DB for MongoDB vCore. | ||
--- | ||
|
||
# azurerm_mongo_cluster | ||
|
||
Manages an Azure Cosmos DB for MongoDB vCore. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Manages an Azure Cosmos DB for MongoDB vCore. | |
--- | |
# azurerm_mongo_cluster | |
Manages an Azure Cosmos DB for MongoDB vCore. | |
Manages a MongoDB Cluster using vCore Architecture. | |
--- | |
# azurerm_mongo_cluster | |
Manages a MongoDB Cluster using vCore Architecture. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
@@ -0,0 +1,129 @@ | |||
--- | |||
subcategory: "MongoCluster" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should typically have spacing
subcategory: "MongoCluster" | |
subcategory: "Mongo Cluster" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
|
||
The following arguments are supported: | ||
|
||
* `name` - (Required) The name which should be used for the Azure Cosmos DB for MongoDB vCore. Changing this forces a new resource to be created. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please update all references in these docs from Azure Cosmos DB for MongoDB vCore
to
* `name` - (Required) The name which should be used for the Azure Cosmos DB for MongoDB vCore. Changing this forces a new resource to be created. | |
* `name` - (Required) The name which should be used for the MongoDB Cluster. Changing this forces a new resource to be created. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
|
||
## Import | ||
|
||
Monitor Azure Active Directory Diagnostic Settings can be imported using the `resource id`, e.g. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Monitor Azure Active Directory Diagnostic Settings can be imported using the `resource id`, e.g. | |
MongoDB Clusters can be imported using the `resource id`, e.g. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
website/allowed-subcategories
Outdated
@@ -73,6 +73,7 @@ Maps | |||
Messaging | |||
Mixed Reality | |||
Mobile Network | |||
MongoCluster |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MongoCluster | |
Mongo Cluster |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
11f3acc
to
868b10f
Compare
868b10f
to
969187a
Compare
Hi @stephybun thanks for your time and feedback. I have fixed/replied the comments. Could you please take another look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @sinbai, I left responses to some of the comments. Unless there is some additional evidence that this is an entirely new product, I still think this should be added to the cosmosdb
service package instead of creating a new mongocluster
service package.
Community Note
Description
New resource
azurerm_mongo_cluster
.Swagger:https://github.com/Azure/azure-rest-api-specs/blob/15b16d1b5c3cccdecdd1cfe936f6a8005680c557/specification/mongocluster/resource-manager/Microsoft.DocumentDB/stable/2024-07-01/mongoCluster.json#L279
PR Checklist
For example: “
resource_name_here
- description of change e.g. adding propertynew_property_name_here
”Changes to existing Resource / Data Source
Testing
Test results:
Change Log
Below please provide what should go into the changelog (if anything) conforming to the Changelog Format documented here.
azurerm_mongo_cluster
- New resourceazurerm_mongo_cluster
[Support for CosmosDb for Mongodb vcore #24161]This is a (please select all that apply):
Related Issue(s)
Fixes #24161