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

service/cosmos: Upgrade API to 2021-01-15 stable and other enhancements #11337

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
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),
},

"included_path": {
Expand Down Expand Up @@ -179,7 +179,7 @@ func CosmosDbIndexingPolicySchema() *schema.Schema {
[]string{
string(documentdb.Ascending),
string(documentdb.Descending),
}, false),
}, true),
},
},
},
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
37 changes: 34 additions & 3 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 @@ -96,6 +96,18 @@ func resourceCosmosDbAccount() *schema.Resource {
}, true),
},

"mongo_server_version": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
string(documentdb.ThreeFullStopTwo),
string(documentdb.ThreeFullStopSix),
string(documentdb.FourFullStopZero),
}, false),
},

"ip_range_filter": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -208,6 +220,7 @@ func resourceCosmosDbAccount() *schema.Resource {
"zone_redundant": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
},
},
Expand Down Expand Up @@ -439,6 +452,14 @@ func resourceCosmosDbAccountCreate(d *schema.ResourceData, meta interface{}) err
Tags: tags.Expand(t),
}

if kind == string(documentdb.MongoDB) {
if v, ok := d.GetOk("mongo_server_version"); ok {
account.DatabaseAccountCreateUpdateProperties.APIProperties = &documentdb.APIProperties{
ServerVersion: documentdb.ServerVersion(v.(string)),
}
}
}

if keyVaultKeyIDRaw, ok := d.GetOk("key_vault_key_id"); ok {
keyVaultKey, err := keyVaultParse.ParseOptionallyVersionedNestedItemID(keyVaultKeyIDRaw.(string))
if err != nil {
Expand Down Expand Up @@ -547,6 +568,14 @@ func resourceCosmosDbAccountUpdate(d *schema.ResourceData, meta interface{}) err
Tags: tags.Expand(t),
}

if kind == string(documentdb.MongoDB) {
if v, ok := d.GetOk("mongo_server_version"); ok {
account.DatabaseAccountCreateUpdateProperties.APIProperties = &documentdb.APIProperties{
ServerVersion: documentdb.ServerVersion(v.(string)),
}
}
}

if keyVaultKeyIDRaw, ok := d.GetOk("key_vault_key_id"); ok {
keyVaultKey, err := keyVaultParse.ParseOptionallyVersionedNestedItemID(keyVaultKeyIDRaw.(string))
if err != nil {
Expand Down Expand Up @@ -644,6 +673,10 @@ func resourceCosmosDbAccountRead(d *schema.ResourceData, meta interface{}) error
d.Set("analytical_storage_enabled", resp.EnableAnalyticalStorage)
d.Set("public_network_access_enabled", resp.PublicNetworkAccess == documentdb.Enabled)

if resp.Kind == documentdb.MongoDB {
d.Set("mongo_server_version", resp.APIProperties.ServerVersion)
}

if v := resp.IsVirtualNetworkFilterEnabled; v != nil {
d.Set("is_virtual_network_filter_enabled", resp.IsVirtualNetworkFilterEnabled)
}
Expand Down Expand Up @@ -932,12 +965,10 @@ func expandAzureRmCosmosDBAccountGeoLocations(d *schema.ResourceData) ([]documen
func expandAzureRmCosmosDBAccountCapabilities(d *schema.ResourceData) *[]documentdb.Capability {
capabilities := d.Get("capabilities").(*schema.Set).List()
s := make([]documentdb.Capability, 0)

for _, c := range capabilities {
m := c.(map[string]interface{})
s = append(s, documentdb.Capability{Name: utils.String(m["name"].(string))})
}

return &s
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ resource "azurerm_cosmosdb_account" "test" {
consistency_level = "BoundedStaleness"
}

capabilities {
name = "EnableMongo"
}

geo_location {
location = azurerm_resource_group.test.location
failover_priority = 0
Expand Down
Loading