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' - Support for 'primary_connection_string' and 'secondary_connection_string' to 'resource_arm_redis_cache' #5958

Merged
merged 2 commits into from
Mar 4, 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
20 changes: 19 additions & 1 deletion azurerm/internal/services/redis/data_source_redis_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,18 @@ func dataSourceArmRedisCache() *schema.Resource {
Sensitive: true,
},

"primary_connection_string": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
},

"secondary_connection_string": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
},

"tags": tags.SchemaDataSource(),
},
}
Expand Down Expand Up @@ -233,7 +245,8 @@ func dataSourceArmRedisCacheRead(d *schema.ResourceData, meta interface{}) error
d.Set("sku_name", sku.Name)
}

if props := resp.Properties; props != nil {
props := resp.Properties
if props != nil {
d.Set("ssl_port", props.SslPort)
d.Set("hostname", props.HostName)
d.Set("minimum_tls_version", string(props.MinimumTLSVersion))
Expand Down Expand Up @@ -275,5 +288,10 @@ func dataSourceArmRedisCacheRead(d *schema.ResourceData, meta interface{}) error
d.Set("primary_access_key", keys.PrimaryKey)
d.Set("secondary_access_key", keys.SecondaryKey)

if props != nil {
d.Set("primary_connection_string", getRedisConnectionString(*props.HostName, *props.SslPort, *keys.PrimaryKey, *props.EnableNonSslPort))
d.Set("secondary_connection_string", getRedisConnectionString(*props.HostName, *props.SslPort, *keys.SecondaryKey, *props.EnableNonSslPort))
}

return tags.FlattenAndSet(d, resp.Tags)
}
24 changes: 23 additions & 1 deletion azurerm/internal/services/redis/resource_arm_redis_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,18 @@ func resourceArmRedisCache() *schema.Resource {
Sensitive: true,
},

"primary_connection_string": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
},

"secondary_connection_string": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
},

"tags": tags.Schema(),
},
}
Expand Down Expand Up @@ -540,7 +552,8 @@ func resourceArmRedisCacheRead(d *schema.ResourceData, meta interface{}) error {
d.Set("sku_name", sku.Name)
}

if props := resp.Properties; props != nil {
props := resp.Properties
if props != nil {
d.Set("ssl_port", props.SslPort)
d.Set("hostname", props.HostName)
d.Set("minimum_tls_version", string(props.MinimumTLSVersion))
Expand All @@ -564,6 +577,11 @@ func resourceArmRedisCacheRead(d *schema.ResourceData, meta interface{}) error {
d.Set("primary_access_key", keysResp.PrimaryKey)
d.Set("secondary_access_key", keysResp.SecondaryKey)

if props != nil {
d.Set("primary_connection_string", getRedisConnectionString(*props.HostName, *props.SslPort, *keysResp.PrimaryKey, *props.EnableNonSslPort))
d.Set("secondary_connection_string", getRedisConnectionString(*props.HostName, *props.SslPort, *keysResp.SecondaryKey, *props.EnableNonSslPort))
}

return tags.FlattenAndSet(d, resp.Tags)
}

Expand Down Expand Up @@ -910,3 +928,7 @@ func validateRedisBackupFrequency(v interface{}, _ string) (warnings []string, e

return warnings, errors
}

func getRedisConnectionString(redisHostName string, sslPort int32, accessKey string, enableSslPort bool) string {
return fmt.Sprintf("%s:%d,password=%s,ssl=%t,abortConnect=False", redisHostName, sslPort, accessKey, enableSslPort)
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ func TestAccDataSourceAzureRMRedisCache_standard(t *testing.T) {
resource.TestCheckResourceAttr(data.ResourceName, "resource_group_name", resourceGroupName),
resource.TestCheckResourceAttr(data.ResourceName, "ssl_port", "6380"),
resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "production"),
resource.TestCheckResourceAttrSet(data.ResourceName, "primary_connection_string"),
resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_connection_string"),
),
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ func TestAccAzureRMRedisCache_basic(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMRedisCacheExists(data.ResourceName),
resource.TestCheckResourceAttrSet(data.ResourceName, "minimum_tls_version"),
resource.TestCheckResourceAttrSet(data.ResourceName, "primary_connection_string"),
resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_connection_string"),
),
},
data.ImportStep(),
Expand Down
4 changes: 4 additions & 0 deletions website/docs/d/redis_cache.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ output "hostname" {

* `secondary_access_key` - The Secondary Access Key for the Redis Instance

* `primary_connection_string` - The primary connection string of the Redis Instance.

* `secondary_connection_string` - The secondary connection string of the Redis Instance.

* `redis_configuration` - A `redis_configuration` block as defined below.

---
Expand Down
4 changes: 4 additions & 0 deletions website/docs/r/redis_cache.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ The following attributes are exported:

* `secondary_access_key` - The Secondary Access Key for the Redis Instance

* `primary_connection_string` - The primary connection string of the Redis Instance.

* `secondary_connection_string` - The secondary connection string of the Redis Instance.

* `redis_configuration` - A `redis_configuration` block as defined below:

---
Expand Down