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

Add composite indexes support to CosmosDB SQL container #8792

Merged
merged 27 commits into from
Oct 19, 2020
Merged

Add composite indexes support to CosmosDB SQL container #8792

merged 27 commits into from
Oct 19, 2020

Conversation

favoretti
Copy link
Collaborator

Fixes #8762

@ghost ghost added the size/M label Oct 8, 2020
@ghost ghost added the documentation label Oct 8, 2020
@ghost ghost added size/L and removed size/M labels Oct 8, 2020
@favoretti favoretti marked this pull request as draft October 8, 2020 18:10
@favoretti
Copy link
Collaborator Author

$ TF_ACC=1 go test -v ./azurerm/internal/services/cosmos/ -timeout=600m -run=TestAccAzureRMCosmosDbSqlContainer_complete
=== RUN   TestAccAzureRMCosmosDbSqlContainer_complete
=== PAUSE TestAccAzureRMCosmosDbSqlContainer_complete
=== CONT  TestAccAzureRMCosmosDbSqlContainer_complete
--- PASS: TestAccAzureRMCosmosDbSqlContainer_complete (1447.26s)
PASS
ok  	github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/cosmos	1448.461s

$ TF_ACC=1 go test -v ./azurerm/internal/services/cosmos/ -timeout=600m -run=TestAccAzureRMCosmosDbSqlContainer_indexing_policy
=== RUN   TestAccAzureRMCosmosDbSqlContainer_indexing_policy
=== PAUSE TestAccAzureRMCosmosDbSqlContainer_indexing_policy
=== CONT  TestAccAzureRMCosmosDbSqlContainer_indexing_policy
--- PASS: TestAccAzureRMCosmosDbSqlContainer_indexing_policy (1588.70s)
PASS
ok  	github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/cosmos	1589.996s

@tombuildsstuff I think this should be ready for a review now. Thanks!

Copy link
Contributor

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

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

hey @favoretti

Thanks for pushing those changes - taking a look through I've left a couple of other comments but this otherwise LGTM 👍

Thanks!

azurerm/internal/services/cosmos/common/schema.go Outdated Show resolved Hide resolved
azurerm/internal/services/cosmos/common/indexing_policy.go Outdated Show resolved Hide resolved
azurerm/internal/services/cosmos/common/indexing_policy.go Outdated Show resolved Hide resolved
azurerm/internal/services/cosmos/common/schema.go Outdated Show resolved Hide resolved
website/docs/r/cosmosdb_sql_container.html.markdown Outdated Show resolved Hide resolved
@tombuildsstuff tombuildsstuff added this to the v2.32.0 milestone Oct 14, 2020
@favoretti
Copy link
Collaborator Author

@tombuildsstuff Thank you, great comments for me to learn off. Committed all.

Copy link
Contributor

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

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

two minor things but this is otherwise good 👍

azurerm/internal/services/cosmos/common/indexing_policy.go Outdated Show resolved Hide resolved
azurerm/internal/services/cosmos/common/schema.go Outdated Show resolved Hide resolved
@jackofallops
Copy link
Member

Hi @favoretti - I had a quick pass at fixing up a couple items to try and get this into today's release, but it looks like there's a casing bug in the API for reading back the order property which is causing a Diff. We'll need to open an issue on the api-specs repo and possibly look at a workaround to get this in for the next release.

@jackofallops jackofallops modified the milestones: v2.32.0, v2.33.0 Oct 15, 2020
@favoretti
Copy link
Collaborator Author

@jackofallops ouch, that's not good. As a workaround we can just lowercase it all over the place when comparing?

@jackofallops
Copy link
Member

@jackofallops ouch, that's not good. As a workaround we can just lowercase it all over the place when comparing?

Probably best to check the string value in the flatten and set the correctly cased value for the state there?

Test output (clipped) demonstrating the issue:

DIFF:
UPDATE: azurerm_cosmosdb_sql_container.test
account_name:                                      "acctest-ca-201015133402551728" => "acctest-ca-201015133402551728"
autoscale_settings.#:                              "0" => "0"
database_name:                                     "acctest-201015133402551728" => "acctest-201015133402551728"
default_ttl:                                       "500" => "500"
id:                                                "/subscriptions/*******/resourceGroups/acctestRG-cosmos-201015133402551728/providers/Microsoft.DocumentDB/databaseAccounts/acctest-ca-201015133402551728/sqlDatabases/acctest-201015133402551728/containers/acctest-CSQLC-201015133402551728" => "/subscriptions/*******/resourceGroups/acctestRG-cosmos-201015133402551728/providers/Microsoft.DocumentDB/databaseAccounts/acctest-ca-201015133402551728/sqlDatabases/acctest-201015133402551728/containers/acctest-CSQLC-201015133402551728"
indexing_policy.#:                                 "1" => "1"
indexing_policy.0.composite_index.#:               "2" => "2"
indexing_policy.0.composite_index.0.index.#:       "2" => "2"
indexing_policy.0.composite_index.0.index.0.order: "descending" => "Descending"
indexing_policy.0.composite_index.0.index.0.path:  "/path1" => "/path1"
indexing_policy.0.composite_index.0.index.1.order: "ascending" => "Ascending"

@favoretti
Copy link
Collaborator Author

favoretti commented Oct 15, 2020

@jackofallops Would something like this work?

index a2539bf50..eaa5e2c4c 100644
--- a/azurerm/internal/services/cosmos/common/indexing_policy.go
+++ b/azurerm/internal/services/cosmos/common/indexing_policy.go
@@ -2,6 +2,7 @@ package common

 import (
        "fmt"
+ "strings"

        "github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2020-04-01/documentdb"
        "github.com/hashicorp/terraform-plugin-sdk/helper/schema"
@@ -123,7 +124,7 @@ func flattenCosmosDBIndexingPolicyCompositeIndex(input []documentdb.CompositePat

                block := make(map[string]interface{})
                block["path"] = path
-           block["order"] = v.Order
+           block["order"] = strings.Title(string(v.Order))
                indexPairs = append(indexPairs, block)
        }

If you're ok with it - I'll push.

@jackofallops
Copy link
Member

At first glance that should be OK, would be worth running the TestAccAzureRMCosmosDbSqlContainer_complete test before pushing though if you can?
Could you also add a comment that it's a workaround for an API issue, I've created it here: Azure/azure-rest-api-specs#11222

@favoretti
Copy link
Collaborator Author

@jackofallops Seems to work:

[17:12:16](⎈ |eastus2-fxs-ops-fxc:ops)➜  terraform-providers/terraform-provider-azurerm git:(favoretti/composite_indexes) ✗ $ TF_ACC=1 go test -v ./azurerm/internal/services/cosmos/ -timeout=600m -run=TestAccAzureRMCosmosDbSqlContainer_complete
=== RUN   TestAccAzureRMCosmosDbSqlContainer_complete
=== PAUSE TestAccAzureRMCosmosDbSqlContainer_complete
=== CONT  TestAccAzureRMCosmosDbSqlContainer_complete
--- PASS: TestAccAzureRMCosmosDbSqlContainer_complete (1345.15s)
PASS
ok  	github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/cosmos	1346.355s
[17:35:59](⎈ |eastus2-fxs-ops-fxc:ops)➜  terraform-providers/terraform-provider-azurerm git:(favoretti/composite_indexes) ✗ $

@jackofallops
Copy link
Member

Tests passing:
image

@jackofallops jackofallops merged commit e584f97 into hashicorp:master Oct 19, 2020
jackofallops added a commit that referenced this pull request Oct 19, 2020
@ghost
Copy link

ghost commented Oct 22, 2020

This has been released in version 2.33.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 = "~> 2.33.0"
}
# ... other configuration ...

@ghost
Copy link

ghost commented Nov 18, 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 👉 [email protected]. Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators Nov 18, 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.

Support for composite indexes in azurerm_cosmosdb_sql_container
3 participants