diff --git a/azurerm/resource_arm_cosmos_db_account.go b/azurerm/resource_arm_cosmos_db_account.go index 9673bcb9f6d3..51fb5415a881 100644 --- a/azurerm/resource_arm_cosmos_db_account.go +++ b/azurerm/resource_arm_cosmos_db_account.go @@ -200,7 +200,10 @@ func resourceArmCosmosDBAccount() *schema.Resource { ValidateFunc: validation.StringInSlice([]string{ "EnableTable", "EnableGremlin", - `EnableCassandra`, + "EnableCassandra", + "EnableAggregationPipeline", + "MongoDBv3.4", + "mongoEnableDocLevelTTL", }, true), }, }, @@ -370,6 +373,21 @@ func resourceArmCosmosDBAccountCreate(d *schema.ResourceData, meta interface{}) return fmt.Errorf("Error creating CosmosDB Account %q (Resource Group %q): %+v", name, resourceGroup, err) } + //for some reason capabilities doesn't always work on create, so lets patch it + //tracked: https://github.com/Azure/azure-sdk-for-go/issues/2864 + future, err := client.Patch(ctx, resourceGroup, name, documentdb.DatabaseAccountPatchParameters{ + DatabaseAccountPatchProperties: &documentdb.DatabaseAccountPatchProperties{ + Capabilities: account.Capabilities, + }, + }) + if err != nil { + return fmt.Errorf("Error Patching CosmosDB Account %q (Resource Group %q): %+v", name, resourceGroup, err) + } + + if err := future.WaitForCompletionRef(context.Background(), client.Client); err != nil { + return fmt.Errorf("Error waiting on patch future CosmosDB Account %q (Resource Group %q): %+v", name, resourceGroup, err) + } + id := resp.ID if id == nil { return fmt.Errorf("Cannot read CosmosDB Account '%s' (resource group %s) ID", name, resourceGroup) @@ -508,6 +526,21 @@ func resourceArmCosmosDBAccountUpdate(d *schema.ResourceData, meta interface{}) return fmt.Errorf("Cannot read CosmosDB Account '%s' (resource group %s) ID", name, resourceGroup) } + //for some reason capabilities doesn't always work on create, so lets patch it + //tracked: https://github.com/Azure/azure-sdk-for-go/issues/2864 + future, err := client.Patch(ctx, resourceGroup, name, documentdb.DatabaseAccountPatchParameters{ + DatabaseAccountPatchProperties: &documentdb.DatabaseAccountPatchProperties{ + Capabilities: account.Capabilities, + }, + }) + if err != nil { + return fmt.Errorf("Error Patching CosmosDB Account %q (Resource Group %q): %+v", name, resourceGroup, err) + } + + if err := future.WaitForCompletionRef(context.Background(), client.Client); err != nil { + return fmt.Errorf("Error waiting on patch future CosmosDB Account %q (Resource Group %q): %+v", name, resourceGroup, err) + } + d.SetId(*id) return resourceArmCosmosDBAccountRead(d, meta) diff --git a/azurerm/resource_arm_cosmos_db_account_test.go b/azurerm/resource_arm_cosmos_db_account_test.go index 0c2caed40d0b..c9cde4eccbe0 100644 --- a/azurerm/resource_arm_cosmos_db_account_test.go +++ b/azurerm/resource_arm_cosmos_db_account_test.go @@ -291,7 +291,7 @@ func TestAccAzureRMCosmosDBAccount_mongoDB(t *testing.T) { }) } -func TestAccAzureRMCosmosDBAccount_gremlin(t *testing.T) { +func TestAccAzureRMCosmosDBAccount_capabilityGremlin(t *testing.T) { ri := tf.AccRandTimeInt() resourceName := "azurerm_cosmosdb_account.test" @@ -301,7 +301,7 @@ func TestAccAzureRMCosmosDBAccount_gremlin(t *testing.T) { CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMCosmosDBAccount_gremlin(ri, testLocation()), + Config: testAccAzureRMCosmosDBAccount_capabilityGremlin(ri, testLocation()), Check: resource.ComposeAggregateTestCheckFunc( checkAccAzureRMCosmosDBAccount_basic(resourceName, testLocation(), string(documentdb.BoundedStaleness), 1), resource.TestCheckResourceAttr(resourceName, "kind", "GlobalDocumentDB"), @@ -316,7 +316,7 @@ func TestAccAzureRMCosmosDBAccount_gremlin(t *testing.T) { }) } -func TestAccAzureRMCosmosDBAccount_table(t *testing.T) { +func TestAccAzureRMCosmosDBAccount_capabilityTable(t *testing.T) { ri := tf.AccRandTimeInt() resourceName := "azurerm_cosmosdb_account.test" @@ -326,7 +326,7 @@ func TestAccAzureRMCosmosDBAccount_table(t *testing.T) { CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMCosmosDBAccount_table(ri, testLocation()), + Config: testAccAzureRMCosmosDBAccount_capabilityTable(ri, testLocation()), Check: resource.ComposeAggregateTestCheckFunc( checkAccAzureRMCosmosDBAccount_basic(resourceName, testLocation(), string(documentdb.BoundedStaleness), 1), resource.TestCheckResourceAttr(resourceName, "kind", "GlobalDocumentDB"), @@ -341,7 +341,139 @@ func TestAccAzureRMCosmosDBAccount_table(t *testing.T) { }) } -func TestAccAzureRMCosmosDBAccount_updatePropertiesAndLocation(t *testing.T) { +func TestAccAzureRMCosmosDBAccount_capabilityCassandra(t *testing.T) { + ri := tf.AccRandTimeInt() + resourceName := "azurerm_cosmosdb_account.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMCosmosDBAccount_capabilityCassandra(ri, testLocation()), + Check: resource.ComposeAggregateTestCheckFunc( + checkAccAzureRMCosmosDBAccount_basic(resourceName, testLocation(), string(documentdb.BoundedStaleness), 1), + resource.TestCheckResourceAttr(resourceName, "kind", "GlobalDocumentDB"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMCosmosDBAccount_capabilityAggregationPipeline(t *testing.T) { + ri := tf.AccRandTimeInt() + resourceName := "azurerm_cosmosdb_account.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMCosmosDBAccount_capabilityAggregationPipeline(ri, testLocation()), + Check: resource.ComposeAggregateTestCheckFunc( + checkAccAzureRMCosmosDBAccount_basic(resourceName, testLocation(), string(documentdb.BoundedStaleness), 1), + resource.TestCheckResourceAttr(resourceName, "kind", "GlobalDocumentDB"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMCosmosDBAccount_capabilityMongo35(t *testing.T) { + ri := tf.AccRandTimeInt() + resourceName := "azurerm_cosmosdb_account.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMCosmosDBAccount_capabilityMongo34(ri, testLocation()), + Check: resource.ComposeAggregateTestCheckFunc( + checkAccAzureRMCosmosDBAccount_basic(resourceName, testLocation(), string(documentdb.BoundedStaleness), 1), + resource.TestCheckResourceAttr(resourceName, "kind", "MongoDB"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMCosmosDBAccount_capabilityDocLevelTTL(t *testing.T) { + ri := tf.AccRandTimeInt() + resourceName := "azurerm_cosmosdb_account.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMCosmosDBAccount_capabilityDocLevelTTL(ri, testLocation()), + Check: resource.ComposeAggregateTestCheckFunc( + checkAccAzureRMCosmosDBAccount_basic(resourceName, testLocation(), string(documentdb.BoundedStaleness), 1), + resource.TestCheckResourceAttr(resourceName, "kind", "MongoDB"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMCosmosDBAccount_capabilityUpdate(t *testing.T) { + ri := tf.AccRandTimeInt() + resourceName := "azurerm_cosmosdb_account.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMCosmosDBAccount_capabilityDocLevelTTL(ri, testLocation()), + Check: resource.ComposeAggregateTestCheckFunc( + checkAccAzureRMCosmosDBAccount_basic(resourceName, testLocation(), string(documentdb.BoundedStaleness), 1), + resource.TestCheckResourceAttr(resourceName, "kind", "MongoDB"), + ), + }, + { + Config: testAccAzureRMCosmosDBAccount_capabilityMongo34(ri, testLocation()), + Check: resource.ComposeAggregateTestCheckFunc( + checkAccAzureRMCosmosDBAccount_basic(resourceName, testLocation(), string(documentdb.BoundedStaleness), 1), + resource.TestCheckResourceAttr(resourceName, "kind", "MongoDB"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAbcAzureRMCosmosDBAccount_updatePropertiesAndLocation(t *testing.T) { ri := tf.AccRandTimeInt() resourceName := "azurerm_cosmosdb_account.test" @@ -658,7 +790,7 @@ func testAccAzureRMCosmosDBAccount_mongoDB(rInt int, location string) string { `) } -func testAccAzureRMCosmosDBAccount_gremlin(rInt int, location string) string { +func testAccAzureRMCosmosDBAccount_capabilityGremlin(rInt int, location string) string { return testAccAzureRMCosmosDBAccount_basic(rInt, location, string(documentdb.BoundedStaleness), "", ` kind = "GlobalDocumentDB" @@ -668,7 +800,7 @@ func testAccAzureRMCosmosDBAccount_gremlin(rInt int, location string) string { `) } -func testAccAzureRMCosmosDBAccount_table(rInt int, location string) string { +func testAccAzureRMCosmosDBAccount_capabilityTable(rInt int, location string) string { return testAccAzureRMCosmosDBAccount_basic(rInt, location, string(documentdb.BoundedStaleness), "", ` kind = "GlobalDocumentDB" @@ -678,6 +810,46 @@ func testAccAzureRMCosmosDBAccount_table(rInt int, location string) string { `) } +func testAccAzureRMCosmosDBAccount_capabilityCassandra(rInt int, location string) string { + return testAccAzureRMCosmosDBAccount_basic(rInt, location, string(documentdb.BoundedStaleness), "", ` + kind = "GlobalDocumentDB" + + capabilities = { + name = "EnableCassandra" + } + `) +} + +func testAccAzureRMCosmosDBAccount_capabilityAggregationPipeline(rInt int, location string) string { + return testAccAzureRMCosmosDBAccount_basic(rInt, location, string(documentdb.BoundedStaleness), "", ` + kind = "GlobalDocumentDB" + + capabilities = { + name = "EnableAggregationPipeline" + } + `) +} + +func testAccAzureRMCosmosDBAccount_capabilityMongo34(rInt int, location string) string { + return testAccAzureRMCosmosDBAccount_basic(rInt, location, string(documentdb.BoundedStaleness), "", ` + kind = "MongoDB" + + capabilities = { + name = "MongoDBv3.4" + } + `) +} + +func testAccAzureRMCosmosDBAccount_capabilityDocLevelTTL(rInt int, location string) string { + return testAccAzureRMCosmosDBAccount_basic(rInt, location, string(documentdb.BoundedStaleness), "", ` + kind = "MongoDB" + + capabilities = { + name = "mongoEnableDocLevelTTL" + } + `) +} + func testAccAzureRMCosmosDBAccount_geoReplicated(rInt int, location string, altLocation string) string { return testAccAzureRMCosmosDBAccount_basic(rInt, location, string(documentdb.BoundedStaleness), "", fmt.Sprintf(` geo_location { diff --git a/azurerm/resource_arm_ddos_protection_plan_test.go b/azurerm/resource_arm_ddos_protection_plan_test.go index 34c86b217e46..6f525d9eb64c 100644 --- a/azurerm/resource_arm_ddos_protection_plan_test.go +++ b/azurerm/resource_arm_ddos_protection_plan_test.go @@ -38,7 +38,7 @@ func testAccAzureRMDDoSProtectionPlan_basic(t *testing.T) { ri := tf.AccRandTimeInt() location := testLocation() - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testCheckAzureRMDDoSProtectionPlanDestroy, @@ -69,7 +69,7 @@ func testAccAzureRMDDoSProtectionPlan_requiresImport(t *testing.T) { ri := tf.AccRandTimeInt() location := testLocation() - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testCheckAzureRMDDoSProtectionPlanDestroy, @@ -93,7 +93,7 @@ func testAccAzureRMDDoSProtectionPlan_withTags(t *testing.T) { ri := tf.AccRandTimeInt() location := testLocation() - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testCheckAzureRMDDoSProtectionPlanDestroy, @@ -129,7 +129,7 @@ func testAccAzureRMDDoSProtectionPlan_disappears(t *testing.T) { ri := tf.AccRandTimeInt() location := testLocation() - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testCheckAzureRMDDoSProtectionPlanDestroy, diff --git a/website/docs/r/cosmosdb_account.html.markdown b/website/docs/r/cosmosdb_account.html.markdown index 4f627de7e90f..e119c247b535 100644 --- a/website/docs/r/cosmosdb_account.html.markdown +++ b/website/docs/r/cosmosdb_account.html.markdown @@ -75,7 +75,7 @@ The following arguments are supported: * `enable_automatic_failover` - (Optional) Enable automatic fail over for this Cosmos DB account. -* `capabilities` - (Optional) Enable capabilities for this Cosmos DB account. +* `capabilities` - (Optional) The capabilities which should be enabled for this Cosmos DB account. Possible values are `EnableAggregationPipeline`, `EnableCassandra`, `EnableGremlin`, `EnableTable`, `MongoDBv3.4`, and `mongoEnableDocLevelTTL`. * `is_virtual_network_filter_enabled` - (Optional) Enables virtual network filtering for this Cosmos DB account.