azurerm_cosmosdb_mongo_collection - fix resource creation and update by adjusting '_id' index specification #26687
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Community Note
Description
Underlying Azure REST API does not accept
unique
property for_id
index specification. This index is always unique by design and API call fails when this property is set to either true or false. This causes issues whenunique
field is set in Terraform configuration file - both true and false values result in a failure duringazurerm_cosmosdb_mongo_collection
resource creation.Existing behavior during resource creation:
_id
index'sunique
property is set totrue
orfalse
, then resource creation fails withThe field 'unique' is not valid for _id index specification.
message. This is exactly this issue: Mongo collection not supporting unique field on _id index #24853_id
index'sunique
property is not set, then resource is created successfully (with unique_id
index, despite the default for thisunique
property beingfalse
)Existing behavior during resource update:
terraform plan
shows thatunique
property is currentlytrue
but needs to be changed tofalse
(as it's the default value). Runningterraform apply
is successful, but it does not change anything in Azure and does not fix invalid terraform state, resulting in repeating this behavior each timeterraform plan
is executed, as described in landintrees's comment and BosBer's comment_id
index'sunique
property is changed totrue
, thenterraform plan
outputs no changes to be made._id
index'sunique
property is changed tofalse
, thenterraform apply
fails withThe field 'unique' is not valid for _id index specification.
message.Expected behavior during resource creation:
_id
index'sunique
property is not set or set tofalse
, then resource creation fails withindex with '_id' key and 'unique' property set to true is required
message._id
index'sunique
property is set totrue
, then resource is created successfully.Expected behavior during resource update:
_id
index'sunique
property is not set or set tofalse
, thenterraform plan
fails withindex with '_id' key and 'unique' property set to true is required
message._id
index'sunique
property is still set totrue
, thenterraform plan
outputs no changes to be made.PR Checklist
For example: “
resource_name_here
- description of change e.g. adding propertynew_property_name_here
”Changes to existing Resource / Data Source
Testing
Change Log
Below please provide what should go into the changelog (if anything) conforming to the Changelog Format documented here.
azurerm_resource
- support for thething1
property [GH-00000]This is a (please select all that apply):
Related Issue(s)
Fixes #24853
Note
If this PR changes meaningfully during the course of review please update the title and description as required.