-
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
Updates and bug fixes to azurerm_cosmosdb_account #1055
Conversation
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.
a few (mostly minor) comments - but this is looking good :)
}, | ||
|
||
"max_staleness_prefix": { | ||
Type: schema.TypeInt, | ||
Optional: true, | ||
Default: 100, | ||
ValidateFunc: validation.IntBetween(1, 2147483647), | ||
ValidateFunc: validation.IntBetween(10, 1000000), |
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.
is there some context for this value change? the older values came from either the Portal or the API Docs, but IIRC where there are different values for DocumentDB and CosmosDB?
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'm not sure where it came from! 2147483647 is the maximum value the API returns.
Required: true, | ||
Type: schema.TypeSet, | ||
Optional: true, | ||
Deprecated: "This field has been renamed to 'geo_location' to better match the SDK/API", |
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'd suggest this becomes "This field has been renamed to 'geo_location' to match Azure's usage"
} | ||
} else { | ||
//could be a CustomizeDiff?, but this is temporary | ||
return fmt.Errorf("Neither `geo_location` or `failover_policy` is set for CosmosDB Account '%s'", name) |
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 is fine providing it's called out in the docs
flattenAndSetAzureRmCosmosDBAccountFailoverPolicy(d, resp.FailoverPolicies) | ||
} else { | ||
//if failover policy isn't default to using geo_location | ||
if err := flattenAndSetAzureRmCosmosDBAccountGeoLocations(d, resp); err != 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.
can we make this flatten and have the Set handled here? Unfortunately tags is a bad example that should be refactored at some point tbh
flattenAndSetAzureRmCosmosDBAccountConsistencyPolicy(d, resp.ConsistencyPolicy) | ||
flattenAndSetAzureRmCosmosDBAccountFailoverPolicy(d, resp.FailoverPolicies) | ||
if _, ok := d.GetOk("failover_policy"); ok { | ||
flattenAndSetAzureRmCosmosDBAccountFailoverPolicy(d, resp.FailoverPolicies) |
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.
can we make this flatten and have the Set handled here? Unfortunately tags is a bad example that should be refactored at some point tbh
|
||
buf.WriteString(fmt.Sprintf("%s-%d-%d", consistencyLevel, maxInterval, maxStalenessPrefix)) | ||
buf.WriteString(fmt.Sprintf("-%s-%d", location, priority)) |
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.
if we're changing the hash value I think we'll need a state migration here?
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.
Good spot, the -
got in there by accident.
@@ -65,8 +73,13 @@ func resourceArmCosmosDBAccount() *schema.Resource { | |||
Optional: true, | |||
}, | |||
|
|||
"enable_automatic_failover": { | |||
Type: schema.TypeBool, | |||
Optional: 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.
since this'll be false
if it's not specified, should we default this to a value or make it required?
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.
When created via the portal its not required and seems to default to false
.
* `max_staleness_prefix` - (Optional) When used with the Bounded Staleness consistency level, this value represents the number of stale requests tolerated. Accepted range for this value is 1 – 2,147,483,647. Defaults to `100`. Required when `consistency_level` is set to `BoundedStaleness`. | ||
* `consistency_level` - (Required) The Consistency Level to use for this CosmosDB Account - can be either `BoundedStaleness`, `Eventual`, `Session`, `Strong` or `ConsistentPrefix`. | ||
* `max_interval_in_seconds` - (Optional) When used with the Bounded Staleness consistency level, this value represents the time amount of staleness (in seconds) tolerated. Accepted range for this value is 5 - 86400 (1 day). Defaults to `5`. Required when `consistency_level` is set to `BoundedStaleness`. | ||
* `max_staleness_prefix` - (Optional) When used with the Bounded Staleness consistency level, this value represents the number of stale requests tolerated. Accepted range for this value is 10 – 1000000. Defaults to `100`. Required when `consistency_level` is set to `BoundedStaleness`. |
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.
minor can we quote
these values?
* `location` - (Required) The name of the Azure region to host replicated data. | ||
* `priority` - (Required) The failover priority of the region. A failover priority of 0 indicates a write region. The maximum value for a failover priority = (total number of regions - 1). Failover priority values must be unique for each of the regions in which the database account exists. | ||
* `priority` - (Required) The failover priority of the region. A failover priority of 0 indicates a write region. The maximum value for a failover priority = (total number of regions - 1). Failover priority values must be unique for each of the regions in which the database account exists. Changing this causes the location to be re-provisioned and cannot be changed for the location with failover priority 0. |
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.
cannot be changed for the location with failover priority 0.
may make sense as an info box? e.g. -> **NOTE:** cannot be changed for the location with failover priority 0.
|
||
* `read_endpoints` - A list of read endpoints available for this CosmosDB account. | ||
|
||
* `write_endpoints` - A list of write endpoints available for this CosmosDB 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.
if there's only one of these should we make this a string?
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.
The API returns an array of locations, not sure if there will ever be more then one however.
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 a couple of minor things (which I'll push a commit to fix) - but this otherwise LGTM 👍
Given this includes a deprecation, let's merge this once 1.3.3 is released?
if err != nil { | ||
return err | ||
return fmt.Errorf("Error creating/updating CosmosDB Account %q (Resource Group %q): %+v", name, resourceGroup, err) |
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.
minor technically this is only creating, but it's fine
if location := resp.Location; location != nil { | ||
d.Set("location", azureRMNormalizeLocation(*location)) | ||
} | ||
d.Set("location", azureRMNormalizeLocation(*resp.Location)) |
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.
can we revert this?
…_location on read, resulted in endless plans
Thanks! Running tests against the proper changeset revealed some regressions: |
d.Set("failover_policy", flattenAzureRmCosmosDBAccountFailoverPolicy(resp.FailoverPolicies)) | ||
} else { | ||
//if failover policy isn't default to using geo_location | ||
d.Set("geo_location", flattenAzureRmCosmosDBAccountGeoLocations(d, resp)) |
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'll push a commit to raise the errors if there's a failure here - this otherwise LGTM 👍
d.Set("failover_policy", flattenAzureRmCosmosDBAccountFailoverPolicy(resp.FailoverPolicies)) | ||
} else { | ||
//if failover policy isn't default to using geo_location | ||
d.Set("geo_location", flattenAzureRmCosmosDBAccountGeoLocations(d, resp)) | ||
} |
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'll push a commit to raise the errors if there's a failure here - this otherwise LGTM 👍
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.
LGTM 👍
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! |
reviewed and improved azurerm_cosmosdb_account:
enable_automatic_failover
endpoint
,read_enpoints
andwrite_endpoints
failover_policy
has been renamed togeo_locations
to better match the API & portal termsfailover_priority
change (except for the primary location)prefix
attribute customizing their endpointsconsistency_policy
is now a list so its attributes can be referencedConsistentPrefix
consistency levelAlso added more comprehensive tests and an
cosmos-db
example