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

Updates and bug fixes to azurerm_cosmosdb_account #1055

Merged
merged 14 commits into from
Apr 17, 2018

Conversation

katbyte
Copy link
Collaborator

@katbyte katbyte commented Apr 2, 2018

reviewed and improved azurerm_cosmosdb_account:

  • Added new field enable_automatic_failover
  • Now exports endpoint, read_enpoints and write_endpoints
  • failover_policy has been renamed to geo_locations to better match the API & portal terms
  • replication locations can now be renamed and have their failover_priority change (except for the primary location)
  • properties can now be changed at the same time replication locations are added
  • replication location ID's can now be set via the prefix attribute customizing their endpoints
  • consistency_policy is now a list so its attributes can be referenced
  • added additional input validation
  • now supports ConsistentPrefix consistency level

Also added more comprehensive tests and an cosmos-db example

@tombuildsstuff tombuildsstuff modified the milestones: 1.3.2, 1.3.3 Apr 4, 2018
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.

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),
Copy link
Contributor

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?

Copy link
Collaborator Author

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",
Copy link
Contributor

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)
Copy link
Contributor

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

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)
Copy link
Contributor

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))
Copy link
Contributor

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?

Copy link
Collaborator Author

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,
Copy link
Contributor

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?

Copy link
Collaborator Author

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 12,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 101000000. Defaults to `100`. Required when `consistency_level` is set to `BoundedStaleness`.
Copy link
Contributor

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

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

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?

Copy link
Collaborator Author

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.

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.

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)
Copy link
Contributor

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))
Copy link
Contributor

Choose a reason for hiding this comment

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

can we revert this?

@katbyte
Copy link
Collaborator Author

katbyte commented Apr 17, 2018

Thanks!

Running tests against the proper changeset revealed some regressions: flattenAndSetTags() was lost in the merge and if we set both failover_policy and geo_location all tests fail due to never ending plans. Reverted both these and re-ran the acceptance tests.

@katbyte
Copy link
Collaborator Author

katbyte commented Apr 17, 2018

Tests pass:
screen shot 2018-04-17 at 01 43 34

@katbyte katbyte modified the milestones: 1.3.3, 1.4.0 Apr 17, 2018
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))
Copy link
Contributor

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))
}
Copy link
Contributor

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 👍

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.

LGTM 👍

@tombuildsstuff tombuildsstuff modified the milestones: 1.4.0, Temp/To Be Sorted Apr 17, 2018
@tombuildsstuff tombuildsstuff merged commit 8f474d4 into master Apr 17, 2018
@tombuildsstuff tombuildsstuff deleted the cosmosdb_account_updates branch April 17, 2018 14:12
tombuildsstuff added a commit that referenced this pull request Apr 17, 2018
@ghost
Copy link

ghost commented Mar 31, 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 Mar 31, 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.

2 participants