Skip to content

Commit

Permalink
Merge pull request #299 from terraform-providers/cosmosdb-type
Browse files Browse the repository at this point in the history
`azurerm_cosmos_db_account`: allow setting the Kind to MongoDB/GlobalDocumentDB
  • Loading branch information
tombuildsstuff authored Sep 1, 2017
2 parents 5e91859 + 471b6b0 commit 29bb84b
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 5 deletions.
24 changes: 24 additions & 0 deletions azurerm/import_arm_cosmosdb_account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,30 @@ func TestAccAzureRMCosmosDBAccount_importEventualConsistency(t *testing.T) {
})
}

func TestAccAzureRMCosmosDBAccount_importMongoDB(t *testing.T) {
resourceName := "azurerm_cosmosdb_account.test"

ri := acctest.RandInt()
config := testAccAzureRMCosmosDBAccount_mongoDB(ri, testLocation())

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy,
Steps: []resource.TestStep{
{
Config: config,
},

{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAzureRMCosmosDBAccount_importSession(t *testing.T) {
resourceName := "azurerm_cosmosdb_account.test"

Expand Down
21 changes: 18 additions & 3 deletions azurerm/resource_arm_cosmos_db_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ func resourceArmCosmosDBAccount() *schema.Resource {
}, true),
},

"kind": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Default: string(cosmosdb.GlobalDocumentDB),
ValidateFunc: validation.StringInSlice([]string{
string(cosmosdb.GlobalDocumentDB),
string(cosmosdb.MongoDB),
}, true),
DiffSuppressFunc: ignoreCaseDiffSuppressFunc,
},

"ip_range_filter": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -152,6 +164,7 @@ func resourceArmCosmosDBAccountCreateUpdate(d *schema.ResourceData, meta interfa
name := d.Get("name").(string)
location := d.Get("location").(string)
resGroup := d.Get("resource_group_name").(string)
kind := d.Get("kind").(string)
offerType := d.Get("offer_type").(string)
ipRangeFilter := d.Get("ip_range_filter").(string)

Expand All @@ -163,12 +176,13 @@ func resourceArmCosmosDBAccountCreateUpdate(d *schema.ResourceData, meta interfa
tags := d.Get("tags").(map[string]interface{})

parameters := cosmosdb.DatabaseAccountCreateUpdateParameters{
Location: &location,
Location: utils.String(location),
Kind: cosmosdb.DatabaseAccountKind(kind),
DatabaseAccountCreateUpdateProperties: &cosmosdb.DatabaseAccountCreateUpdateProperties{
ConsistencyPolicy: &consistencyPolicy,
DatabaseAccountOfferType: &offerType,
Locations: &failoverPolicies,
IPRangeFilter: &ipRangeFilter,
DatabaseAccountOfferType: utils.String(offerType),
IPRangeFilter: utils.String(ipRangeFilter),
},
Tags: expandTags(tags),
}
Expand Down Expand Up @@ -215,6 +229,7 @@ func resourceArmCosmosDBAccountRead(d *schema.ResourceData, meta interface{}) er
d.Set("name", resp.Name)
d.Set("location", azureRMNormalizeLocation(*resp.Location))
d.Set("resource_group_name", resGroup)
d.Set("kind", string(resp.Kind))
d.Set("offer_type", string(resp.DatabaseAccountOfferType))
d.Set("ip_range_filter", resp.IPRangeFilter)
flattenAndSetAzureRmCosmosDBAccountConsistencyPolicy(d, resp.ConsistencyPolicy)
Expand Down
52 changes: 50 additions & 2 deletions azurerm/resource_arm_cosmos_db_account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestAccAzureRMCosmosDBAccountName_validation(t *testing.T) {
}

func TestAccAzureRMCosmosDBAccount_boundedStaleness(t *testing.T) {

resourceName := "azurerm_cosmosdb_account.test"
ri := acctest.RandInt()
config := testAccAzureRMCosmosDBAccount_boundedStaleness(ri, testLocation())

Expand All @@ -64,7 +64,8 @@ func TestAccAzureRMCosmosDBAccount_boundedStaleness(t *testing.T) {
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMCosmosDBAccountExists("azurerm_cosmosdb_account.test"),
testCheckAzureRMCosmosDBAccountExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "kind", "GlobalDocumentDB"),
),
},
},
Expand Down Expand Up @@ -110,6 +111,27 @@ func TestAccAzureRMCosmosDBAccount_eventualConsistency(t *testing.T) {
})
}

func TestAccAzureRMCosmosDBAccount_mongoDB(t *testing.T) {
resourceName := "azurerm_cosmosdb_account.test"
ri := acctest.RandInt()
config := testAccAzureRMCosmosDBAccount_mongoDB(ri, testLocation())

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMCosmosDBAccountExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "kind", "MongoDB"),
),
},
},
})
}

func TestAccAzureRMCosmosDBAccount_session(t *testing.T) {
ri := acctest.RandInt()
config := testAccAzureRMCosmosDBAccount_session(ri, testLocation())
Expand Down Expand Up @@ -324,6 +346,32 @@ resource "azurerm_cosmosdb_account" "test" {
`, rInt, location, rInt)
}

func testAccAzureRMCosmosDBAccount_mongoDB(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}
resource "azurerm_cosmosdb_account" "test" {
name = "acctest-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
kind = "MongoDB"
offer_type = "Standard"
consistency_policy {
consistency_level = "BoundedStaleness"
}
failover_policy {
location = "${azurerm_resource_group.test.location}"
priority = 0
}
}
`, rInt, location, rInt)
}

func testAccAzureRMCosmosDBAccount_strong(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/cosmosdb_account.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ The following arguments are supported:

* `offer_type` - (Required) Specifies the Offer Type to use for this CosmosDB Account - currently this can only be set to `Standard`.

* `kind` - (Optional) Specifies the Kind of CosmosDB to create - possible values are `GlobalDocumentDB` and `MongoDB`. Defaults to `GlobalDocumentDB`. Changing this forces a new resource to be created.

* `consistency_policy` - (Required) Specifies a `consistency_policy` resource, used to define the consistency policy for this CosmosDB account.

* `failover_policy` - (Required) Specifies a `failover_policy` resource, used to define where data should be replicated.
Expand Down

0 comments on commit 29bb84b

Please sign in to comment.