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

Update Azure Cosmos DB API to to 2020-04-01 from 2015-04-08 #7597

Merged
merged 43 commits into from
Jul 20, 2020
Merged
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
de2cf8e
Upgrade CosmosDB SDK to 2019-08-01 from 2015-04-08
jackbatzner Mar 25, 2020
07cc41a
Parse new and old SDK IDs.
jackbatzner Mar 26, 2020
d9a4cbf
Update import statements to reflect new API Resource ID
jackbatzner Mar 26, 2020
91569d2
Properly reference old SDK Resource IDs
jackbatzner Mar 26, 2020
8a73962
Properly retrieve Gremlin Graph
jackbatzner Mar 26, 2020
82fd2ff
Create StateMigration for old SDK to new SDK
jackbatzner Mar 26, 2020
fce09bd
Format error messages
jackbatzner Mar 26, 2020
feefa15
Create common helper for getting throughput value
jackbatzner Mar 26, 2020
cd690af
Properly generate error when importing ID
jackbatzner Mar 26, 2020
23f2995
fix migration logic
katbyte Apr 15, 2020
00e3be4
Get latest version of Cosmos SDK
jackbatzner Apr 15, 2020
48bcaf6
Clean up duplicate resources
marc-sensenich Jul 7, 2020
ce39a50
Update Cosmos DB SDK to 2020-04-01
marc-sensenich Jul 7, 2020
71b202f
Add common Cosmos utility for IPRules to IPFilter changes
marc-sensenich Jul 7, 2020
c615726
fixup! Clean up duplicate resources
marc-sensenich Jul 7, 2020
108e58c
Update Azure Cosmos DB Resources and Data Source to 2020-04-01
marc-sensenich Jul 7, 2020
4b3769f
fixup! Update Azure Cosmos DB Resources and Data Source to 2020-04-01
marc-sensenich Jul 7, 2020
e9d9cd3
Check for 3 locations in Azure Cosmos DB Account Data Source
marc-sensenich Jul 9, 2020
d619031
Update EnableMultipleWriteLocations on Cosmos DB resource independently
marc-sensenich Jul 9, 2020
f18994b
Create utility for conversion of throughput from ResourceData
marc-sensenich Jul 9, 2020
6447ade
Run go mod tidy and go mod vendor
marc-sensenich Jul 9, 2020
a90efe0
Update Cosmos DB delete StateChangeConf Refresh check for not found
marc-sensenich Jul 10, 2020
df86b75
Update Cosmos DB EnableMultipleWriteLocations independently
marc-sensenich Jul 10, 2020
888622d
fixup! Update Cosmos DB EnableMultipleWriteLocations independently
marc-sensenich Jul 10, 2020
a016100
fixup! Update Cosmos DB EnableMultipleWriteLocations independently
marc-sensenich Jul 10, 2020
00c2ec5
fixup! Update Cosmos DB EnableMultipleWriteLocations independently
marc-sensenich Jul 10, 2020
866fc11
fixup! Update Cosmos DB EnableMultipleWriteLocations independently
marc-sensenich Jul 10, 2020
dcef797
fixup! Update Cosmos DB EnableMultipleWriteLocations independently
marc-sensenich Jul 10, 2020
de09753
fixup! Update Cosmos DB EnableMultipleWriteLocations independently
marc-sensenich Jul 10, 2020
5453fa7
fixup! Update Cosmos DB EnableMultipleWriteLocations independently
marc-sensenich Jul 10, 2020
0ad547f
Have Cosmos DB consistency tests use BoundedStaleness
marc-sensenich Jul 10, 2020
fea3123
Raise an error if staleness values are set for anything but bounded s…
marc-sensenich Jul 10, 2020
cd93826
go mod tidy and go mod vendor
marc-sensenich Jul 11, 2020
1f01cda
Update Cosmos DB EnableMultipleWriteLocations after Locations
marc-sensenich Jul 11, 2020
d6f24d8
fixup! Raise an error if staleness values are set for anything but bo…
marc-sensenich Jul 11, 2020
ec10270
Correct parameter ordering in Gremlin Graph resource tests
marc-sensenich Jul 11, 2020
d2c2a56
Utilize DiffSuppressFunc for Consistency staleness configuration
marc-sensenich Jul 11, 2020
c23b1fd
Bring in changes from #7588: Deprecate prefix property of azure_cosmo…
marc-sensenich Jul 12, 2020
6c7995b
Set Cosmos DB Mongo coolection TTL from options in flattenCosmosMongo…
marc-sensenich Jul 12, 2020
ac7ce89
fixup! Bring in changes from #7588: Deprecate prefix property of azur…
marc-sensenich Jul 12, 2020
71e649c
Align cosmosdb_mongo_collection_resource with 1e37be88d7
marc-sensenich Jul 12, 2020
1fa29d3
Fix inversion of defaults for max_staleness_prefix and max_interval_i…
marc-sensenich Jul 12, 2020
c50f049
fixup! Bring in changes from #7588: Deprecate prefix property of azur…
marc-sensenich Jul 13, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Bring in changes from #7588: Deprecate prefix property of azure_cosmo…
…sdb_account

This resolved the issue of the acceptance tests from finding all read locations
marc-sensenich committed Jul 12, 2020
commit c23b1fd9e6e19c9f12037ece923607c63a284d0d
79 changes: 18 additions & 61 deletions azurerm/internal/services/cosmos/cosmosdb_account_resource.go
Original file line number Diff line number Diff line change
@@ -160,6 +160,7 @@ func resourceArmCosmosDbAccount() *schema.Resource {
regexp.MustCompile("^[-a-z0-9]{3,50}$"),
"Cosmos DB location prefix (ID) must be 3 - 50 characters long, contain only lowercase letters, numbers and hyphens.",
),
Deprecated: "This is deprecated because the service no longer accepts this as an input since Apr 25, 2019",
},

"id": {
@@ -338,7 +339,7 @@ func resourceArmCosmosDbAccountCreate(d *schema.ResourceData, meta interface{})
return fmt.Errorf("CosmosDB Account %s already exists, please import the resource via terraform import", name)
}
}
geoLocations, err := expandAzureRmCosmosDBAccountGeoLocations(name, d)
geoLocations, err := expandAzureRmCosmosDBAccountGeoLocations(d)
if err != nil {
return fmt.Errorf("Error expanding CosmosDB Account %q (Resource Group %q) geo locations: %+v", name, resourceGroup, err)
}
@@ -407,7 +408,7 @@ func resourceArmCosmosDbAccountUpdate(d *schema.ResourceData, meta interface{})
enableAutomaticFailover := d.Get("enable_automatic_failover").(bool)
enableMultipleWriteLocations := d.Get("enable_multiple_write_locations").(bool)

newLocations, err := expandAzureRmCosmosDBAccountGeoLocations(name, d)
newLocations, err := expandAzureRmCosmosDBAccountGeoLocations(d)
if err != nil {
return fmt.Errorf("Error expanding CosmosDB Account %q (Resource Group %q) geo locations: %+v", name, resourceGroup, err)
}
@@ -445,6 +446,7 @@ func resourceArmCosmosDbAccountUpdate(d *schema.ResourceData, meta interface{})
ConsistencyPolicy: expandAzureRmCosmosDBAccountConsistencyPolicy(d),
Locations: &oldLocations,
VirtualNetworkRules: expandAzureRmCosmosDBAccountVirtualNetworkRules(d),
EnableMultipleWriteLocations: resp.EnableMultipleWriteLocations,
},
Tags: tags.Expand(t),
}
@@ -453,6 +455,14 @@ func resourceArmCosmosDbAccountUpdate(d *schema.ResourceData, meta interface{})
return fmt.Errorf("Error updating CosmosDB Account %q properties (Resource Group %q): %+v", name, resourceGroup, err)
}

// Update the property independently after the initial upsert as no other properties may change at the same time.
account.DatabaseAccountCreateUpdateProperties.EnableMultipleWriteLocations = utils.Bool(enableMultipleWriteLocations)
if *resp.EnableMultipleWriteLocations != enableMultipleWriteLocations {
if _, err = resourceArmCosmosDbAccountApiUpsert(client, ctx, resourceGroup, name, account, d); err != nil {
return fmt.Errorf("Error updating CosmosDB Account %q EnableMultipleWriteLocations (Resource Group %q): %+v", name, resourceGroup, err)
}
}

// determine if any locations have been renamed/priority reordered and remove them
removedOne := false
for _, l := range newLocations {
@@ -465,16 +475,6 @@ func resourceArmCosmosDbAccountUpdate(d *schema.ResourceData, meta interface{})
removedOne = true
continue
}
if *l.ID == "" && *ol.ID == resourceArmCosmosDbAccountGenerateDefaultId(name, *l.LocationName) {
continue
}
if *l.ID != *ol.ID {
if *l.FailoverPriority == 0 {
return fmt.Errorf("Cannot change the prefix/ID of the primary Cosmos DB account %q location %s (Resource Group %q)", name, *l.LocationName, resourceGroup)
}
delete(oldLocationsMap, *l.LocationName)
removedOne = true
}
}
}

@@ -497,21 +497,6 @@ func resourceArmCosmosDbAccountUpdate(d *schema.ResourceData, meta interface{})
return fmt.Errorf("Error updating CosmosDB Account %q locations (Resource Group %q): %+v", name, resourceGroup, err)
}

if *resp.EnableMultipleWriteLocations != enableMultipleWriteLocations {
enableMultipleWriteLocationsCreateUpdateParameters := documentdb.DatabaseAccountCreateUpdateParameters{
Location: utils.String(location),
DatabaseAccountCreateUpdateProperties: &documentdb.DatabaseAccountCreateUpdateProperties{
DatabaseAccountOfferType: utils.String(offerType),
EnableMultipleWriteLocations: utils.Bool(enableMultipleWriteLocations),
Locations: &newLocations,
},
}

if _, err = resourceArmCosmosDbAccountApiUpsert(client, ctx, resourceGroup, name, enableMultipleWriteLocationsCreateUpdateParameters, d); err != nil {
return fmt.Errorf("Error updating CosmosDB Account %q EnableMultipleWriteLocations (Resource Group %q): %+v", name, resourceGroup, err)
}
}

if upsertResponse.ID == nil {
return fmt.Errorf("Cannot read CosmosDB Account '%s' (resource group %s) ID", name, resourceGroup)
}
@@ -571,7 +556,7 @@ func resourceArmCosmosDbAccountRead(d *schema.ResourceData, meta interface{}) er
return fmt.Errorf("Error setting CosmosDB Account %q `consistency_policy` (Resource Group %q): %+v", name, resourceGroup, err)
}

if err = d.Set("geo_location", flattenAzureRmCosmosDBAccountGeoLocations(d, resp)); err != nil {
if err = d.Set("geo_location", flattenAzureRmCosmosDBAccountGeoLocations(resp)); err != nil {
return fmt.Errorf("Error setting `geo_location`: %+v", err)
}

@@ -731,7 +716,8 @@ func resourceArmCosmosDbAccountApiUpsert(client *documentdb.DatabaseAccountsClie
return nil, "", fmt.Errorf("Error reading CosmosDB Account %q after create/update (Resource Group %q): %+v", name, resourceGroup, err2)
}
status := "Succeeded"
for _, l := range append(*resp.ReadLocations, *resp.WriteLocations...) {
locations := append(*resp.ReadLocations, *resp.WriteLocations...)
for _, l := range locations {
if status = *l.ProvisioningState; status == "Creating" || status == "Updating" || status == "Deleting" {
break // return the first non successful status.
}
@@ -784,11 +770,7 @@ func expandAzureRmCosmosDBAccountConsistencyPolicy(d *schema.ResourceData) *docu
return &policy
}

func resourceArmCosmosDbAccountGenerateDefaultId(databaseName string, location string) string {
return fmt.Sprintf("%s-%s", databaseName, location)
}

func expandAzureRmCosmosDBAccountGeoLocations(databaseName string, d *schema.ResourceData) ([]documentdb.Location, error) {
func expandAzureRmCosmosDBAccountGeoLocations(d *schema.ResourceData) ([]documentdb.Location, error) {
locations := make([]documentdb.Location, 0)
for _, l := range d.Get("geo_location").(*schema.Set).List() {
data := l.(map[string]interface{})
@@ -798,13 +780,6 @@ func expandAzureRmCosmosDBAccountGeoLocations(databaseName string, d *schema.Res
FailoverPriority: utils.Int32(int32(data["failover_priority"].(int))),
}

if v, ok := data["prefix"].(string); ok {
data["id"] = v
} else {
data["id"] = utils.String(resourceArmCosmosDbAccountGenerateDefaultId(databaseName, *location.LocationName))
}
location.ID = utils.String(data["id"].(string))

locations = append(locations, location)
}

@@ -875,20 +850,11 @@ func flattenAzureRmCosmosDBAccountConsistencyPolicy(policy *documentdb.Consisten
return []interface{}{result}
}

func flattenAzureRmCosmosDBAccountGeoLocations(d *schema.ResourceData, account documentdb.DatabaseAccountGetResults) *schema.Set {
func flattenAzureRmCosmosDBAccountGeoLocations(account documentdb.DatabaseAccountGetResults) *schema.Set {
locationSet := schema.Set{
F: resourceAzureRMCosmosDBAccountGeoLocationHash,
}

// we need to propagate the `prefix` field so fetch existing
prefixMap := map[string]string{}
if locations, ok := d.GetOk("geo_location"); ok {
for _, lRaw := range locations.(*schema.Set).List() {
lb := lRaw.(map[string]interface{})
prefixMap[lb["location"].(string)] = lb["prefix"].(string)
}
}

for _, l := range *account.FailoverPolicies {
id := *l.ID
lb := map[string]interface{}{
@@ -897,11 +863,6 @@ func flattenAzureRmCosmosDBAccountGeoLocations(d *schema.ResourceData, account d
"failover_priority": int(*l.FailoverPriority),
}

// if id is not the default then it must be set via prefix
if id != resourceArmCosmosDbAccountGenerateDefaultId(d.Get("name").(string), lb["location"].(string)) {
lb["prefix"] = id
}

locationSet.Add(lb)
}

@@ -947,14 +908,10 @@ func resourceAzureRMCosmosDBAccountGeoLocationHash(v interface{}) int {
var buf bytes.Buffer

if m, ok := v.(map[string]interface{}); ok {
prefix := ""
if v, ok := m["prefix"].(string); ok {
prefix = v
}
location := azure.NormalizeLocation(m["location"].(string))
priority := int32(m["failover_priority"].(int))

buf.WriteString(fmt.Sprintf("%s-%s-%d", prefix, location, priority))
buf.WriteString(fmt.Sprintf("%s-%d", location, priority))
}

return hashcode.String(buf.String())
Original file line number Diff line number Diff line change
@@ -494,12 +494,12 @@ resource "azurerm_cosmosdb_account" "import" {
offer_type = azurerm_cosmosdb_account.test.offer_type

consistency_policy {
consistency_level = azurerm_cosmosdb_account.consistency_policy[0].consistency_level
consistency_level = azurerm_cosmosdb_account.test.consistency_policy[0].consistency_level
}

geo_location {
location = azurerm_cosmosdb_account.geo_location[0].location
failover_priority = azurerm_cosmosdb_account.geo_location[0].location
location = azurerm_resource_group.test.location
failover_priority = 0
}
}
`, testAccAzureRMCosmosDBAccount_basic(data, "GlobalDocumentDB", consistency))
@@ -609,7 +609,6 @@ resource "azurerm_cosmosdb_account" "test" {
}

geo_location {
prefix = "acctest-%[2]d-custom-id"
location = "%[5]s"
failover_priority = 1
}
@@ -635,6 +634,7 @@ resource "azurerm_cosmosdb_account" "test" {

consistency_policy {
consistency_level = "%[4]s"
max_interval_in_seconds = 360
max_staleness_prefix = 170000
}

@@ -652,13 +652,11 @@ resource "azurerm_cosmosdb_account" "test" {
}

geo_location {
prefix = "acctest-%[2]d-custom-id-updated"
location = "%[5]s"
failover_priority = 1
}

geo_location {
prefix = "acctest-%[2]d-custom-id-added"
location = "%[6]s"
failover_priority = 2
}