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

Upgrade Cosmos version from 2020-04-01-preview to 2021-01-15 #10926

Merged
merged 22 commits into from
Apr 27, 2021
2 changes: 1 addition & 1 deletion azurerm/internal/services/cosmos/client/client.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package client

import (
"github.com/Azure/azure-sdk-for-go/services/preview/cosmos-db/mgmt/2020-04-01-preview/documentdb"
"github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2021-01-15/documentdb"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/common"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package common
import (
"log"

"github.com/Azure/azure-sdk-for-go/services/preview/cosmos-db/mgmt/2020-04-01-preview/documentdb"
"github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2021-01-15/documentdb"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)
Expand Down
2 changes: 1 addition & 1 deletion azurerm/internal/services/cosmos/common/indexing_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package common
import (
"fmt"

"github.com/Azure/azure-sdk-for-go/services/preview/cosmos-db/mgmt/2020-04-01-preview/documentdb"
"github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2021-01-15/documentdb"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package common
import (
"testing"

"github.com/Azure/azure-sdk-for-go/services/preview/cosmos-db/mgmt/2020-04-01-preview/documentdb"
"github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2021-01-15/documentdb"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

Expand Down
2 changes: 1 addition & 1 deletion azurerm/internal/services/cosmos/common/ip_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package common
import (
"strings"

"github.com/Azure/azure-sdk-for-go/services/preview/cosmos-db/mgmt/2020-04-01-preview/documentdb"
"github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2021-01-15/documentdb"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

Expand Down
2 changes: 1 addition & 1 deletion azurerm/internal/services/cosmos/common/ip_rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"reflect"
"testing"

"github.com/Azure/azure-sdk-for-go/services/preview/cosmos-db/mgmt/2020-04-01-preview/documentdb"
"github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2021-01-15/documentdb"
)

var (
Expand Down
6 changes: 3 additions & 3 deletions azurerm/internal/services/cosmos/common/schema.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package common

import (
"github.com/Azure/azure-sdk-for-go/services/preview/cosmos-db/mgmt/2020-04-01-preview/documentdb"
"github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2021-01-15/documentdb"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/cosmos/validate"
Expand Down Expand Up @@ -123,7 +123,7 @@ func CosmosDbIndexingPolicySchema() *schema.Schema {
ValidateFunc: validation.StringInSlice([]string{
string(documentdb.Consistent),
string(documentdb.None),
}, false),
}, true),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are we making this case insensitive? the SDK values should match what we get from the API?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In preview version, the value is "consistent" and "none", but in current version, the value is "Consistent" and "None". To resolve the breaking change, I set it to be case insensitive?

Copy link
Collaborator

Choose a reason for hiding this comment

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

instead of making this case insensitive can we just correct the casing to the SDK values on read?

also - could we open an issue on the SDK or somewhere to track this discrepancy?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The case has been change when the service has released 2020-04-01 stable version. The old 2020-04-01-preview version has been deleted.
Since preview version permits breaking changes, shall I not open the issue?

},

"included_path": {
Expand Down Expand Up @@ -179,7 +179,7 @@ func CosmosDbIndexingPolicySchema() *schema.Schema {
[]string{
string(documentdb.Ascending),
string(documentdb.Descending),
}, false),
}, true),
yupwei68 marked this conversation as resolved.
Show resolved Hide resolved
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion azurerm/internal/services/cosmos/common/throughput.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package common
import (
"fmt"

"github.com/Azure/azure-sdk-for-go/services/preview/cosmos-db/mgmt/2020-04-01-preview/documentdb"
"github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2021-01-15/documentdb"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"log"
"time"

"github.com/Azure/azure-sdk-for-go/services/preview/cosmos-db/mgmt/2020-04-01-preview/documentdb"
"github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2021-01-15/documentdb"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/cosmos/common"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"testing"

"github.com/Azure/azure-sdk-for-go/services/preview/cosmos-db/mgmt/2020-04-01-preview/documentdb"
"github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2021-01-15/documentdb"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance/check"
Expand Down Expand Up @@ -54,6 +54,8 @@ func (CosmosDBAccountDataSourceResource) basic(data acceptance.TestData) string
data "azurerm_cosmosdb_account" "test" {
name = azurerm_cosmosdb_account.test.name
resource_group_name = azurerm_resource_group.test.name

depends_on = [azurerm_cosmosdb_account.test]
yupwei68 marked this conversation as resolved.
Show resolved Hide resolved
}
`, CosmosDBAccountResource{}.basic(data, documentdb.GlobalDocumentDB, documentdb.BoundedStaleness))
}
Expand All @@ -65,6 +67,8 @@ func (CosmosDBAccountDataSourceResource) complete(data acceptance.TestData) stri
data "azurerm_cosmosdb_account" "test" {
name = azurerm_cosmosdb_account.test.name
resource_group_name = azurerm_resource_group.test.name

depends_on = [azurerm_cosmosdb_account.test]
}
`, CosmosDBAccountResource{}.complete(data, documentdb.GlobalDocumentDB, documentdb.BoundedStaleness))
}
29 changes: 16 additions & 13 deletions azurerm/internal/services/cosmos/cosmosdb_account_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"strings"
"time"

"github.com/Azure/azure-sdk-for-go/services/preview/cosmos-db/mgmt/2020-04-01-preview/documentdb"
"github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2021-01-15/documentdb"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
Expand Down Expand Up @@ -208,6 +208,7 @@ func resourceCosmosDbAccount() *schema.Resource {
"zone_redundant": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
},
},
Expand Down Expand Up @@ -820,21 +821,23 @@ func resourceCosmosDbAccountApiUpsert(client *documentdb.DatabaseAccountsClient,
return nil, "", fmt.Errorf("Error reading CosmosDB Account %q after create/update (Resource Group %q): %+v", name, resourceGroup, err2)
}
status := "Succeeded"
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.
if props := resp.DatabaseAccountGetProperties; props != nil {
locations := append(*props.ReadLocations, *props.WriteLocations...)
for _, l := range locations {
if status = *l.ProvisioningState; status == "Creating" || status == "Updating" || status == "Deleting" {
break // return the first non successful status.
}
}
}

for _, desiredLocation := range *account.Locations {
for index, l := range locations {
if azure.NormalizeLocation(*desiredLocation.LocationName) == azure.NormalizeLocation(*l.LocationName) {
break
}
for _, desiredLocation := range *account.Locations {
for index, l := range locations {
if azure.NormalizeLocation(*desiredLocation.LocationName) == azure.NormalizeLocation(*l.LocationName) {
break
}

if (index + 1) == len(locations) {
return resp, "Updating", nil
if (index + 1) == len(locations) {
return resp, "Updating", nil
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@ resource "azurerm_cosmosdb_account" "test" {
kind = "MongoDB"
offer_type = "Standard"

capabilities {
name = "EnableMongo"
}

consistency_policy {
consistency_level = "BoundedStaleness"
}
Expand Down
Loading