Skip to content

Commit

Permalink
Add support for enable_authentication parameter under redis_configura…
Browse files Browse the repository at this point in the history
…tion to disable authentication
  • Loading branch information
Abhinav I committed May 8, 2019
1 parent f2cde3b commit 85367cc
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
33 changes: 33 additions & 0 deletions azurerm/resource_arm_redis_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ func resourceArmRedisCache() *schema.Resource {
Optional: true,
Sensitive: true,
},
"enable_authentication": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},
},
},
},
Expand Down Expand Up @@ -660,6 +665,12 @@ func expandRedisConfiguration(d *schema.ResourceData) map[string]*string {
output["aof-storage-connection-string-1"] = utils.String(v.(string))
}

// Redis Auth
if v, ok := d.GetOk("redis_configuration.0.enable_authentication"); ok {
value := isAuthNotRequiredAsString(v.(bool))
output["authnotrequired"] = utils.String(value)
}

return output
}

Expand Down Expand Up @@ -770,9 +781,31 @@ func flattenRedisConfiguration(input map[string]*string) ([]interface{}, error)
outputs["aof_storage_connection_string_1"] = *v
}

// Redis Auth
if v := input["authnotrequired"]; v != nil {
outputs["enable_authentication"] = isAuthRequiredAsBool(*v)
}

return []interface{}{outputs}, nil
}

func isAuthRequiredAsBool(not_required string) bool {
value := strings.ToLower(not_required)
output := map[string]bool{
"yes": false,
"no": true,
}
return output[value]
}

func isAuthNotRequiredAsString(auth_required bool) string {
output := map[bool]string{
true: "no",
false: "yes",
}
return output[auth_required]
}

func flattenRedisPatchSchedules(schedule redis.PatchSchedule) []interface{} {
outputs := make([]interface{}, 0)

Expand Down
57 changes: 57 additions & 0 deletions azurerm/resource_arm_redis_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,28 @@ func TestAccAzureRMRedisCache_SubscribeAllEvents(t *testing.T) {
})
}

func TestAccAzureRMRedisCacheWithoutAuth(t *testing.T) {
resourceName := "azurerm_redis_cache.test"
ri := tf.AccRandTimeInt()
rs := acctest.RandString(4)
config := testAccAzureRMRedisCacheWithoutAuth(ri, rs, 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, "redis_configuration.0.enable_authentication", "false"),
),
},
},
})
}

func testAccAzureRMRedisCache_basic(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
Expand Down Expand Up @@ -1095,3 +1117,38 @@ resource "azurerm_redis_cache" "test" {
}
`, ri, location, ri, ri)
}

func testAccAzureRMRedisCacheWithoutAuth(rInt int, rString string, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}
resource "azurerm_storage_account" "test" {
name = "unlikely23exst2acct%s"
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
account_tier = "Standard"
account_replication_type = "GRS"
tags = {
environment = "staging"
}
}
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
redis_configuration {
enable_authentication = false
}
}
`, rInt, location, rString, rInt)
}
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 @@ -80,6 +80,8 @@ The following arguments are supported:

A `redis_configuration` block supports the following:

* `enable_authentication` - (Optional) If set to `false`, the Redis instance will be accessible without authentication. Defaults to `true`.

* `maxmemory_reserved` - (Optional) Value in megabytes reserved for non-cache usage e.g. failover. Defaults are shown below.
* `maxmemory_delta` - (Optional) The max-memory delta for this Redis instance. Defaults are shown below.
* `maxmemory_policy` - (Optional) How Redis will select what to remove when `maxmemory` is reached. Defaults are shown below.
Expand Down Expand Up @@ -114,6 +116,7 @@ redis_configuration {

| Redis Value | Basic | Standard | Premium |
| ------------------------------- | ------------ | ------------ | ------------ |
| enable_authentication | true | true | true |
| maxmemory_reserved | 2 | 50 | 200 |
| maxfragmentationmemory_reserved | 2 | 50 | 200 |
| maxmemory_delta | 2 | 50 | 200 |
Expand Down

0 comments on commit 85367cc

Please sign in to comment.