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_cosmosdb_mongo_collection, azurerm_cosmosdb_mongo_database - support configuring throughput #4620

Closed
wants to merge 5 commits into from

Conversation

e96wic
Copy link

@e96wic e96wic commented Oct 15, 2019

No description provided.

@e96wic
Copy link
Author

e96wic commented Oct 15, 2019

Changes functionality of 0caed50

@e96wic e96wic marked this pull request as ready for review October 15, 2019 11:19
@katbyte
Copy link
Collaborator

katbyte commented Oct 21, 2019

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?

@e96wic
Copy link
Author

e96wic commented Oct 21, 2019

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!

@ghost ghost removed the waiting-response label Oct 21, 2019
@katbyte
Copy link
Collaborator

katbyte commented Oct 21, 2019

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?)

@katbyte
Copy link
Collaborator

katbyte commented Oct 21, 2019

@e96wic

Copy link
Collaborator

@katbyte katbyte left a comment

Choose a reason for hiding this comment

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

@e96wic,

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?

website/docs/r/cosmosdb_mongo_database.html.markdown Outdated Show resolved Hide resolved
website/docs/r/cosmosdb_mongo_collection.html.markdown Outdated Show resolved Hide resolved
Comment on lines 142 to 154
} else if dbHasThroughputConfigured {
createUpdateOptions["throughput"] = utils.String(strconv.Itoa(throughput))
}
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 we'll need to change this to

Suggested change
} else if dbHasThroughputConfigured {
createUpdateOptions["throughput"] = utils.String(strconv.Itoa(throughput))
}
if hasThroughput {
createUpdateOptions["throughput"] = utils.String(strconv.Itoa(throughput))
}

Copy link
Author

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?

Copy link
Author

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

azurerm/resource_arm_cosmosdb_mongo_collection.go Outdated Show resolved Hide resolved
}
throughputFuture, err := client.UpdateMongoDBCollectionThroughput(ctx, resourceGroup, account, database, name, throughputParameters)
if err != nil {
_ = d.Set("throughput", nil)
Copy link
Collaborator

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,
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 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

Copy link
Author

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.

Copy link
Author

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 ?

Copy link
Contributor

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

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 your correct, at worst the user will just have a plan with no affect.

azurerm/resource_arm_cosmosdb_mongo_database.go Outdated Show resolved Hide resolved
Comment on lines 176 to 177
_ = d.Set("resource_group_name", id.ResourceGroup)
_ = d.Set("account_name", id.Account)
Copy link
Collaborator

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

Suggested change
_ = d.Set("resource_group_name", id.ResourceGroup)
_ = d.Set("account_name", id.Account)
d.Set("account_name", id.Account)

azurerm/resource_arm_cosmosdb_mongo_database.go Outdated Show resolved Hide resolved
azurerm/resource_arm_cosmosdb_mongo_database.go Outdated Show resolved Hide resolved
@k-k
Copy link
Contributor

k-k commented Oct 24, 2019

@e96wic Thanks for this follow up

@katbyte Once this PR is resolved, I'll use it for the basis of fixing #4616

@ghost ghost removed the waiting-response label Oct 24, 2019
@e96wic
Copy link
Author

e96wic commented Oct 26, 2019

@katbyte Could you have another look at this PR? :)

Copy link
Collaborator

@katbyte katbyte left a 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

@e96wic e96wic requested a review from katbyte November 9, 2019 23:41
@e96wic
Copy link
Author

e96wic commented Nov 9, 2019

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.

@ghost ghost removed the waiting-response label Nov 9, 2019
@katbyte katbyte changed the title Cosmos db throughput azurerm_cosmosdb_mongo_collection, azurerm_cosmosdb_mongo_database - support configuring throughput Nov 10, 2019
Copy link
Collaborator

@katbyte katbyte left a 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,
Copy link
Collaborator

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.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we make this

Suggested change
* `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.
Copy link
Collaborator

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 {
Copy link
Collaborator

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

@tombuildsstuff tombuildsstuff modified the milestones: v1.37.0, v1.38.0 Nov 21, 2019
@tombuildsstuff tombuildsstuff removed this from the v1.38.0 milestone Dec 2, 2019
@katbyte
Copy link
Collaborator

katbyte commented Dec 4, 2019

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?

@katbyte
Copy link
Collaborator

katbyte commented Dec 10, 2019

Hey @e96wic, i've opened #5116 that address the comments i've made so we can get this merged. As such i am going to close this in favour of it, thanks for all your work on this change!

@katbyte katbyte closed this Dec 10, 2019
@katbyte katbyte added this to the v1.39.0 milestone Dec 10, 2019
katbyte added a commit that referenced this pull request Dec 11, 2019
@ghost
Copy link

ghost commented Dec 16, 2019

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 ...

@ghost ghost removed the waiting-response label Dec 16, 2019
@ghost
Copy link

ghost commented Jan 9, 2020

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!

@ghost ghost locked and limited conversation to collaborators Jan 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants