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 5 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
21 changes: 20 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,22 @@ 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)
}

future.WaitForCompletionRef(context.Background(), client.Client)
katbyte marked this conversation as resolved.
Show resolved Hide resolved
if 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
154 changes: 147 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,107 @@ 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 TestAbcAzureRMCosmosDBAccount_updatePropertiesAndLocation(t *testing.T) {
ri := tf.AccRandTimeInt()
resourceName := "azurerm_cosmosdb_account.test"

Expand Down Expand Up @@ -658,7 +758,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 +768,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 +778,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