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_cosmos_db_account - add support for enable_free_tier #7814

Merged
merged 8 commits into from
Jul 21, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ func dataSourceArmCosmosDbAccount() *schema.Resource {
Computed: true,
},

"enable_free_tier": {
Type: schema.TypeBool,
Computed: true,
},

"enable_automatic_failover": {
Type: schema.TypeBool,
Computed: true,
Expand Down Expand Up @@ -217,6 +222,7 @@ func dataSourceArmCosmosDbAccountRead(d *schema.ResourceData, meta interface{})
d.Set("ip_range_filter", common.CosmosDBIpRulesToIpRangeFilter(props.IPRules))
d.Set("endpoint", props.DocumentEndpoint)
d.Set("is_virtual_network_filter_enabled", resp.IsVirtualNetworkFilterEnabled)
d.Set("enable_free_tier", resp.EnableFreeTier)
d.Set("enable_automatic_failover", resp.EnableAutomaticFailover)

if err = d.Set("consistency_policy", flattenAzureRmCosmosDBAccountConsistencyPolicy(resp.ConsistencyPolicy)); err != nil {
Expand Down
13 changes: 13 additions & 0 deletions azurerm/internal/services/cosmos/cosmosdb_account_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ func resourceArmCosmosDbAccount() *schema.Resource {
),
},

"enable_free_tier": {
Type: schema.TypeBool,
Optional: true,
Default: false,
ForceNew: true,
},

"enable_automatic_failover": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -325,6 +332,7 @@ func resourceArmCosmosDbAccountCreate(d *schema.ResourceData, meta interface{})
offerType := d.Get("offer_type").(string)
ipRangeFilter := d.Get("ip_range_filter").(string)
isVirtualNetworkFilterEnabled := d.Get("is_virtual_network_filter_enabled").(bool)
enableFreeTier := d.Get("enable_free_tier").(bool)
enableAutomaticFailover := d.Get("enable_automatic_failover").(bool)
enableMultipleWriteLocations := d.Get("enable_multiple_write_locations").(bool)

Expand All @@ -351,6 +359,7 @@ func resourceArmCosmosDbAccountCreate(d *schema.ResourceData, meta interface{})
DatabaseAccountOfferType: utils.String(offerType),
IPRules: common.CosmosDBIpRangeFilterToIpRules(ipRangeFilter),
IsVirtualNetworkFilterEnabled: utils.Bool(isVirtualNetworkFilterEnabled),
EnableFreeTier: utils.Bool(enableFreeTier),
EnableAutomaticFailover: utils.Bool(enableAutomaticFailover),
ConsistencyPolicy: expandAzureRmCosmosDBAccountConsistencyPolicy(d),
Locations: &geoLocations,
Expand Down Expand Up @@ -403,6 +412,7 @@ func resourceArmCosmosDbAccountUpdate(d *schema.ResourceData, meta interface{})
offerType := d.Get("offer_type").(string)
ipRangeFilter := d.Get("ip_range_filter").(string)
isVirtualNetworkFilterEnabled := d.Get("is_virtual_network_filter_enabled").(bool)
enableFreeTier := d.Get("enable_free_tier").(bool)
enableAutomaticFailover := d.Get("enable_automatic_failover").(bool)
enableMultipleWriteLocations := d.Get("enable_multiple_write_locations").(bool)

Expand Down Expand Up @@ -439,6 +449,7 @@ func resourceArmCosmosDbAccountUpdate(d *schema.ResourceData, meta interface{})
DatabaseAccountOfferType: utils.String(offerType),
IPRules: common.CosmosDBIpRangeFilterToIpRules(ipRangeFilter),
IsVirtualNetworkFilterEnabled: utils.Bool(isVirtualNetworkFilterEnabled),
EnableFreeTier: utils.Bool(enableFreeTier),
EnableAutomaticFailover: utils.Bool(enableAutomaticFailover),
Capabilities: expandAzureRmCosmosDBAccountCapabilities(d),
ConsistencyPolicy: expandAzureRmCosmosDBAccountConsistencyPolicy(d),
Expand Down Expand Up @@ -538,6 +549,8 @@ func resourceArmCosmosDbAccountRead(d *schema.ResourceData, meta interface{}) er
d.Set("ip_range_filter", common.CosmosDBIpRulesToIpRangeFilter(resp.IPRules))
d.Set("endpoint", resp.DocumentEndpoint)

d.Set("enable_free_tier", resp.EnableFreeTier)

if v := resp.IsVirtualNetworkFilterEnabled; v != nil {
d.Set("is_virtual_network_filter_enabled", resp.IsVirtualNetworkFilterEnabled)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,26 @@ func TestAccAzureRMCosmosDBAccount_geoLocationsUpdate(t *testing.T) {
})
}

func TestAccAzureRMCosmosDBAccount_freeTier(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMCosmosDBAccount_freeTier(data, "GlobalDocumentDB", documentdb.Eventual),
Check: resource.ComposeAggregateTestCheckFunc(
checkAccAzureRMCosmosDBAccount_basic(data, documentdb.Eventual, 1),
resource.TestCheckResourceAttr(data.ResourceName, "enable_free_tier", "true"),
),
},
data.ImportStep(),
},
})
}

func TestAccAzureRMCosmosDBAccount_vNetFilters(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test")

Expand Down Expand Up @@ -817,6 +837,38 @@ resource "azurerm_cosmosdb_account" "test" {
`, testAccAzureRMCosmosDBAccount_vNetFiltersPreReqs(data), data.RandomInteger)
}

func testAccAzureRMCosmosDBAccount_freeTier(data acceptance.TestData, kind documentdb.DatabaseAccountKind, consistency documentdb.DefaultConsistencyLevel) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "test" {
name = "acctestRG-cosmos-%d"
location = "%s"
}

resource "azurerm_cosmosdb_account" "test" {
name = "acctest-ca-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
offer_type = "Standard"
kind = "%s"

enable_free_tier = true

consistency_policy {
consistency_level = "%s"
}

geo_location {
location = azurerm_resource_group.test.location
failover_priority = 0
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, string(kind), string(consistency))
}

func checkAccAzureRMCosmosDBAccount_basic(data acceptance.TestData, consistency documentdb.DefaultConsistencyLevel, locationCount int) resource.TestCheckFunc {
return resource.ComposeTestCheckFunc(
testCheckAzureRMCosmosDBAccountExists(data.ResourceName),
Expand Down
2 changes: 2 additions & 0 deletions website/docs/d/cosmosdb_account.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ The following attributes are exported:

* `ip_range_filter` - The current IP Filter for this CosmosDB account

* `enable_free_tier` - If Free Tier pricing option is enabled for this CosmosDB Account.

* `enable_automatic_failover` - If automatic failover is enabled for this CosmosDB Account.

* `capabilities` - Capabilities enabled on this Cosmos DB account.
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 @@ -73,6 +73,8 @@ The following arguments are supported:

* `ip_range_filter` - (Optional) CosmosDB Firewall Support: This value specifies the set of IP addresses or IP address ranges in CIDR form to be included as the allowed list of client IP's for a given database account. IP addresses/ranges must be comma separated and must not contain any spaces.

* `enable_free_tier` - (Optional) Enable Free Tier pricing option for this Cosmos DB account. Defaults to `false`. Changing this forces a new resource to be created.

* `enable_automatic_failover` - (Optional) Enable automatic fail over 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`.
Expand Down