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

Add availability zone support for Redis cache #2580

Merged
merged 3 commits into from
Dec 29, 2018
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
9 changes: 9 additions & 0 deletions azurerm/resource_arm_redis_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ func resourceArmRedisCache() *schema.Resource {

"resource_group_name": resourceGroupNameSchema(),

"zones": singleZonesSchema(),

"capacity": {
Type: schema.TypeInt,
Required: true,
Expand Down Expand Up @@ -249,6 +251,10 @@ func resourceArmRedisCacheCreate(d *schema.ResourceData, meta interface{}) error
parameters.SubnetID = utils.String(v.(string))
}

if v, ok := d.GetOk("zones"); ok {
parameters.Zones = expandZones(v.([]interface{}))
}

future, err := client.Create(ctx, resGroup, name, parameters)
if err != nil {
return err
Expand Down Expand Up @@ -422,6 +428,9 @@ func resourceArmRedisCacheRead(d *schema.ResourceData, meta interface{}) error {
if location := resp.Location; location != nil {
d.Set("location", azureRMNormalizeLocation(*location))
}
if zones := resp.Zones; zones != nil {
d.Set("zones", zones)
}

if sku := resp.Sku; sku != nil {
d.Set("capacity", sku.Capacity)
Expand Down
63 changes: 63 additions & 0 deletions azurerm/resource_arm_redis_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,33 @@ func TestAccAzureRMRedisCache_InternalSubnetStaticIP(t *testing.T) {
})
}

func TestAccAzureRMRedisCache_InternalSubnet_withZone(t *testing.T) {
resourceName := "azurerm_redis_cache.test"
ri := acctest.RandInt()
config := testAccAzureRMRedisCache_internalSubnet_withZone(ri, testLocation())

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMRedisCacheDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMRedisCacheExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "zones.#", "1"),
resource.TestCheckResourceAttr(resourceName, "zones.0", "1"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testCheckAzureRMRedisCacheExists(name string) resource.TestCheckFunc {
return func(s *terraform.State) error {
// Ensure we have enough information in state to look up in API
Expand Down Expand Up @@ -865,3 +892,39 @@ resource "azurerm_redis_cache" "test" {
}
`, ri, location, ri, ri)
}

func testAccAzureRMRedisCache_internalSubnet_withZone(ri int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}

resource "azurerm_virtual_network" "test" {
name = "acctestnw-%d"
address_space = ["10.0.0.0/16"]
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
}

resource "azurerm_subnet" "test" {
name = "testsubnet"
resource_group_name = "${azurerm_resource_group.test.name}"
virtual_network_name = "${azurerm_virtual_network.test.name}"
address_prefix = "10.0.1.0/24"
}

resource "azurerm_redis_cache" "test" {
name = "acctestRedis-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
capacity = 1
family = "P"
sku_name = "Premium"
enable_non_ssl_port = false
subnet_id = "${azurerm_subnet.test.id}"
redis_configuration = {}
zones = ["1"]
}
`, ri, location, ri, ri)
}
3 changes: 3 additions & 0 deletions website/docs/r/redis_cache.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ The pricing group for the Redis Family - either "C" or "P" at present.

* `tags` - (Optional) A mapping of tags to assign to the resource.

* `zones` - (Optional) A list of a single item of the Availability Zone which the Redis Cache should be allocated in.

-> **Please Note**: Availability Zones are [in Preview and only supported in several regions at this time](https://docs.microsoft.com/en-us/azure/availability-zones/az-overview) - as such you must be opted into the Preview to use this functionality. You can [opt into the Availability Zones Preview in the Azure Portal](http://aka.ms/azenroll).
---

* `redis_configuration` supports the following:
Expand Down