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

cosmosdb_mongo_collection - support index & system_index #6426

Merged
merged 15 commits into from Apr 21, 2020

Conversation

neil-yechenwei
Copy link
Contributor

@neil-yechenwei neil-yechenwei commented Apr 9, 2020

Fix the issue of #4460

Fixes #4460

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 @neil-yechenwei,

it looks like you're not setting the index back on read? thence why you are having to do the import ignore. We should reading these back and ignoring the system ones?

@neil-yechenwei
Copy link
Contributor Author

neil-yechenwei commented Apr 11, 2020

@katbyte , after tested previously, I found some system keys can be updated and some system keys cannot be updated. So I think maybe we cannot simply ignore all system keys, right? After checked azure cli and powershell for this resource, seems they also didn't ignore system keys but expose all keys to user. So I think we can align with them. Does it make sense?

@ghost ghost removed the waiting-response label Apr 11, 2020
@katbyte
Copy link
Collaborator

katbyte commented Apr 12, 2020

@neil-yechenwei - however we do it, maybe separate index and a computed index_system properties, we should always reading all properties back on read.

@ghost ghost added size/L and removed size/M labels Apr 13, 2020
@neil-yechenwei
Copy link
Contributor Author

neil-yechenwei commented Apr 13, 2020

@katbyte , because some system indexes can be updated. So if I move them to computed index_system property, it would cause diff on index property. So seems I cannot do this. After double confirmed with service owner, seems only system indexes "_id" and "DocumentDBDefaultIndex" cannot be updated, other system indexes can be updated. So I ignore them. See my updated code.

@ghost ghost removed the waiting-response label Apr 13, 2020
@ghost ghost added size/M and removed size/L labels Apr 13, 2020
@katbyte
Copy link
Collaborator

katbyte commented Apr 14, 2020

@neil-yechenwei, we should always be reading in the values the user can set. weather we seperate user settable and system into indexes & a computed system_indexes ot just ignore the system ones we should be ensure the user's are read back in from the API.

@neil-yechenwei
Copy link
Contributor Author

neil-yechenwei commented Apr 14, 2020

@katbyte , I've updated code to move user settable indexes which include user customized index and settable system index into property "index" and move system indexes which are not settable into a computed "system_index"

@ghost ghost removed the waiting-response label Apr 14, 2020
@ghost ghost removed the size/M label Apr 14, 2020
@ghost ghost added the size/L label Apr 14, 2020
@katbyte katbyte changed the title Support index for cosmosdb cosmosdb_mongo_collection - support index & system_index Apr 15, 2020
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.

Thanks for the changes @neil-yechenwei,

Just one minor comment inline otherwise this LGTM!

},
},

"system_index": {
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 should be system_indexes as it'll never be used as seperate blocks?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

@katbyte katbyte added this to the v2.6.0 milestone Apr 15, 2020
@neil-yechenwei
Copy link
Contributor Author

@katbyte , thanks for your comments. I've updated code.

@ghost ghost removed the waiting-response label Apr 15, 2020
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.

Thanks @neil-yechenwei! LGTM now 👍

Copy link
Member

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

hi @neil-yechenwei

Thanks for pushing those changes - I've taken a look and left some comments inline - but if we can fix those up then this otherwise LGTM

Thanks!

@@ -264,7 +303,16 @@ func resourceArmCosmosDbMongoCollectionRead(d *schema.ResourceData, meta interfa
}

if props.Indexes != nil {
Copy link
Member

Choose a reason for hiding this comment

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

we need to ensure these fields are always set, so we can remove the if statement here, since the flatten function should handle these being nil

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

for _, i := range *indexes {
if key := i.Key; key != nil {
var ttlInner int32
func flattenCosmosMongoCollectionIndex(input *[]documentdb.MongoIndex) (*[]map[string]interface{}, *[]map[string]interface{}, *int32) {
Copy link
Member

Choose a reason for hiding this comment

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

this method needs to account for input being nil here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

systemIndex := map[string]interface{}{}

if v.Key != nil && v.Key.Keys != nil {
key := (*v.Key.Keys)[0]
Copy link
Member

Choose a reason for hiding this comment

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

there's a crash here if there's 0 items in this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated


* `keys` - The list of system keys which are not settable for each Cosmos DB Mongo Collection.

* `unique` - The unique status of the index.
Copy link
Member

Choose a reason for hiding this comment

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

can we add a better description here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

@tombuildsstuff tombuildsstuff modified the milestones: v2.6.0, v2.7.0 Apr 16, 2020
@neil-yechenwei
Copy link
Contributor Author

@tombuildsstuff , thanks for your comments. I've updated code.

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.

Thanks @neil-yechenwei! LGTM 👍

@katbyte katbyte merged commit 4dc6fdd into hashicorp:master Apr 21, 2020
katbyte added a commit that referenced this pull request Apr 21, 2020
@ghost
Copy link

ghost commented Apr 23, 2020

This has been released in version 2.7.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.7.0"
}
# ... other configuration ...

@ghost
Copy link

ghost commented May 21, 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!

@hashicorp hashicorp locked and limited conversation to collaborators May 21, 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.

azurerm_cosmosdb_mongo_collection does not seem to allow compound indexes
4 participants