Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_cosmosdb_account: add new capabilities EnableAggregationPipeline, MongoDBv3.4, mongoEnableDocLevelTTL #2715

Merged
merged 7 commits into from
Jan 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion azurerm/resource_arm_cosmos_db_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,10 @@ func resourceArmCosmosDBAccount() *schema.Resource {
ValidateFunc: validation.StringInSlice([]string{
"EnableTable",
"EnableGremlin",
`EnableCassandra`,
"EnableCassandra",
"EnableAggregationPipeline",
"MongoDBv3.4",
"mongoEnableDocLevelTTL",
tombuildsstuff marked this conversation as resolved.
Show resolved Hide resolved
}, true),
},
},
Expand Down Expand Up @@ -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{
katbyte marked this conversation as resolved.
Show resolved Hide resolved
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)
Expand Down Expand Up @@ -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)
Expand Down
186 changes: 179 additions & 7 deletions azurerm/resource_arm_cosmos_db_account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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"),
Expand All @@ -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"

Expand All @@ -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"),
Expand All @@ -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"

Expand Down Expand Up @@ -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"

Expand All @@ -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"

Expand All @@ -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"
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It’d be good to add a test handling an update here

Copy link
Contributor

Choose a reason for hiding this comment

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

Also a test with more than one - we have "MongoDB3.4" and "EnableAggregationPipeline" and a) I have no idea how to add to the .tf file and b) maybe the test should confirm that >1 capabilities can be added.

`)
}

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 {
Expand Down
8 changes: 4 additions & 4 deletions azurerm/resource_arm_ddos_protection_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/cosmosdb_account.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down