-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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_cosmos_db_account
: allow setting the Kind to MongoDB/GlobalDocumentDB
#299
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
|
@@ -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) | ||
|
||
|
@@ -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), | ||
} | ||
|
@@ -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)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would have thought There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we could, however I think it's worth being explicit that this value is coming from an external type? |
||
d.Set("offer_type", string(resp.DatabaseAccountOfferType)) | ||
d.Set("ip_range_filter", resp.IPRangeFilter) | ||
flattenAndSetAzureRmCosmosDBAccountConsistencyPolicy(d, resp.ConsistencyPolicy) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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()) | ||
|
||
|
@@ -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"), | ||
), | ||
}, | ||
}, | ||
|
@@ -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"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be nice to add a similar check to existing tests - just to verify that we expose the default kind. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccAzureRMCosmosDBAccount_session(t *testing.T) { | ||
ri := acctest.RandInt() | ||
config := testAccAzureRMCosmosDBAccount_session(ri, testLocation()) | ||
|
@@ -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" { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this is a ForceNew field, are you sure we don't need a state migration? Technically the old state will have empty
kind
(or nokind
to be precise) and we're setting default here, so"" => "global-document-db"
would cause recreation, unless I'm mistaken?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just verified - seems good since there's a default value and this field was missing previously: