-
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
azurerm_cosmosdb_mongo_collection, azurerm_cosmosdb_mongo_database - support configuring throughput #4620
Conversation
Changes functionality of 0caed50 |
hi @e96wic, I don't think silently recreating the DB is the best user experience here. We are discussing this in #4616 and i think we should instead error with a message saying the resource needs to be recreated by hand linking to an issue on the azure-for-go SDK detailing the limitation of the API (it does sound like a bug on their end) WDYT? |
Hi @katbyte, where do you think I'm recreating the DB - can you point me to the code? I totally agree with you, silently recreating resources is a bad idea! |
whoops 😅 i totally am misremembering this PR from last week. Your entirely right, i will give it a closer look later today/tomorrow. It looks like you arebasicallyy doing what was suggested already by adding in some guards and removing the default throughput (which i can now see would cause some problems?) |
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've left some comments inline, overall this is looking great. Thanks for fixing this. I am concerned about a breaking change by making the schema default, however i think it should be fine as if its not configured it'll be ignored, otherwise a user will get a plan on upgrade. WDYT?
} else if dbHasThroughputConfigured { | ||
createUpdateOptions["throughput"] = utils.String(strconv.Itoa(throughput)) | ||
} |
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 we'll need to change this to
} else if dbHasThroughputConfigured { | |
createUpdateOptions["throughput"] = utils.String(strconv.Itoa(throughput)) | |
} | |
if hasThroughput { | |
createUpdateOptions["throughput"] = utils.String(strconv.Itoa(throughput)) | |
} |
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.
looks correct, but don't we update the resource when executing "terraform import" with the current logic?
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.
manual tests did not show what I was assuming so I guess it's fine
} | ||
throughputFuture, err := client.UpdateMongoDBCollectionThroughput(ctx, resourceGroup, account, database, name, throughputParameters) | ||
if err != nil { | ||
_ = d.Set("throughput", 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.
Why are you setting this to nil?
@@ -78,7 +80,7 @@ func resourceArmCosmosDbMongoCollection() *schema.Resource { | |||
"throughput": { | |||
Type: schema.TypeInt, | |||
Optional: true, | |||
Default: 400, | |||
Default: 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.
I think this will technically be a breaking change? While i agree we should make the change i'm not sure we can until 2.0 where we break/change schema
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.
That is a good question. If I'm correct it should not break anyones code / resources.
Case 1 - user had no throughput configured for existing resource -> terraform won't re-apply the throughput meaning it won't override whatever is configured in azure.
Case 2 - user creates a new resource -> will be created with the azure default (which should be 1000)
Case 3 - user had throughput configured -> will use that value
In the past my team had quite some trouble with newly added parameters with default values. In some cases it destroyed resources for us. In this case setting the throughput to a default of 400 might scale down collections for users which had them previously configured in terraform, but scaled via azure directly. If users roll their terraform config out automatically this is dangerous.
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.
What do you think, @katbyte ?
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.
Documentation and testing showed 400 being the azure default - but I do agree that defaulting to nil
here probably makes more sense
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 your correct, at worst the user will just have a plan with no affect.
_ = d.Set("resource_group_name", id.ResourceGroup) | ||
_ = d.Set("account_name", id.Account) |
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 the assingment
_ = d.Set("resource_group_name", id.ResourceGroup) | |
_ = d.Set("account_name", id.Account) | |
d.Set("account_name", id.Account) |
@katbyte Could you have another look at this PR? :) |
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 @e96wic,
Thanks for making those revisions, but looks like we are getting some test failures:
------- Stdout: -------
=== RUN TestAccAzureRMCosmosDbMongoCollection_basic
=== PAUSE TestAccAzureRMCosmosDbMongoCollection_basic
=== CONT TestAccAzureRMCosmosDbMongoCollection_basic
--- FAIL: TestAccAzureRMCosmosDbMongoCollection_basic (1125.66s)
testing.go:569: Step 0 error: After applying this step, the plan was not empty:
DIFF:
UPDATE: azurerm_cosmosdb_mongo_collection.test
account_name: "acctest-191028043915315190" => "acctest-191028043915315190"
database_name: "acctest-191028043915315190" => "acctest-191028043915315190"
default_ttl_seconds: "0" => "0"
id: "/subscriptions/1a6092a6-137e-4025-9a7c-ef77f76f2c02/resourceGroups/acctestRG-191028043915315190/providers/Microsoft.DocumentDB/databaseAccounts/acctest-191028043915315190/apis/mongodb/databases/acctest-191028043915315190/collections/acctest-191028043915315190" => "/subscriptions/1a6092a6-137e-4025-9a7c-ef77f76f2c02/resourceGroups/acctestRG-191028043915315190/providers/Microsoft.DocumentDB/databaseAccounts/acctest-191028043915315190/apis/mongodb/databases/acctest-191028043915315190/collections/acctest-191028043915315190"
indexes.#: "0" => "0"
name: "acctest-191028043915315190" => "acctest-191028043915315190"
resource_group_name: "acctestRG-191028043915315190" => "acctestRG-191028043915315190"
throughput: "400" => ""
you may have to simply not pull in the throughput if its not been set
Hi @katbyte, the failing acceptance test actually indicated the desired behavior. The import test step failed because the config did not have throughput configured. Azure sets a default throughput though, which will be imported to the state by my changes. |
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 @e96wic,
That failing test indicates a perpetual diff when no throughput is specified, so we will need to make sure that test step passes (the rest fail do to a change in the API causing a diff with indexes)
Also we'll need to write a complete test for the database resource & an update test to ensure the throughput can be updated if included on creation.
), | ||
ExpectNonEmptyPlan: 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.
We shouldn't need this, could we remove this and make the test pass?
@@ -36,6 +37,8 @@ The following arguments are supported: | |||
|
|||
* `account_name` - (Required) The name of the Cosmos DB Mongo Database to create the table within. Changing this forces a new resource to be created. | |||
|
|||
* `throughput` - (Optional) The throughput of the MongoDB collection (RU/s). Must be set in increments of `100`. The minimum value is `400`. This must be set upon database creation otherwise it cannot be updated without a manual terraform destroy-apply. |
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 we make this
* `throughput` - (Optional) The throughput of the MongoDB collection (RU/s). Must be set in increments of `100`. The minimum value is `400`. This must be set upon database creation otherwise it cannot be updated without a manual terraform destroy-apply. | |
* `throughput` - (Optional) The throughput of the MongoDB collection (RU/s). Must be set in increments of `100`, and defaults to `400`. | |
-> **NOTE:** The minimum value is `400`. This must be set upon database creation otherwise it cannot be updated without a manual terraform destroy-apply. |
@@ -56,7 +56,7 @@ The following arguments are supported: | |||
* `database_name` - (Required) The name of the Cosmos DB Mongo Database in which the Cosmos DB Mongo Collection is created. Changing this forces a new resource to be created. | |||
* `default_ttl_seconds` - (Required) The default Time To Live in seconds. If the value is `-1` items are not automatically expired. | |||
* `shard_key` - (Required) The name of the key to partition on for sharding. There must not be any other unique index keys. | |||
* `throughput` - (Optional) The throughput of the MongoDB collection (RU/s). Must be set in increments of `100`. The default and minimum value is `400`. | |||
* `throughput` - (Optional) The throughput of the MongoDB collection (RU/s). Must be set in increments of `100`. The minimum value is `400`. This must be set upon database creation otherwise it cannot be updated without a manual terraform destroy-apply. |
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.
see my other comment
}, | ||
} | ||
} | ||
|
||
func resourceArmCosmosDbMongoDatabaseCreate(d *schema.ResourceData, meta interface{}) error { | ||
func resourceArmCosmosDbMongoDatabaseCreateUpdate(d *schema.ResourceData, meta interface{}) error { |
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 we use separate create and update functions? i think it'll simplify things a tad
hi @e96wic, I am looking into finishing this and it doesn't appear i have permission to push to your branch. Are you still working on this or should i go ahead and open a new PR? |
This has been released in version 1.39.0 of the provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. As an example: provider "azurerm" {
version = "~> 1.39.0"
}
# ... other configuration ... |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks! |
No description provided.