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_redis_cache: add replicas_per_master attribute #11714

Merged
merged 4 commits into from
May 16, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
18 changes: 18 additions & 0 deletions azurerm/internal/services/redis/redis_cache_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,13 @@ func resourceRedisCache() *schema.Resource {
Default: true,
},

"replicas_per_master": {
Type: schema.TypeInt,
Optional: true,
// Can't make more than 3 replicas in portal, assuming it's a limitation
ValidateFunc: validation.IntBetween(1, 3),
},

"tags": tags.Schema(),
},
}
Expand Down Expand Up @@ -345,6 +352,10 @@ func resourceRedisCacheCreate(d *schema.ResourceData, meta interface{}) error {
parameters.ShardCount = &shardCount
}

if v, ok := d.GetOk("replicas_per_master"); ok {
parameters.ReplicasPerMaster = utils.Int32(int32(v.(int)))
}

if v, ok := d.GetOk("private_static_ip_address"); ok {
parameters.StaticIP = utils.String(v.(string))
}
Expand Down Expand Up @@ -442,6 +453,12 @@ func resourceRedisCacheUpdate(d *schema.ResourceData, meta interface{}) error {
}
}

if v, ok := d.GetOk("replicas_per_master"); ok {
if d.HasChange("replicas_per_master") {
parameters.ReplicasPerMaster = utils.Int32(int32(v.(int)))
}
}

if d.HasChange("public_network_access_enabled") {
publicNetworkAccess := redis.Enabled
if !d.Get("public_network_access_enabled").(bool) {
Expand Down Expand Up @@ -562,6 +579,7 @@ func resourceRedisCacheRead(d *schema.ResourceData, meta interface{}) error {
d.Set("subnet_id", subnetId)

d.Set("public_network_access_enabled", props.PublicNetworkAccess == redis.Enabled)
d.Set("replicas_per_master", props.ReplicasPerMaster)
}

redisConfiguration, err := flattenRedisConfiguration(resp.RedisConfiguration)
Expand Down
38 changes: 38 additions & 0 deletions azurerm/internal/services/redis/redis_cache_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,20 @@ func TestAccRedisCache_WithoutAuth(t *testing.T) {
})
}

func TestAccRedisCache_ReplicasPerMaster(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_redis_cache", "test")
r := RedisCacheResource{}

data.ResourceTest(t, r, []resource.TestStep{
{
Config: r.replicasPerMaster(data),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
})
}

func (t RedisCacheResource) Exists(ctx context.Context, clients *clients.Client, state *terraform.InstanceState) (*bool, error) {
id, err := parse.CacheID(state.ID)
if err != nil {
Expand Down Expand Up @@ -1002,6 +1016,30 @@ resource "azurerm_redis_cache" "test" {
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger)
}

func (RedisCacheResource) replicasPerMaster(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

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

resource "azurerm_redis_cache" "test" {
name = "acctestRedis-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
capacity = 3
family = "P"
sku_name = "Premium"
enable_non_ssl_port = false
replicas_per_master = 3
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}

func testCheckSSLInConnectionString(resourceName string, propertyName string, requireSSL bool) resource.TestCheckFunc {
return func(s *terraform.State) error {
// Ensure we have enough information in state to look up in API
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/redis_cache.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ The following arguments are supported:

* `redis_configuration` - (Optional) A `redis_configuration` as defined below - with some limitations by SKU - defaults/details are shown below.

* `replicas_per_master` - (Optional) Amount of replicas to create per master for this Redis Cache.

* `shard_count` - (Optional) *Only available when using the Premium SKU* The number of Shards to create on the Redis Cluster.

* `subnet_id` - (Optional) *Only available when using the Premium SKU* The ID of the Subnet within which the Redis Cache should be deployed. This Subnet must only contain Azure Cache for Redis instances without any other type of resources. Changing this forces a new resource to be created.
Expand Down