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 CosmosDB SDK to 2019-08-01 from 2015-04-08 #6253

Closed
wants to merge 12 commits into from
179 changes: 0 additions & 179 deletions azurerm/helpers/azure/cosmos.go

This file was deleted.

31 changes: 28 additions & 3 deletions azurerm/internal/services/cosmos/client/client.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,44 @@
package client

import (
"github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2015-04-08/documentdb"
"github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2019-08-01/documentdb"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/common"
)

type Client struct {
DatabaseClient *documentdb.DatabaseAccountsClient
CassandraClient *documentdb.CassandraResourcesClient
DatabaseClient *documentdb.DatabaseAccountsClient
GremlinClient *documentdb.GremlinResourcesClient
MongoDbClient *documentdb.MongoDBResourcesClient
SqlClient *documentdb.SQLResourcesClient
TableClient *documentdb.TableResourcesClient
}

func NewClient(o *common.ClientOptions) *Client {
cassandraClient := documentdb.NewCassandraResourcesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&cassandraClient.Client, o.ResourceManagerAuthorizer)

databaseClient := documentdb.NewDatabaseAccountsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&databaseClient.Client, o.ResourceManagerAuthorizer)

gremlinClient := documentdb.NewGremlinResourcesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&gremlinClient.Client, o.ResourceManagerAuthorizer)

mongoDbClient := documentdb.NewMongoDBResourcesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&mongoDbClient.Client, o.ResourceManagerAuthorizer)

sqlClient := documentdb.NewSQLResourcesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&sqlClient.Client, o.ResourceManagerAuthorizer)

tableClient := documentdb.NewTableResourcesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&tableClient.Client, o.ResourceManagerAuthorizer)

return &Client{
DatabaseClient: &databaseClient,
CassandraClient: &cassandraClient,
DatabaseClient: &databaseClient,
GremlinClient: &gremlinClient,
MongoDbClient: &mongoDbClient,
SqlClient: &sqlClient,
TableClient: &tableClient,
}
}
19 changes: 19 additions & 0 deletions azurerm/internal/services/cosmos/common/throughput.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package common

import (
"github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2019-08-01/documentdb"
)

func GetThroughputFromResult(throughputResponse documentdb.ThroughputSettingsGetResults) *int32 {
props := throughputResponse.ThroughputSettingsGetProperties
if props == nil {
return nil
}

res := props.Resource
if res == nil {
return nil
}

return res.Throughput
}
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/cosmos-db/mgmt/2015-04-08/documentdb"
"github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2019-08-01/documentdb"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts"
Expand Down Expand Up @@ -211,7 +211,7 @@ func dataSourceArmCosmosDbAccountRead(d *schema.ResourceData, meta interface{})
}
d.Set("kind", string(resp.Kind))

if props := resp.DatabaseAccountProperties; props != nil {
if props := resp.DatabaseAccountGetProperties; props != nil {
d.Set("offer_type", string(props.DatabaseAccountOfferType))
d.Set("ip_range_filter", props.IPRangeFilter)
d.Set("endpoint", props.DocumentEndpoint)
Expand Down
50 changes: 50 additions & 0 deletions azurerm/internal/services/cosmos/migration/cassandra_keyspace.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package migration

import (
"log"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate"
)

func ResourceCassandraKeyspaceUpgradeV0Schema() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validate.CosmosEntityName,
},

"resource_group_name": azure.SchemaResourceGroupName(),

"account_name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validate.CosmosAccountName,
},

"throughput": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
ValidateFunc: validate.CosmosThroughput,
},
},
}
}

func ResourceCassandraKeyspaceStateUpgradeV0ToV1(rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) {
oldId := rawState["id"].(string)
newId := strings.Replace(rawState["id"].(string), "apis/cassandra/keyspaces", "cassandraKeyspaces", 1)

log.Printf("[DEBUG] Updating ID from %q to %q", oldId, newId)

rawState["id"] = newId

return rawState, nil
}
50 changes: 50 additions & 0 deletions azurerm/internal/services/cosmos/migration/gremlin_database.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package migration

import (
"log"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate"
)

func ResourceGremlinDatabaseUpgradeV0Schema() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validate.CosmosEntityName,
},

"resource_group_name": azure.SchemaResourceGroupName(),

"account_name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validate.CosmosAccountName,
},

"throughput": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
ValidateFunc: validate.CosmosThroughput,
},
},
}
}

func ResourceGremlinDatabaseStateUpgradeV0ToV1(rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) {
oldId := rawState["id"].(string)
newId := strings.Replace(rawState["id"].(string), "apis/gremlin/databases", "gremlinDatabases", 1)

log.Printf("[DEBUG] Updating ID from %q to %q", oldId, newId)

rawState["id"] = newId

return rawState, nil
}
Loading