diff --git a/azurerm/config.go b/azurerm/config.go index 2ff23ee9724e..4d67e56be644 100644 --- a/azurerm/config.go +++ b/azurerm/config.go @@ -95,7 +95,7 @@ type ArmClient struct { StopContext context.Context - cosmosDBClient documentdb.DatabaseAccountsClient + cosmosAccountsClient documentdb.DatabaseAccountsClient automationAccountClient automation.AccountClient automationAgentRegistrationInfoClient automation.AgentRegistrationInformationClient @@ -498,7 +498,7 @@ func getArmClient(c *authentication.Config, skipProviderRegistration bool, partn client.registerContainerInstanceClients(endpoint, c.SubscriptionID, auth) client.registerContainerRegistryClients(endpoint, c.SubscriptionID, auth) client.registerContainerServicesClients(endpoint, c.SubscriptionID, auth) - client.registerCosmosDBClients(endpoint, c.SubscriptionID, auth) + client.registerCosmosAccountsClients(endpoint, c.SubscriptionID, auth) client.registerDatabricksClients(endpoint, c.SubscriptionID, auth) client.registerDatabases(endpoint, c.SubscriptionID, auth, sender) client.registerDataFactoryClients(endpoint, c.SubscriptionID, auth) @@ -735,10 +735,10 @@ func (c *ArmClient) registerCognitiveServiceClients(endpoint, subscriptionId str c.cognitiveAccountsClient = accountsClient } -func (c *ArmClient) registerCosmosDBClients(endpoint, subscriptionId string, auth autorest.Authorizer) { - cdb := documentdb.NewDatabaseAccountsClientWithBaseURI(endpoint, subscriptionId) - c.configureClient(&cdb.Client, auth) - c.cosmosDBClient = cdb +func (c *ArmClient) registerCosmosAccountsClients(endpoint, subscriptionId string, auth autorest.Authorizer) { + ca := documentdb.NewDatabaseAccountsClientWithBaseURI(endpoint, subscriptionId) + c.configureClient(&ca.Client, auth) + c.cosmosAccountsClient = ca } func (c *ArmClient) registerMediaServiceClients(endpoint, subscriptionId string, auth autorest.Authorizer) { diff --git a/azurerm/data_source_cosmos_db_account.go b/azurerm/data_source_cosmos_db_account.go index a4445239bc60..71d953671227 100644 --- a/azurerm/data_source_cosmos_db_account.go +++ b/azurerm/data_source_cosmos_db_account.go @@ -10,9 +10,9 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) -func dataSourceArmCosmosDBAccount() *schema.Resource { +func dataSourceArmCosmosDbAccount() *schema.Resource { return &schema.Resource{ - Read: dataSourceArmCosmosDBAccountRead, + Read: dataSourceArmCosmosDbAccountRead, Schema: map[string]*schema.Schema{ "name": { @@ -176,8 +176,8 @@ func dataSourceArmCosmosDBAccount() *schema.Resource { } } -func dataSourceArmCosmosDBAccountRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*ArmClient).cosmosDBClient +func dataSourceArmCosmosDbAccountRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).cosmosAccountsClient ctx := meta.(*ArmClient).StopContext resourceGroup := d.Get("resource_group_name").(string) diff --git a/azurerm/helpers/azure/cosmos.go b/azurerm/helpers/azure/cosmos.go new file mode 100644 index 000000000000..216dddc94c4d --- /dev/null +++ b/azurerm/helpers/azure/cosmos.go @@ -0,0 +1,128 @@ +package azure + +import ( + "fmt" + + "github.com/Azure/go-autorest/autorest" +) + +// it seems the cosmos API is not returning any sort of valid ID in the main response body +// so lets grab it from the response.request.url.path +func CosmosGetIDFromResponse(resp autorest.Response) (string, error) { + if resp.Response == nil { + return "", fmt.Errorf("Error: Unable to get Cosmos ID from Response: http response is nil") + } + + if resp.Response.Request == nil { + return "", fmt.Errorf("Error: Unable to get Cosmos ID from Response: Request is nil") + } + + if resp.Response.Request.URL == nil { + return "", fmt.Errorf("Error: Unable to get Cosmos ID from Response: URL is nil") + } + + return resp.Response.Request.URL.Path, nil +} + +type CosmosAccountID struct { + ResourceID + Account string +} + +func ParseCosmosAccountID(id string) (*CosmosAccountID, error) { + subid, err := ParseAzureResourceID(id) + if err != nil { + return nil, err + } + + account, ok := subid.Path["databaseAccounts"] + if !ok { + return nil, fmt.Errorf("Error: Unable to parse Cosmos Database Resource ID: databaseAccounts is missing from: %s", id) + } + + return &CosmosAccountID{ + ResourceID: *subid, + Account: account, + }, nil +} + +type CosmosDatabaseID struct { + CosmosAccountID + Database string +} + +func ParseCosmosDatabaseID(id string) (*CosmosDatabaseID, error) { + subid, err := ParseCosmosAccountID(id) + if err != nil { + return nil, err + } + + db, ok := subid.Path["databases"] + if !ok { + return nil, fmt.Errorf("Error: Unable to parse Cosmos Database Resource ID: databases is missing from: %s", id) + } + + return &CosmosDatabaseID{ + CosmosAccountID: *subid, + Database: db, + }, nil +} + +type CosmosDatabaseCollectionID struct { + CosmosDatabaseID + Collection string +} + +type CosmosDatabaseContainerID struct { + CosmosDatabaseID + Container string +} + +type CosmosKeyspaceID struct { + CosmosAccountID + Keyspace string +} + +func ParseCosmosKeyspaceID(id string) (*CosmosKeyspaceID, error) { + subid, err := ParseCosmosAccountID(id) + if err != nil { + return nil, err + } + + ks, ok := subid.Path["keyspaces"] + if !ok { + return nil, fmt.Errorf("Error: Unable to parse Cosmos Keyspace Resource ID: keyspaces is missing from: %s", id) + } + + return &CosmosKeyspaceID{ + CosmosAccountID: *subid, + Keyspace: ks, + }, nil +} + +type CosmosKeyspaceTableID struct { + CosmosKeyspaceID + Table string +} + +type CosmosTableID struct { + CosmosAccountID + Table string +} + +func ParseCosmosTableID(id string) (*CosmosTableID, error) { + subid, err := ParseCosmosAccountID(id) + if err != nil { + return nil, err + } + + table, ok := subid.Path["tables"] + if !ok { + return nil, fmt.Errorf("Error: Unable to parse Cosmos Table Resource ID: tables is missing from: %s", id) + } + + return &CosmosTableID{ + CosmosAccountID: *subid, + Table: table, + }, nil +} diff --git a/azurerm/helpers/validate/cosmos.go b/azurerm/helpers/validate/cosmos.go new file mode 100644 index 000000000000..3172f496b198 --- /dev/null +++ b/azurerm/helpers/validate/cosmos.go @@ -0,0 +1,28 @@ +package validate + +import ( + "fmt" + "regexp" +) + +func CosmosAccountName(v interface{}, k string) (warnings []string, errors []error) { + value := v.(string) + + // Portal: The value must contain only alphanumeric characters or the following: - + if matched := regexp.MustCompile("^[-a-z0-9]{3,50}$").Match([]byte(value)); !matched { + errors = append(errors, fmt.Errorf("%s name must be 3 - 50 characters long, contain only letters, numbers and hyphens.", k)) + } + + return warnings, errors +} + +func CosmosEntityName(v interface{}, k string) (warnings []string, errors []error) { + value := v.(string) + + if len(value) < 1 || len(value) > 255 { + errors = append(errors, fmt.Errorf( + "%q must be between 1 and 255 characters: %q", k, value)) + } + + return warnings, errors +} diff --git a/azurerm/provider.go b/azurerm/provider.go index 11b6921f5dad..5d076df4939c 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -121,7 +121,7 @@ func Provider() terraform.ResourceProvider { "azurerm_cdn_profile": dataSourceArmCdnProfile(), "azurerm_client_config": dataSourceArmClientConfig(), "azurerm_container_registry": dataSourceArmContainerRegistry(), - "azurerm_cosmosdb_account": dataSourceArmCosmosDBAccount(), + "azurerm_cosmosdb_account": dataSourceArmCosmosDbAccount(), "azurerm_data_lake_store": dataSourceArmDataLakeStoreAccount(), "azurerm_dev_test_lab": dataSourceArmDevTestLab(), "azurerm_dns_zone": dataSourceArmDnsZone(), @@ -233,7 +233,11 @@ func Provider() terraform.ResourceProvider { "azurerm_container_group": resourceArmContainerGroup(), "azurerm_container_registry": resourceArmContainerRegistry(), "azurerm_container_service": resourceArmContainerService(), - "azurerm_cosmosdb_account": resourceArmCosmosDBAccount(), + "azurerm_cosmosdb_account": resourceArmCosmosDbAccount(), + "azurerm_cosmosdb_cassandra_keyspace": resourceArmCosmosDbCassandraKeyspace(), + "azurerm_cosmosdb_mongo_database": resourceArmCosmosDbMongoDatabase(), + "azurerm_cosmosdb_sql_database": resourceArmCosmosDbSQLDatabase(), + "azurerm_cosmosdb_table": resourceArmCosmosDbTable(), "azurerm_data_factory": resourceArmDataFactory(), "azurerm_data_factory_dataset_mysql": resourceArmDataFactoryDatasetMySQL(), "azurerm_data_factory_dataset_postgresql": resourceArmDataFactoryDatasetPostgreSQL(), diff --git a/azurerm/resource_arm_cosmos_db_account.go b/azurerm/resource_arm_cosmosdb_account.go similarity index 96% rename from azurerm/resource_arm_cosmos_db_account.go rename to azurerm/resource_arm_cosmosdb_account.go index 41704b418ba4..cd6e50f4fb90 100644 --- a/azurerm/resource_arm_cosmos_db_account.go +++ b/azurerm/resource_arm_cosmosdb_account.go @@ -22,12 +22,12 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) -func resourceArmCosmosDBAccount() *schema.Resource { +func resourceArmCosmosDbAccount() *schema.Resource { return &schema.Resource{ - Create: resourceArmCosmosDBAccountCreate, - Read: resourceArmCosmosDBAccountRead, - Update: resourceArmCosmosDBAccountUpdate, - Delete: resourceArmCosmosDBAccountDelete, + Create: resourceArmCosmosDbAccountCreate, + Read: resourceArmCosmosDbAccountRead, + Update: resourceArmCosmosDbAccountUpdate, + Delete: resourceArmCosmosDbAccountDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -296,8 +296,8 @@ func resourceArmCosmosDBAccount() *schema.Resource { } } -func resourceArmCosmosDBAccountCreate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*ArmClient).cosmosDBClient +func resourceArmCosmosDbAccountCreate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).cosmosAccountsClient ctx := meta.(*ArmClient).StopContext log.Printf("[INFO] preparing arguments for AzureRM Cosmos DB Account creation.") @@ -368,7 +368,7 @@ func resourceArmCosmosDBAccountCreate(d *schema.ResourceData, meta interface{}) Tags: expandTags(tags), } - resp, err := resourceArmCosmosDBAccountApiUpsert(client, ctx, resourceGroup, name, account) + resp, err := resourceArmCosmosDbAccountApiUpsert(client, ctx, resourceGroup, name, account) if err != nil { return fmt.Errorf("Error creating CosmosDB Account %q (Resource Group %q): %+v", name, resourceGroup, err) } @@ -395,11 +395,11 @@ func resourceArmCosmosDBAccountCreate(d *schema.ResourceData, meta interface{}) d.SetId(*id) - return resourceArmCosmosDBAccountRead(d, meta) + return resourceArmCosmosDbAccountRead(d, meta) } -func resourceArmCosmosDBAccountUpdate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*ArmClient).cosmosDBClient +func resourceArmCosmosDbAccountUpdate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).cosmosAccountsClient ctx := meta.(*ArmClient).StopContext log.Printf("[INFO] preparing arguments for AzureRM Cosmos DB Account update.") @@ -472,7 +472,7 @@ func resourceArmCosmosDBAccountUpdate(d *schema.ResourceData, meta interface{}) Tags: expandTags(tags), } - if _, err = resourceArmCosmosDBAccountApiUpsert(client, ctx, resourceGroup, name, account); err != nil { + if _, err = resourceArmCosmosDbAccountApiUpsert(client, ctx, resourceGroup, name, account); err != nil { return fmt.Errorf("Error updating CosmosDB Account %q properties (Resource Group %q): %+v", name, resourceGroup, err) } @@ -488,7 +488,7 @@ func resourceArmCosmosDBAccountUpdate(d *schema.ResourceData, meta interface{}) removedOne = true continue } - if *l.ID == "" && *ol.ID == resourceArmCosmosDBAccountGenerateDefaultId(name, *l.LocationName) { + if *l.ID == "" && *ol.ID == resourceArmCosmosDbAccountGenerateDefaultId(name, *l.LocationName) { continue } if *l.ID != *ol.ID { @@ -509,14 +509,14 @@ func resourceArmCosmosDBAccountUpdate(d *schema.ResourceData, meta interface{}) } account.DatabaseAccountCreateUpdateProperties.Locations = &locationsUnchanged - if _, err = resourceArmCosmosDBAccountApiUpsert(client, ctx, resourceGroup, name, account); err != nil { + if _, err = resourceArmCosmosDbAccountApiUpsert(client, ctx, resourceGroup, name, account); err != nil { return fmt.Errorf("Error removing CosmosDB Account %q renamed locations (Resource Group %q): %+v", name, resourceGroup, err) } } //add any new/renamed locations account.DatabaseAccountCreateUpdateProperties.Locations = &newLocations - upsertResponse, err := resourceArmCosmosDBAccountApiUpsert(client, ctx, resourceGroup, name, account) + upsertResponse, err := resourceArmCosmosDbAccountApiUpsert(client, ctx, resourceGroup, name, account) if err != nil { return fmt.Errorf("Error updating CosmosDB Account %q locations (Resource Group %q): %+v", name, resourceGroup, err) } @@ -543,11 +543,11 @@ func resourceArmCosmosDBAccountUpdate(d *schema.ResourceData, meta interface{}) d.SetId(*id) - return resourceArmCosmosDBAccountRead(d, meta) + return resourceArmCosmosDbAccountRead(d, meta) } -func resourceArmCosmosDBAccountRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*ArmClient).cosmosDBClient +func resourceArmCosmosDbAccountRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).cosmosAccountsClient ctx := meta.(*ArmClient).StopContext id, err := parseAzureResourceID(d.Id()) @@ -682,8 +682,8 @@ func resourceArmCosmosDBAccountRead(d *schema.ResourceData, meta interface{}) er return nil } -func resourceArmCosmosDBAccountDelete(d *schema.ResourceData, meta interface{}) error { - client := meta.(*ArmClient).cosmosDBClient +func resourceArmCosmosDbAccountDelete(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).cosmosAccountsClient ctx := meta.(*ArmClient).StopContext id, err := parseAzureResourceID(d.Id()) @@ -729,7 +729,7 @@ func resourceArmCosmosDBAccountDelete(d *schema.ResourceData, meta interface{}) return nil } -func resourceArmCosmosDBAccountApiUpsert(client documentdb.DatabaseAccountsClient, ctx context.Context, resourceGroup string, name string, account documentdb.DatabaseAccountCreateUpdateParameters) (*documentdb.DatabaseAccount, error) { +func resourceArmCosmosDbAccountApiUpsert(client documentdb.DatabaseAccountsClient, ctx context.Context, resourceGroup string, name string, account documentdb.DatabaseAccountCreateUpdateParameters) (*documentdb.DatabaseAccount, error) { future, err := client.CreateOrUpdate(ctx, resourceGroup, name, account) if err != nil { return nil, fmt.Errorf("Error creating/updating CosmosDB Account %q (Resource Group %q): %+v", name, resourceGroup, err) @@ -791,7 +791,7 @@ func expandAzureRmCosmosDBAccountConsistencyPolicy(d *schema.ResourceData) *docu return &policy } -func resourceArmCosmosDBAccountGenerateDefaultId(databaseName string, location string) string { +func resourceArmCosmosDbAccountGenerateDefaultId(databaseName string, location string) string { return fmt.Sprintf("%s-%s", databaseName, location) } @@ -809,7 +809,7 @@ func expandAzureRmCosmosDBAccountGeoLocations(databaseName string, d *schema.Res if v, ok := data["prefix"].(string); ok { data["id"] = v } else { - data["id"] = utils.String(resourceArmCosmosDBAccountGenerateDefaultId(databaseName, *location.LocationName)) + data["id"] = utils.String(resourceArmCosmosDbAccountGenerateDefaultId(databaseName, *location.LocationName)) } location.ID = utils.String(data["id"].(string)) @@ -974,7 +974,7 @@ func flattenAzureRmCosmosDBAccountGeoLocations(d *schema.ResourceData, account d } //if id is not the default then it must be set via prefix - if id != resourceArmCosmosDBAccountGenerateDefaultId(d.Get("name").(string), lb["location"].(string)) { + if id != resourceArmCosmosDbAccountGenerateDefaultId(d.Get("name").(string), lb["location"].(string)) { lb["prefix"] = id } diff --git a/azurerm/resource_arm_cosmos_db_account_failover_test.go b/azurerm/resource_arm_cosmosdb_account_failover_test.go similarity index 100% rename from azurerm/resource_arm_cosmos_db_account_failover_test.go rename to azurerm/resource_arm_cosmosdb_account_failover_test.go diff --git a/azurerm/resource_arm_cosmos_db_account_test.go b/azurerm/resource_arm_cosmosdb_account_test.go similarity index 98% rename from azurerm/resource_arm_cosmos_db_account_test.go rename to azurerm/resource_arm_cosmosdb_account_test.go index 6e676dbfb458..f1875bdfa745 100644 --- a/azurerm/resource_arm_cosmos_db_account_test.go +++ b/azurerm/resource_arm_cosmosdb_account_test.go @@ -643,7 +643,7 @@ func TestAccAzureRMCosmosDBAccount_multiMaster(t *testing.T) { } func testCheckAzureRMCosmosDBAccountDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*ArmClient).cosmosDBClient + conn := testAccProvider.Meta().(*ArmClient).cosmosAccountsClient ctx := testAccProvider.Meta().(*ArmClient).StopContext for _, rs := range s.RootModule().Resources { @@ -655,7 +655,6 @@ func testCheckAzureRMCosmosDBAccountDestroy(s *terraform.State) error { resourceGroup := rs.Primary.Attributes["resource_group_name"] resp, err := conn.Get(ctx, resourceGroup, name) - if err != nil { return nil } @@ -670,6 +669,9 @@ func testCheckAzureRMCosmosDBAccountDestroy(s *terraform.State) error { func testCheckAzureRMCosmosDBAccountExists(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { + conn := testAccProvider.Meta().(*ArmClient).cosmosAccountsClient + ctx := testAccProvider.Meta().(*ArmClient).StopContext + // Ensure we have enough information in state to look up in API rs, ok := s.RootModule().Resources[resourceName] if !ok { @@ -677,17 +679,11 @@ func testCheckAzureRMCosmosDBAccountExists(resourceName string) resource.TestChe } name := rs.Primary.Attributes["name"] - resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] - if !hasResourceGroup { - return fmt.Errorf("Bad: no resource group found in state for CosmosDB Account: '%s'", name) - } - - conn := testAccProvider.Meta().(*ArmClient).cosmosDBClient - ctx := testAccProvider.Meta().(*ArmClient).StopContext + resourceGroup := rs.Primary.Attributes["resource_group_name"] resp, err := conn.Get(ctx, resourceGroup, name) if err != nil { - return fmt.Errorf("Bad: Get on cosmosDBClient: %+v", err) + return fmt.Errorf("Bad: Get on cosmosAccountsClient: %+v", err) } if resp.StatusCode == http.StatusNotFound { diff --git a/azurerm/resource_arm_cosmosdb_cassandra_keyspace.go b/azurerm/resource_arm_cosmosdb_cassandra_keyspace.go new file mode 100644 index 000000000000..1beeb326cda6 --- /dev/null +++ b/azurerm/resource_arm_cosmosdb_cassandra_keyspace.go @@ -0,0 +1,153 @@ +package azurerm + +import ( + "fmt" + "log" + + "github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2015-04-08/documentdb" + "github.com/hashicorp/terraform/helper/schema" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/response" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func resourceArmCosmosDbCassandraKeyspace() *schema.Resource { + return &schema.Resource{ + Create: resourceArmCosmosDbCassandraKeyspaceCreate, + Read: resourceArmCosmosDbCassandraKeyspaceRead, + Delete: resourceArmCosmosDbCassandraKeyspaceDelete, + + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validate.CosmosEntityName, + }, + + "resource_group_name": resourceGroupNameSchema(), + + "account_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validate.CosmosAccountName, + }, + }, + } +} + +func resourceArmCosmosDbCassandraKeyspaceCreate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).cosmosAccountsClient + ctx := meta.(*ArmClient).StopContext + + name := d.Get("name").(string) + resourceGroup := d.Get("resource_group_name").(string) + account := d.Get("account_name").(string) + + if requireResourcesToBeImported && d.IsNewResource() { + existing, err := client.GetCassandraKeyspace(ctx, resourceGroup, account, name) + if err != nil { + if !utils.ResponseWasNotFound(existing.Response) { + return fmt.Errorf("Error checking for presence of creating Cosmos Cassandra Keyspace %s (Account %s): %+v", name, account, err) + } + } else { + id, err := azure.CosmosGetIDFromResponse(existing.Response) + if err != nil { + return fmt.Errorf("Error generating import ID for Cosmos Cassandra Keyspace '%s' (Account %s)", name, account) + } + + return tf.ImportAsExistsError("azurerm_cosmosdb_cassandra_keyspace", id) + } + } + + db := documentdb.CassandraKeyspaceCreateUpdateParameters{ + CassandraKeyspaceCreateUpdateProperties: &documentdb.CassandraKeyspaceCreateUpdateProperties{ + Resource: &documentdb.CassandraKeyspaceResource{ + ID: &name, + }, + Options: map[string]*string{}, + }, + } + + future, err := client.CreateUpdateCassandraKeyspace(ctx, resourceGroup, account, name, db) + if err != nil { + return fmt.Errorf("Error issuing create/update request for Cosmos Cassandra Keyspace %s (Account %s): %+v", name, account, err) + } + + if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { + return fmt.Errorf("Error waiting on create/update future for Cosmos Cassandra Keyspace %s (Account %s): %+v", name, account, err) + } + + resp, err := client.GetCassandraKeyspace(ctx, resourceGroup, account, name) + if err != nil { + return fmt.Errorf("Error making get request for Cosmos Cassandra Keyspace %s (Account %s): %+v", name, account, err) + } + + id, err := azure.CosmosGetIDFromResponse(resp.Response) + if err != nil { + return fmt.Errorf("Error retrieving the ID for Cosmos Cassandra Keyspace '%s' (Account %s) ID: %v", name, account, err) + } + d.SetId(id) + + return resourceArmCosmosDbCassandraKeyspaceRead(d, meta) +} + +func resourceArmCosmosDbCassandraKeyspaceRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).cosmosAccountsClient + ctx := meta.(*ArmClient).StopContext + + id, err := azure.ParseCosmosKeyspaceID(d.Id()) + if err != nil { + return err + } + + resp, err := client.GetCassandraKeyspace(ctx, id.ResourceGroup, id.Account, id.Keyspace) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + log.Printf("[INFO] Error reading Cosmos Cassandra Keyspace %s (Account %s) - removing from state", id.Keyspace, id.Account) + d.SetId("") + return nil + } + + return fmt.Errorf("Error reading Cosmos Cassandra Keyspace %s (Account %s): %+v", id.Keyspace, id.Account, err) + } + + d.Set("resource_group_name", id.ResourceGroup) + d.Set("account_name", id.Account) + if props := resp.CassandraKeyspaceProperties; props != nil { + d.Set("name", props.ID) + } + + return nil +} + +func resourceArmCosmosDbCassandraKeyspaceDelete(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).cosmosAccountsClient + ctx := meta.(*ArmClient).StopContext + + id, err := azure.ParseCosmosKeyspaceID(d.Id()) + if err != nil { + return err + } + + future, err := client.DeleteCassandraKeyspace(ctx, id.ResourceGroup, id.Account, id.Keyspace) + if err != nil { + if !response.WasNotFound(future.Response()) { + return fmt.Errorf("Error deleting Cosmos Cassandra Keyspace %s (Account %s): %+v", id.Keyspace, id.Account, err) + } + } + + err = future.WaitForCompletionRef(ctx, client.Client) + if err != nil { + return fmt.Errorf("Error waiting on delete future for Cosmos Cassandra Keyspace %s (Account %s): %+v", id.Keyspace, id.Account, err) + } + + return nil +} diff --git a/azurerm/resource_arm_cosmosdb_cassandra_keyspace_test.go b/azurerm/resource_arm_cosmosdb_cassandra_keyspace_test.go new file mode 100644 index 000000000000..6d0bcf5bcbbc --- /dev/null +++ b/azurerm/resource_arm_cosmosdb_cassandra_keyspace_test.go @@ -0,0 +1,104 @@ +package azurerm + +import ( + "fmt" + "net/http" + "testing" + + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func TestAccAzureRMCosmosCassandraKeyspace_basic(t *testing.T) { + ri := tf.AccRandTimeInt() + resourceName := "azurerm_cosmosdb_cassandra_keyspace.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMCosmosCassandraKeyspaceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMCosmosCassandraKeyspace_basic(ri, testLocation()), + Check: resource.ComposeAggregateTestCheckFunc( + testCheckAzureRMCosmosCassandraKeyspaceExists(resourceName), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testCheckAzureRMCosmosCassandraKeyspaceDestroy(s *terraform.State) error { + client := testAccProvider.Meta().(*ArmClient).cosmosAccountsClient + ctx := testAccProvider.Meta().(*ArmClient).StopContext + + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_cosmosdb_cassandra_keyspace" { + continue + } + + name := rs.Primary.Attributes["name"] + account := rs.Primary.Attributes["account_name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + + resp, err := client.GetCassandraKeyspace(ctx, resourceGroup, account, name) + if err != nil { + if !utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Bad: Error checking destroy for Cosmos Cassandra Keyspace %s (account %s) still exists:\n%v", name, account, err) + } + } + + if !utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Cosmos Cassandra Keyspace %s (account %s) still exists:\n%#v", name, account, resp) + } + } + + return nil +} + +func testCheckAzureRMCosmosCassandraKeyspaceExists(resourceName string) resource.TestCheckFunc { + return func(s *terraform.State) error { + client := testAccProvider.Meta().(*ArmClient).cosmosAccountsClient + ctx := testAccProvider.Meta().(*ArmClient).StopContext + + // Ensure we have enough information in state to look up in API + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return fmt.Errorf("Not found: %s", resourceName) + } + + name := rs.Primary.Attributes["name"] + account := rs.Primary.Attributes["account_name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + + resp, err := client.GetCassandraKeyspace(ctx, resourceGroup, account, name) + if err != nil { + return fmt.Errorf("Bad: Get on cosmosAccountsClient: %+v", err) + } + + if resp.StatusCode == http.StatusNotFound { + return fmt.Errorf("Bad: Cosmos database '%s' (account: '%s') does not exist", name, account) + } + + return nil + } +} + +func testAccAzureRMCosmosCassandraKeyspace_basic(rInt int, location string) string { + return fmt.Sprintf(` +%[1]s + +resource "azurerm_cosmosdb_cassandra_keyspace" "test" { + name = "acctest-%[2]d" + resource_group_name = "${azurerm_cosmosdb_account.test.resource_group_name}" + account_name = "${azurerm_cosmosdb_account.test.name}" +} +`, testAccAzureRMCosmosDBAccount_capabilityCassandra(rInt, location), rInt) +} diff --git a/azurerm/resource_arm_cosmosdb_mongo_database.go b/azurerm/resource_arm_cosmosdb_mongo_database.go new file mode 100644 index 000000000000..7ee52a368731 --- /dev/null +++ b/azurerm/resource_arm_cosmosdb_mongo_database.go @@ -0,0 +1,153 @@ +package azurerm + +import ( + "fmt" + "log" + + "github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2015-04-08/documentdb" + "github.com/hashicorp/terraform/helper/schema" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/response" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func resourceArmCosmosDbMongoDatabase() *schema.Resource { + return &schema.Resource{ + Create: resourceArmCosmosDbMongoDatabaseCreate, + Read: resourceArmCosmosDbMongoDatabaseRead, + Delete: resourceArmCosmosDbMongoDatabaseDelete, + + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validate.CosmosEntityName, + }, + + "resource_group_name": resourceGroupNameSchema(), + + "account_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validate.CosmosAccountName, + }, + }, + } +} + +func resourceArmCosmosDbMongoDatabaseCreate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).cosmosAccountsClient + ctx := meta.(*ArmClient).StopContext + + name := d.Get("name").(string) + resourceGroup := d.Get("resource_group_name").(string) + account := d.Get("account_name").(string) + + if requireResourcesToBeImported && d.IsNewResource() { + existing, err := client.GetMongoDBDatabase(ctx, resourceGroup, account, name) + if err != nil { + if !utils.ResponseWasNotFound(existing.Response) { + return fmt.Errorf("Error checking for presence of creating Cosmos Mongo Database %s (Account %s): %+v", name, account, err) + } + } else { + id, err := azure.CosmosGetIDFromResponse(existing.Response) + if err != nil { + return fmt.Errorf("Error generating import ID for Cosmos Mongo Database '%s' (Account %s)", name, account) + } + + return tf.ImportAsExistsError("azurerm_cosmosdb_mongo_database", id) + } + } + + db := documentdb.MongoDBDatabaseCreateUpdateParameters{ + MongoDBDatabaseCreateUpdateProperties: &documentdb.MongoDBDatabaseCreateUpdateProperties{ + Resource: &documentdb.MongoDBDatabaseResource{ + ID: &name, + }, + Options: map[string]*string{}, + }, + } + + future, err := client.CreateUpdateMongoDBDatabase(ctx, resourceGroup, account, name, db) + if err != nil { + return fmt.Errorf("Error issuing create/update request for Cosmos Mongo Database %s (Account %s): %+v", name, account, err) + } + + if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { + return fmt.Errorf("Error waiting on create/update future for Cosmos Mongo Database %s (Account %s): %+v", name, account, err) + } + + resp, err := client.GetMongoDBDatabase(ctx, resourceGroup, account, name) + if err != nil { + return fmt.Errorf("Error making get request for Cosmos Mongo Database %s (Account %s): %+v", name, account, err) + } + + id, err := azure.CosmosGetIDFromResponse(resp.Response) + if err != nil { + return fmt.Errorf("Error retrieving the ID for Cosmos Mongo Database '%s' (Account %s) ID: %v", name, account, err) + } + d.SetId(id) + + return resourceArmCosmosDbMongoDatabaseRead(d, meta) +} + +func resourceArmCosmosDbMongoDatabaseRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).cosmosAccountsClient + ctx := meta.(*ArmClient).StopContext + + id, err := azure.ParseCosmosDatabaseID(d.Id()) + if err != nil { + return err + } + + resp, err := client.GetMongoDBDatabase(ctx, id.ResourceGroup, id.Account, id.Database) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + log.Printf("[INFO] Error reading Cosmos Mongo Database %s (Account %s) - removing from state", id.Database, id.Account) + d.SetId("") + return nil + } + + return fmt.Errorf("Error reading Cosmos Mongo Database %s (Account %s): %+v", id.Database, id.Account, err) + } + + d.Set("resource_group_name", id.ResourceGroup) + d.Set("account_name", id.Account) + if props := resp.MongoDBDatabaseProperties; props != nil { + d.Set("name", props.ID) + } + + return nil +} + +func resourceArmCosmosDbMongoDatabaseDelete(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).cosmosAccountsClient + ctx := meta.(*ArmClient).StopContext + + id, err := azure.ParseCosmosDatabaseID(d.Id()) + if err != nil { + return err + } + + future, err := client.DeleteMongoDBDatabase(ctx, id.ResourceGroup, id.Account, id.Database) + if err != nil { + if !response.WasNotFound(future.Response()) { + return fmt.Errorf("Error deleting Cosmos Mongo Database %s (Account %s): %+v", id.Database, id.Account, err) + } + } + + err = future.WaitForCompletionRef(ctx, client.Client) + if err != nil { + return fmt.Errorf("Error waiting on delete future for Cosmos Mongo Database %s (Account %s): %+v", id.Database, id.Account, err) + } + + return nil +} diff --git a/azurerm/resource_arm_cosmosdb_mongo_database_test.go b/azurerm/resource_arm_cosmosdb_mongo_database_test.go new file mode 100644 index 000000000000..448e6662bffc --- /dev/null +++ b/azurerm/resource_arm_cosmosdb_mongo_database_test.go @@ -0,0 +1,104 @@ +package azurerm + +import ( + "fmt" + "net/http" + "testing" + + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func TestAccAzureRMCosmosMongoDatabase_basic(t *testing.T) { + ri := tf.AccRandTimeInt() + resourceName := "azurerm_cosmosdb_mongo_database.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMCosmosMongoDatabaseDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMCosmosMongoDatabase_basic(ri, testLocation()), + Check: resource.ComposeAggregateTestCheckFunc( + testCheckAzureRMCosmosMongoDatabaseExists(resourceName), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testCheckAzureRMCosmosMongoDatabaseDestroy(s *terraform.State) error { + client := testAccProvider.Meta().(*ArmClient).cosmosAccountsClient + ctx := testAccProvider.Meta().(*ArmClient).StopContext + + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_cosmosdb_mongo_database" { + continue + } + + name := rs.Primary.Attributes["name"] + account := rs.Primary.Attributes["account_name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + + resp, err := client.GetMongoDBDatabase(ctx, resourceGroup, account, name) + if err != nil { + if !utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Bad: Error checking destroy for Cosmos Mongo Database %s (account %s) still exists:\n%v", name, account, err) + } + } + + if !utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Cosmos Mongo Database %s (account %s) still exists:\n%#v", name, account, resp) + } + } + + return nil +} + +func testCheckAzureRMCosmosMongoDatabaseExists(resourceName string) resource.TestCheckFunc { + return func(s *terraform.State) error { + client := testAccProvider.Meta().(*ArmClient).cosmosAccountsClient + ctx := testAccProvider.Meta().(*ArmClient).StopContext + + // Ensure we have enough information in state to look up in API + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return fmt.Errorf("Not found: %s", resourceName) + } + + name := rs.Primary.Attributes["name"] + account := rs.Primary.Attributes["account_name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + + resp, err := client.GetMongoDBDatabase(ctx, resourceGroup, account, name) + if err != nil { + return fmt.Errorf("Bad: Get on cosmosAccountsClient: %+v", err) + } + + if resp.StatusCode == http.StatusNotFound { + return fmt.Errorf("Bad: Cosmos database '%s' (account: '%s') does not exist", name, account) + } + + return nil + } +} + +func testAccAzureRMCosmosMongoDatabase_basic(rInt int, location string) string { + return fmt.Sprintf(` +%[1]s + +resource "azurerm_cosmosdb_mongo_database" "test" { + name = "acctest-%[2]d" + resource_group_name = "${azurerm_cosmosdb_account.test.resource_group_name}" + account_name = "${azurerm_cosmosdb_account.test.name}" +} +`, testAccAzureRMCosmosDBAccount_mongoDB(rInt, location), rInt) +} diff --git a/azurerm/resource_arm_cosmosdb_sql_database.go b/azurerm/resource_arm_cosmosdb_sql_database.go new file mode 100644 index 000000000000..0da710fa0981 --- /dev/null +++ b/azurerm/resource_arm_cosmosdb_sql_database.go @@ -0,0 +1,153 @@ +package azurerm + +import ( + "fmt" + "log" + + "github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2015-04-08/documentdb" + "github.com/hashicorp/terraform/helper/schema" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/response" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func resourceArmCosmosDbSQLDatabase() *schema.Resource { + return &schema.Resource{ + Create: resourceArmCosmosDbSQLDatabaseCreate, + Read: resourceArmCosmosDbSQLDatabaseRead, + Delete: resourceArmCosmosDbSQLDatabaseDelete, + + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validate.CosmosEntityName, + }, + + "resource_group_name": resourceGroupNameSchema(), + + "account_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validate.CosmosAccountName, + }, + }, + } +} + +func resourceArmCosmosDbSQLDatabaseCreate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).cosmosAccountsClient + ctx := meta.(*ArmClient).StopContext + + name := d.Get("name").(string) + resourceGroup := d.Get("resource_group_name").(string) + account := d.Get("account_name").(string) + + if requireResourcesToBeImported && d.IsNewResource() { + existing, err := client.GetSQLDatabase(ctx, resourceGroup, account, name) + if err != nil { + if !utils.ResponseWasNotFound(existing.Response) { + return fmt.Errorf("Error checking for presence of creating Cosmos SQL Database %s (Account %s): %+v", name, account, err) + } + } else { + id, err := azure.CosmosGetIDFromResponse(existing.Response) + if err != nil { + return fmt.Errorf("Error generating import ID for Cosmos SQL Database '%s' (Account %s)", name, account) + } + + return tf.ImportAsExistsError("azurerm_cosmosdb_sql_database", id) + } + } + + db := documentdb.SQLDatabaseCreateUpdateParameters{ + SQLDatabaseCreateUpdateProperties: &documentdb.SQLDatabaseCreateUpdateProperties{ + Resource: &documentdb.SQLDatabaseResource{ + ID: &name, + }, + Options: map[string]*string{}, + }, + } + + future, err := client.CreateUpdateSQLDatabase(ctx, resourceGroup, account, name, db) + if err != nil { + return fmt.Errorf("Error issuing create/update request for Cosmos SQL Database %s (Account %s): %+v", name, account, err) + } + + if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { + return fmt.Errorf("Error waiting on create/update future for Cosmos SQL Database %s (Account %s): %+v", name, account, err) + } + + resp, err := client.GetSQLDatabase(ctx, resourceGroup, account, name) + if err != nil { + return fmt.Errorf("Error making get request for Cosmos SQL Database %s (Account %s): %+v", name, account, err) + } + + id, err := azure.CosmosGetIDFromResponse(resp.Response) + if err != nil { + return fmt.Errorf("Error retrieving the ID for Cosmos SQL Database '%s' (Account %s) ID: %v", name, account, err) + } + d.SetId(id) + + return resourceArmCosmosDbSQLDatabaseRead(d, meta) +} + +func resourceArmCosmosDbSQLDatabaseRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).cosmosAccountsClient + ctx := meta.(*ArmClient).StopContext + + id, err := azure.ParseCosmosDatabaseID(d.Id()) + if err != nil { + return err + } + + resp, err := client.GetSQLDatabase(ctx, id.ResourceGroup, id.Account, id.Database) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + log.Printf("[INFO] Error reading Cosmos SQL Database %s (Account %s) - removing from state", id.Database, id.Account) + d.SetId("") + return nil + } + + return fmt.Errorf("Error reading Cosmos SQL Database %s (Account %s): %+v", id.Database, id.Account, err) + } + + d.Set("resource_group_name", id.ResourceGroup) + d.Set("account_name", id.Account) + if props := resp.SQLDatabaseProperties; props != nil { + d.Set("name", props.ID) + } + + return nil +} + +func resourceArmCosmosDbSQLDatabaseDelete(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).cosmosAccountsClient + ctx := meta.(*ArmClient).StopContext + + id, err := azure.ParseCosmosDatabaseID(d.Id()) + if err != nil { + return err + } + + future, err := client.DeleteSQLDatabase(ctx, id.ResourceGroup, id.Account, id.Database) + if err != nil { + if !response.WasNotFound(future.Response()) { + return fmt.Errorf("Error deleting Cosmos SQL Database %s (Account %s): %+v", id.Database, id.Account, err) + } + } + + err = future.WaitForCompletionRef(ctx, client.Client) + if err != nil { + return fmt.Errorf("Error waiting on delete future for Cosmos SQL Database %s (Account %s): %+v", id.Database, id.Account, err) + } + + return nil +} diff --git a/azurerm/resource_arm_cosmosdb_sql_database_test.go b/azurerm/resource_arm_cosmosdb_sql_database_test.go new file mode 100644 index 000000000000..b84d9b3ad355 --- /dev/null +++ b/azurerm/resource_arm_cosmosdb_sql_database_test.go @@ -0,0 +1,105 @@ +package azurerm + +import ( + "fmt" + "net/http" + "testing" + + "github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2015-04-08/documentdb" + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func TestAccAzureRMCosmosSQLDatabase_basic(t *testing.T) { + ri := tf.AccRandTimeInt() + resourceName := "azurerm_cosmosdb_sql_database.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMCosmosSQLDatabaseDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMCosmosSQLDatabase_basic(ri, testLocation()), + Check: resource.ComposeAggregateTestCheckFunc( + testCheckAzureRMCosmosSQLDatabaseExists(resourceName), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testCheckAzureRMCosmosSQLDatabaseDestroy(s *terraform.State) error { + client := testAccProvider.Meta().(*ArmClient).cosmosAccountsClient + ctx := testAccProvider.Meta().(*ArmClient).StopContext + + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_cosmosdb_sql_database" { + continue + } + + name := rs.Primary.Attributes["name"] + account := rs.Primary.Attributes["account_name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + + resp, err := client.GetSQLDatabase(ctx, resourceGroup, account, name) + if err != nil { + if !utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Bad: Error checking destroy for Cosmos SQL Database %s (account %s) still exists:\n%v", name, account, err) + } + } + + if !utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Cosmos SQL Database %s (account %s) still exists:\n%#v", name, account, resp) + } + } + + return nil +} + +func testCheckAzureRMCosmosSQLDatabaseExists(resourceName string) resource.TestCheckFunc { + return func(s *terraform.State) error { + client := testAccProvider.Meta().(*ArmClient).cosmosAccountsClient + ctx := testAccProvider.Meta().(*ArmClient).StopContext + + // Ensure we have enough information in state to look up in API + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return fmt.Errorf("Not found: %s", resourceName) + } + + name := rs.Primary.Attributes["name"] + account := rs.Primary.Attributes["account_name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + + resp, err := client.GetSQLDatabase(ctx, resourceGroup, account, name) + if err != nil { + return fmt.Errorf("Bad: Get on cosmosAccountsClient: %+v", err) + } + + if resp.StatusCode == http.StatusNotFound { + return fmt.Errorf("Bad: Cosmos database '%s' (account: '%s') does not exist", name, account) + } + + return nil + } +} + +func testAccAzureRMCosmosSQLDatabase_basic(rInt int, location string) string { + return fmt.Sprintf(` +%[1]s + +resource "azurerm_cosmosdb_sql_database" "test" { + name = "acctest-%[2]d" + resource_group_name = "${azurerm_cosmosdb_account.test.resource_group_name}" + account_name = "${azurerm_cosmosdb_account.test.name}" +} +`, testAccAzureRMCosmosDBAccount_basic(rInt, location, string(documentdb.Eventual), "", ""), rInt) +} diff --git a/azurerm/resource_arm_cosmosdb_table.go b/azurerm/resource_arm_cosmosdb_table.go new file mode 100644 index 000000000000..929a2dbfd632 --- /dev/null +++ b/azurerm/resource_arm_cosmosdb_table.go @@ -0,0 +1,153 @@ +package azurerm + +import ( + "fmt" + "log" + + "github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2015-04-08/documentdb" + "github.com/hashicorp/terraform/helper/schema" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/response" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func resourceArmCosmosDbTable() *schema.Resource { + return &schema.Resource{ + Create: resourceArmCosmosDbTableCreate, + Read: resourceArmCosmosDbTableRead, + Delete: resourceArmCosmosDbTableDelete, + + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validate.CosmosEntityName, + }, + + "resource_group_name": resourceGroupNameSchema(), + + "account_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validate.CosmosAccountName, + }, + }, + } +} + +func resourceArmCosmosDbTableCreate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).cosmosAccountsClient + ctx := meta.(*ArmClient).StopContext + + name := d.Get("name").(string) + resourceGroup := d.Get("resource_group_name").(string) + account := d.Get("account_name").(string) + + if requireResourcesToBeImported && d.IsNewResource() { + existing, err := client.GetTable(ctx, resourceGroup, account, name) + if err != nil { + if !utils.ResponseWasNotFound(existing.Response) { + return fmt.Errorf("Error checking for presence of creating Cosmos Table %s (Account %s): %+v", name, account, err) + } + } else { + id, err := azure.CosmosGetIDFromResponse(existing.Response) + if err != nil { + return fmt.Errorf("Error generating import ID for Cosmos Table '%s' (Account %s)", name, account) + } + + return tf.ImportAsExistsError("azurerm_cosmosdb_mongo_database", id) + } + } + + db := documentdb.TableCreateUpdateParameters{ + TableCreateUpdateProperties: &documentdb.TableCreateUpdateProperties{ + Resource: &documentdb.TableResource{ + ID: &name, + }, + Options: map[string]*string{}, + }, + } + + future, err := client.CreateUpdateTable(ctx, resourceGroup, account, name, db) + if err != nil { + return fmt.Errorf("Error issuing create/update request for Cosmos Table %s (Account %s): %+v", name, account, err) + } + + if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { + return fmt.Errorf("Error waiting on create/update future for Cosmos Table %s (Account %s): %+v", name, account, err) + } + + resp, err := client.GetTable(ctx, resourceGroup, account, name) + if err != nil { + return fmt.Errorf("Error making get request for Cosmos Table %s (Account %s): %+v", name, account, err) + } + + id, err := azure.CosmosGetIDFromResponse(resp.Response) + if err != nil { + return fmt.Errorf("Error retrieving the ID for Cosmos Table '%s' (Account %s) ID: %v", name, account, err) + } + d.SetId(id) + + return resourceArmCosmosDbTableRead(d, meta) +} + +func resourceArmCosmosDbTableRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).cosmosAccountsClient + ctx := meta.(*ArmClient).StopContext + + id, err := azure.ParseCosmosTableID(d.Id()) + if err != nil { + return err + } + + resp, err := client.GetTable(ctx, id.ResourceGroup, id.Account, id.Table) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + log.Printf("[INFO] Error reading Cosmos Table %s (Account %s) - removing from state", id.Table, id.Account) + d.SetId("") + return nil + } + + return fmt.Errorf("Error reading Cosmos Table %s (Account %s): %+v", id.Table, id.Account, err) + } + + d.Set("resource_group_name", id.ResourceGroup) + d.Set("account_name", id.Account) + if props := resp.TableProperties; props != nil { + d.Set("name", props.ID) + } + + return nil +} + +func resourceArmCosmosDbTableDelete(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).cosmosAccountsClient + ctx := meta.(*ArmClient).StopContext + + id, err := azure.ParseCosmosTableID(d.Id()) + if err != nil { + return err + } + + future, err := client.DeleteTable(ctx, id.ResourceGroup, id.Account, id.Table) + if err != nil { + if !response.WasNotFound(future.Response()) { + return fmt.Errorf("Error deleting Cosmos Table %s (Account %s): %+v", id.Table, id.Account, err) + } + } + + err = future.WaitForCompletionRef(ctx, client.Client) + if err != nil { + return fmt.Errorf("Error waiting on delete future for Cosmos Table %s (Account %s): %+v", id.Table, id.Account, err) + } + + return nil +} diff --git a/azurerm/resource_arm_cosmosdb_table_test.go b/azurerm/resource_arm_cosmosdb_table_test.go new file mode 100644 index 000000000000..cce96d646e17 --- /dev/null +++ b/azurerm/resource_arm_cosmosdb_table_test.go @@ -0,0 +1,104 @@ +package azurerm + +import ( + "fmt" + "net/http" + "testing" + + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func TestAccAzureRMCosmosTable_basic(t *testing.T) { + ri := tf.AccRandTimeInt() + resourceName := "azurerm_cosmosdb_table.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMCosmosTableDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMCosmosTable_basic(ri, testLocation()), + Check: resource.ComposeAggregateTestCheckFunc( + testCheckAzureRMCosmosTableExists(resourceName), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testCheckAzureRMCosmosTableDestroy(s *terraform.State) error { + client := testAccProvider.Meta().(*ArmClient).cosmosAccountsClient + ctx := testAccProvider.Meta().(*ArmClient).StopContext + + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_cosmosdb_table" { + continue + } + + name := rs.Primary.Attributes["name"] + account := rs.Primary.Attributes["account_name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + + resp, err := client.GetTable(ctx, resourceGroup, account, name) + if err != nil { + if !utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Bad: Error checking destroy for Cosmos Table %s (account %s) still exists:\n%v", name, account, err) + } + } + + if !utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Cosmos Table %s (account %s) still exists:\n%#v", name, account, resp) + } + } + + return nil +} + +func testCheckAzureRMCosmosTableExists(resourceName string) resource.TestCheckFunc { + return func(s *terraform.State) error { + client := testAccProvider.Meta().(*ArmClient).cosmosAccountsClient + ctx := testAccProvider.Meta().(*ArmClient).StopContext + + // Ensure we have enough information in state to look up in API + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return fmt.Errorf("Not found: %s", resourceName) + } + + name := rs.Primary.Attributes["name"] + account := rs.Primary.Attributes["account_name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + + resp, err := client.GetTable(ctx, resourceGroup, account, name) + if err != nil { + return fmt.Errorf("Bad: Get on cosmosAccountsClient: %+v", err) + } + + if resp.StatusCode == http.StatusNotFound { + return fmt.Errorf("Bad: Cosmos Table '%s' (account: '%s') does not exist", name, account) + } + + return nil + } +} + +func testAccAzureRMCosmosTable_basic(rInt int, location string) string { + return fmt.Sprintf(` +%[1]s + +resource "azurerm_cosmosdb_table" "test" { + name = "acctest-%[2]d" + resource_group_name = "${azurerm_cosmosdb_account.test.resource_group_name}" + account_name = "${azurerm_cosmosdb_account.test.name}" +} +`, testAccAzureRMCosmosDBAccount_capabilityTable(rInt, location), rInt) +} diff --git a/azurerm/resource_arm_sql_server.go b/azurerm/resource_arm_sql_server.go index 177ce78897b7..24a2bfeb7c41 100644 --- a/azurerm/resource_arm_sql_server.go +++ b/azurerm/resource_arm_sql_server.go @@ -114,7 +114,6 @@ func resourceArmSqlServerCreateUpdate(d *schema.ResourceData, meta interface{}) } if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - if response.WasConflict(future.Response()) { return fmt.Errorf("SQL Server names need to be globally unique and %q is already in use.", name) } diff --git a/go.mod b/go.mod index 4225209124e9..85404e9930ff 100644 --- a/go.mod +++ b/go.mod @@ -12,9 +12,10 @@ require ( github.com/hashicorp/go-multierror v1.0.0 github.com/hashicorp/go-uuid v1.0.1 github.com/hashicorp/terraform v0.12.0-alpha4.0.20190424121927-9327eedb0417 + github.com/katbyte/tctest v0.0.0-20190516150427-12a4ac6363f8 // indirect github.com/satori/go.uuid v1.2.0 github.com/satori/uuid v0.0.0-20160927100844-b061729afc07 - golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 - golang.org/x/net v0.0.0-20190311183353-d8887717615a + golang.org/x/crypto v0.0.0-20190506204251-e1dfcc566284 + golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 gopkg.in/yaml.v2 v2.2.2 ) diff --git a/go.sum b/go.sum index 7360e22ba5e2..c7105755d4b5 100644 --- a/go.sum +++ b/go.sum @@ -42,6 +42,7 @@ github.com/apparentlymart/go-textseg v1.0.0 h1:rRmlIsPEEhUTIKQb7T++Nz/A5Q6C9IuX2 github.com/apparentlymart/go-textseg v1.0.0/go.mod h1:z96Txxhf3xSFMPmb5X/1W05FF/Nj9VFpLOpjS5yuumk= github.com/armon/circbuf v0.0.0-20190214190532-5111143e8da2 h1:7Ip0wMmLHLRJdrloDxZfhMm0xrLXZS8+COSu2bXmEQs= github.com/armon/circbuf v0.0.0-20190214190532-5111143e8da2/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= +github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310 h1:BUAU3CGlLvorLI26FmByPp2eC2qla6E1Tw+scpcg/to= github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= @@ -71,6 +72,7 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk github.com/coreos/bbolt v1.3.0/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= github.com/coreos/etcd v3.3.10+incompatible h1:jFneRYjIvLMLhDLCzuTuU4rSJUjRplcJQ7pD7MnhC04= github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= +github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= github.com/coreos/go-semver v0.2.0 h1:3Jm3tLmsgAYcjC+4Up7hJrFBPr+n7rAqYeSw/SZazuY= github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-systemd v0.0.0-20181012123002-c6f51f82210d/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= @@ -93,6 +95,7 @@ github.com/dylanmei/winrmtest v0.0.0-20190225150635-99b7fe2fddf1/go.mod h1:lcy9/ github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= +github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= @@ -128,6 +131,8 @@ github.com/googleapis/gax-go v2.0.0+incompatible h1:j0GKcs05QVmm7yesiZq2+9cxHkNK github.com/googleapis/gax-go v2.0.0+incompatible/go.mod h1:SFVmujtThgffbyetf+mdk2eWhX2bMyUtNHzFKcPA9HY= github.com/googleapis/gax-go/v2 v2.0.3 h1:siORttZ36U2R/WjiJuDz8znElWBiAlO9rVt+mqJt0Cc= github.com/googleapis/gax-go/v2 v2.0.3/go.mod h1:LLvjysVCY1JZeum8Z6l8qUty8fiNwE08qbEPm1M08qg= +github.com/gookit/color v1.1.7 h1:WR5I/mhSHzemW2DzG54hTsUb7OzaREvkcmUG4/WST4Q= +github.com/gookit/color v1.1.7/go.mod h1:R3ogXq2B9rTbXoSHJ1HyUVAZ3poOJHpd9nQmyGZsfvQ= github.com/gophercloud/gophercloud v0.0.0-20190208042652-bc37892e1968 h1:Pu+HW4kcQozw0QyrTTgLE+3RXNqFhQNNzhbnoLFL83c= github.com/gophercloud/gophercloud v0.0.0-20190208042652-bc37892e1968/go.mod h1:3WdhXV3rUYy9p6AUW8d94kr+HS62Y4VL9mBnFxsD8q4= github.com/gophercloud/utils v0.0.0-20190128072930-fbb6ab446f01 h1:OgCNGSnEalfkRpn//WGJHhpo7fkP+LhTpvEITZ7CkK4= @@ -186,6 +191,8 @@ github.com/hashicorp/go-version v1.1.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09 github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/hcl v0.0.0-20170504190234-a4b07c25de5f h1:UdxlrJz4JOnY8W+DbLISwf2B8WXEolNRA8BGCwI9jws= github.com/hashicorp/hcl v0.0.0-20170504190234-a4b07c25de5f/go.mod h1:oZtUIOe8dh44I2q6ScRibXws4Ajl+d+nod3AaR9vL5w= +github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= +github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hashicorp/hcl2 v0.0.0-20181208003705-670926858200/go.mod h1:ShfpTh661oAaxo7VcNxg0zcZW6jvMa7Moy2oFx7e5dE= github.com/hashicorp/hcl2 v0.0.0-20190416162332-2c5a4b7d729a h1:doKt9ZBCYgYQrGK6CqJsEB+8xqm3WoFyKu4TPZlyymg= github.com/hashicorp/hcl2 v0.0.0-20190416162332-2c5a4b7d729a/go.mod h1:HtEzazM5AZ9fviNEof8QZB4T1Vz9UhHrGhnMPzl//Ek= @@ -204,6 +211,7 @@ github.com/hashicorp/vault v0.10.4/go.mod h1:KfSyffbKxoVyspOdlaGVjIuwLobi07qD1bA github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb h1:b5rjCoWHc7eqmAS4/qyk21ZsHyb6Mxv/jykxvNTkU4M= github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/jellevandenhooff/dkim v0.0.0-20150330215556-f50fe3d243e1/go.mod h1:E0B/fFc00Y+Rasa88328GlI/XbtyysCtTHZS8h7IrBU= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= @@ -216,9 +224,12 @@ github.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVY github.com/kardianos/osext v0.0.0-20170510131534-ae77be60afb1/go.mod h1:1NbS8ALrpOvjt0rHPNLyCIeMtbizbir8U//inJ+zuB8= github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 h1:iQTw/8FWTuc7uiaSepXwyf3o52HaUYcV+Tu66S3F5GA= github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0/go.mod h1:1NbS8ALrpOvjt0rHPNLyCIeMtbizbir8U//inJ+zuB8= +github.com/katbyte/tctest v0.0.0-20190516150427-12a4ac6363f8 h1:9h/MlBPZXkvV0DtpG8k1XTjUbyxqdSG2rn/qJJaba9A= +github.com/katbyte/tctest v0.0.0-20190516150427-12a4ac6363f8/go.mod h1:V9lgatLC6NYNKGfMLjp2w7cky3MCXq2r5UrpCywoIY4= github.com/keybase/go-crypto v0.0.0-20161004153544-93f5b35093ba/go.mod h1:ghbZscTyKdM07+Fw3KSi0hcJm+AlEUWj8QLlPtijN/M= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/konsorten/go-windows-terminal-sequences v0.0.0-20180402223658-b729f2633dfe/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= @@ -231,6 +242,8 @@ github.com/lib/pq v1.0.0 h1:X5PMW56eZitiTeO7tKzZxFCSpbFZJtkMMooicw2us9A= github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/lusis/go-artifactory v0.0.0-20160115162124-7e4ce345df82 h1:wnfcqULT+N2seWf6y4yHzmi7GD2kNx4Ute0qArktD48= github.com/lusis/go-artifactory v0.0.0-20160115162124-7e4ce345df82/go.mod h1:y54tfGmO3NKssKveTEFFzH8C/akrSOy/iW9qEAUDV84= +github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY= +github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/marstr/guid v1.1.0 h1:/M4H/1G4avsieL6BbUwCOBzulmoeKVP5ux/3mQNnbyI= github.com/marstr/guid v1.1.0/go.mod h1:74gB1z2wpxxInTG6yaqA7KrtM0NZ+RbrcqDvYHefzho= github.com/masterzen/simplexml v0.0.0-20160608183007-4572e39b1ab9 h1:SmVbOZFWAlyQshuMfOkiAx1f5oUTsOGG5IXplAEYeeM= @@ -291,6 +304,8 @@ github.com/openzipkin/zipkin-go v0.1.1/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTm github.com/packer-community/winrmcp v0.0.0-20180102160824-81144009af58 h1:m3CEgv3ah1Rhy82L+c0QG/U3VyY1UsvsIdkh0/rU97Y= github.com/packer-community/winrmcp v0.0.0-20180102160824-81144009af58/go.mod h1:f6Izs6JvFTdnRbziASagjZ2vmf55NSIkC/weStxCHqk= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= +github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc= +github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/pkg/errors v0.0.0-20170505043639-c605e284fe17 h1:chPfVn+gpAM5CTpTyVU9j8J+xgRGwmoDlNDLjKnJiYo= github.com/pkg/errors v0.0.0-20170505043639-c605e284fe17/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -334,17 +349,31 @@ github.com/shurcooL/sanitized_anchor_name v0.0.0-20170918181015-86672fcb3f95/go. github.com/shurcooL/users v0.0.0-20180125191416-49c67e49c537/go.mod h1:QJTqeLYEDaXHZDBsXlPCDqdhQuJkuw4NOtaxYe3xii4= github.com/shurcooL/webdavfs v0.0.0-20170829043945-18c3829fa133/go.mod h1:hKmq5kWdCj2z2KEozexVbfEZIWiTjhE0+UjmZgPqehw= github.com/sirupsen/logrus v1.1.1/go.mod h1:zrgwTnHtNr00buQ1vSptGe8m1f/BbgsPukg8qsT7A+A= +github.com/sirupsen/logrus v1.4.1 h1:GL2rEmy6nsikmW0r8opw9JIRScdMF5hA8cOYLH7In1k= +github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/goconvey v0.0.0-20180222194500-ef6db91d284a/go.mod h1:XDJAKZRPZ1CvBcN2aX5YOUTYGHki24fSF0Iv48Ibg0s= github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d/go.mod h1:UdhH50NIW0fCiwBSr0co2m7BnFLdv4fQTgdqdJTHFeE= github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e/go.mod h1:HuIsMU8RRBOtsCgI77wP899iHVBQpCmg4ErYMZB+2IA= +github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= github.com/spf13/afero v1.2.1 h1:qgMbHoJbPbw579P+1zVY+6n4nIFuIchaIjzZ/I/Yq8M= github.com/spf13/afero v1.2.1/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk= +github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8= +github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= +github.com/spf13/cobra v0.0.3 h1:ZlrZ4XsMRm04Fr5pSFxBgfND2EBVa1nLpiy1stUsX/8= +github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= +github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk= +github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= github.com/spf13/pflag v1.0.2/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg= +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/spf13/viper v1.3.2 h1:VUFqw5KcqRf7i70GOzW7N+Q7+gxVBkSSqiXB12+JQ4M= +github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= @@ -356,6 +385,7 @@ github.com/terraform-providers/terraform-provider-openstack v1.15.0/go.mod h1:2a github.com/tmc/grpc-websocket-proxy v0.0.0-20171017195756-830351dc03c6/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/ugorji/go v0.0.0-20180813092308-00b869d2f4a5 h1:cMjKdf4PxEBN9K5HaD9UMW8gkTbM0kMzkTa9SJe0WNQ= github.com/ugorji/go v0.0.0-20180813092308-00b869d2f4a5/go.mod h1:hnLbHMwcvSihnDhEfx2/BzKp2xb0Y+ErdfYcrs9tkJQ= +github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= github.com/ulikunitz/xz v0.5.5 h1:pFrO0lVpTBXLpYw+pnLj6TbvHuyjXMfjGeCwSqCVwok= github.com/ulikunitz/xz v0.5.5/go.mod h1:2bypXElzHzzJZwzH67Y6wb67pO62Rzfn7BSiF4ABRW8= github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= @@ -366,6 +396,7 @@ github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0B github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/xlab/treeprint v0.0.0-20161029104018-1d6e34225557 h1:Jpn2j6wHkC9wJv5iMfJhKqrZJx3TahFx+7sbZ7zQdxs= github.com/xlab/treeprint v0.0.0-20161029104018-1d6e34225557/go.mod h1:ce1O1j6UtZfjr22oyGxGLbauSBp2YVXpARAosm7dHBg= +github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= github.com/zclconf/go-cty v0.0.0-20181129180422-88fbe721e0f8/go.mod h1:xnAOWiHeOqg2nWS62VtQ7pbOu17FtxJNW8RLEih+O3s= github.com/zclconf/go-cty v0.0.0-20190124225737-a385d646c1e9/go.mod h1:xnAOWiHeOqg2nWS62VtQ7pbOu17FtxJNW8RLEih+O3s= github.com/zclconf/go-cty v0.0.0-20190320224746-fd76348b9329 h1:ne520NlvoncW5zfBGkmP4EJhyd6ruSaSyhzobv0Vz9w= @@ -383,10 +414,13 @@ golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnf golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181112202954-3d3f9f413869 h1:kkXA53yGe04D0adEYJwEVQjeBppL01Exg+fnMjfUraU= golang.org/x/crypto v0.0.0-20181112202954-3d3f9f413869/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190222235706-ffb98f73852f/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190506204251-e1dfcc566284 h1:rlLehGeYg6jfoyz/eDqDU1iRXLKfR42nnNh57ytKEWo= +golang.org/x/crypto v0.0.0-20190506204251-e1dfcc566284/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -403,6 +437,7 @@ golang.org/x/net v0.0.0-20190213061140-3a22650c66bd h1:HuTn7WObtcDo9uEEU7rEqL0jY golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a h1:oWX7TPOiFAMXLq8o0ikBYfCJVlRHBcsciT5bXOrH628= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181017192945-9dcd33a902f4/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890 h1:uESlIz09WIHT2I+pasSXcpLYqYK8wHcdCetU3VuMBJE= @@ -419,6 +454,7 @@ golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181029174526-d69651ed3497/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181213200352-4d1cda033e06/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190129075346-302c3dd5f1cc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU= @@ -426,6 +462,8 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190221075227-b4e8571b14e0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223 h1:DH4skfRX4EBpamg7iV4ZlCpblAHI6s6TDM39bFZumv8= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2 h1:z99zHgr7hKfrUcX/KsoJk5FJfjTceCKIp96+biqP4To= diff --git a/website/azurerm.erb b/website/azurerm.erb index d982f71e9417..6562cca2c1b3 100644 --- a/website/azurerm.erb +++ b/website/azurerm.erb @@ -692,6 +692,18 @@ > azurerm_cosmosdb_account + > + azurerm_cosmosdb_cassandra_keyspace + + > + azurerm_cosmosdb_mongo_database + + > + azurerm_cosmosdb_sql_database + + > + azurerm_cosmosdb_table + diff --git a/website/docs/r/cosmosdb_cassandra_keyspace.html.markdown b/website/docs/r/cosmosdb_cassandra_keyspace.html.markdown new file mode 100644 index 000000000000..a46024fa2be0 --- /dev/null +++ b/website/docs/r/cosmosdb_cassandra_keyspace.html.markdown @@ -0,0 +1,51 @@ +--- +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_cosmosdb_cassandra_keyspace" +sidebar_current: "docs-azurerm-resource-cosmosdb-cassandra-keyspace" +description: |- + Manages a Cassandra KeySpace within a Cosmos DB Account. +--- + +# azurerm_cosmosdb_cassandra_keyspace + +Manages a Cassandra KeySpace within a Cosmos DB Account. + +## Example Usage + +```hcl +data "azurerm_cosmosdb_account" "example" { + name = "tfex-cosmosdb-account" + resource_group_name = "tfex-cosmosdb-account-rg" +} + +resource "azurerm_cosmosdb_cassandra_keyspace" "example" { + name = "tfex-cosmos-cassandra-keyspace" + resource_group_name = "${data.azurerm_cosmosdb_account.example.resource_group_name}" + account_name = "${data.azurerm_cosmosdb_account.example.name}" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) Specifies the name of the Cosmos DB Cassandra KeySpace. Changing this forces a new resource to be created. + +* `resource_group_name` - (Required) The name of the resource group in which the Cosmos DB Cassandra KeySpace is created. Changing this forces a new resource to be created. + +* `account_name` - (Required) The name of the Cosmos DB Cassandra KeySpace to create the table within. Changing this forces a new resource to be created. + + +## Attributes Reference + +The following attributes are exported: + +* `id` - the Cosmos DB Cassandra KeySpace ID. + +## Import + +Cosmos Cassandra KeySpace can be imported using the `resource id`, e.g. + +```shell +terraform import azurerm_cosmosdb_cassandra_keyspace.ks1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg1/providers/Microsoft.DocumentDB/databaseAccounts/account1/apis/cassandra/keyspaces/ks1 +``` diff --git a/website/docs/r/cosmosdb_mongo_database.html.markdown b/website/docs/r/cosmosdb_mongo_database.html.markdown new file mode 100644 index 000000000000..8ba2543a74f3 --- /dev/null +++ b/website/docs/r/cosmosdb_mongo_database.html.markdown @@ -0,0 +1,51 @@ +--- +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_cosmosdb_mongo_database" +sidebar_current: "docs-azurerm-resource-cosmosdb-mongo-database" +description: |- + Manages a Mongo Database within a Cosmos DB Account. +--- + +# azurerm_cosmosdb_mongo_database + +Manages a Mongo Database within a Cosmos DB Account. + +## Example Usage + +```hcl +data "azurerm_cosmosdb_account" "example" { + name = "tfex-cosmosdb-account" + resource_group_name = "tfex-cosmosdb-account-rg" +} + +resource "azurerm_cosmosdb_mongo_database" "example" { + name = "tfex-cosmos-mongo-db" + resource_group_name = "${data.azurerm_cosmosdb_account.example.resource_group_name}" + account_name = "${data.azurerm_cosmosdb_account.example.name}" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) Specifies the name of the Cosmos DB Mongo Database. Changing this forces a new resource to be created. + +* `resource_group_name` - (Required) The name of the resource group in which the Cosmos DB Mongo Database is created. Changing this forces a new resource to be created. + +* `account_name` - (Required) The name of the Cosmos DB Mongo Database to create the table within. Changing this forces a new resource to be created. + + +## Attributes Reference + +The following attributes are exported: + +* `id` - the Cosmos DB Mongo Database ID. + +## Import + +Cosmos Mongo KeySpace can be imported using the `resource id`, e.g. + +```shell +terraform import azurerm_cosmosdb_mongo_database.db1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg1/providers/Microsoft.DocumentDB/databaseAccounts/account1/apis/mongodb/databases/db1 +``` diff --git a/website/docs/r/cosmosdb_sql_database.html.markdown b/website/docs/r/cosmosdb_sql_database.html.markdown new file mode 100644 index 000000000000..ec8d903249de --- /dev/null +++ b/website/docs/r/cosmosdb_sql_database.html.markdown @@ -0,0 +1,51 @@ +--- +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_cosmosdb_sql_database" +sidebar_current: "docs-azurerm-resource-cosmosdb-sql-database" +description: |- + Manages a SQL Database within a Cosmos DB Account. +--- + +# azurerm_cosmosdb_sql_database + +Manages a SQL Database within a Cosmos DB Account. + +## Example Usage + +```hcl +data "azurerm_cosmosdb_account" "example" { + name = "tfex-cosmosdb-account" + resource_group_name = "tfex-cosmosdb-account-rg" +} + +resource "azurerm_cosmosdb_sql_database" "example" { + name = "tfex-cosmos-mongo-db" + resource_group_name = "${data.azurerm_cosmosdb_account.example.resource_group_name}" + account_name = "${data.azurerm_cosmosdb_account.example.name}" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) Specifies the name of the Cosmos DB SQL Database. Changing this forces a new resource to be created. + +* `resource_group_name` - (Required) The name of the resource group in which the Cosmos DB SQL Database is created. Changing this forces a new resource to be created. + +* `account_name` - (Required) The name of the Cosmos DB SQL Database to create the table within. Changing this forces a new resource to be created. + + +## Attributes Reference + +The following attributes are exported: + +* `id` - the Cosmos DB SQL Database ID. + +## Import + +Cosmos SQL KeySpace can be imported using the `resource id`, e.g. + +```shell +terraform import azurerm_cosmosdb_sql_database.db1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg1/providers/Microsoft.DocumentDB/databaseAccounts/account1/apis/sql/databases/db1 +``` \ No newline at end of file diff --git a/website/docs/r/cosmosdb_table.html.markdown b/website/docs/r/cosmosdb_table.html.markdown new file mode 100644 index 000000000000..ea40cc0963bf --- /dev/null +++ b/website/docs/r/cosmosdb_table.html.markdown @@ -0,0 +1,51 @@ +--- +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_cosmosdb_table" +sidebar_current: "docs-azurerm-resource-cosmosdb-table" +description: |- + Manages a Table within a Cosmos DB Account. +--- + +# azurerm_cosmosdb_table + +Manages a Table within a Cosmos DB Account. + +## Example Usage + +```hcl +data "azurerm_cosmosdb_account" "example" { + name = "tfex-cosmosdb-account" + resource_group_name = "tfex-cosmosdb-account-rg" +} + +resource "azurerm_cosmosdb_table" "example" { + name = "tfex-cosmos-table" + resource_group_name = "${data.azurerm_cosmosdb_account.example.resource_group_name}" + account_name = "${data.azurerm_cosmosdb_account.example.name}" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) Specifies the name of the Cosmos DB Table. Changing this forces a new resource to be created. + +* `resource_group_name` - (Required) The name of the resource group in which the Cosmos DB Table is created. Changing this forces a new resource to be created. + +* `account_name` - (Required) The name of the Cosmos DB Table to create the table within. Changing this forces a new resource to be created. + + +## Attributes Reference + +The following attributes are exported: + +* `id` - the Cosmos DB Table ID. + +## Import + +Cosmos Tables can be imported using the `resource id`, e.g. + +```shell +terraform import azurerm_cosmosdb_table.t1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg1/providers/Microsoft.DocumentDB/databaseAccounts/account1/apis/table/tables/t1 +```