Skip to content

Commit 45857ef

Browse files
authored
'azurerm_redis_cache' - Support for 'primary_connection_string'… (#5958)
* #5856 - Add 'primary_connection_string' and 'secondary_connection_string' to 'resource_arm_redis_cache' resource and data source Resource Acceptance Tests: === RUN TestAccDataSourceAzureRMRedisCache_standard === PAUSE TestAccDataSourceAzureRMRedisCache_standard === CONT TestAccDataSourceAzureRMRedisCache_standard --- PASS: TestAccDataSourceAzureRMRedisCache_standard (2127.56s) PASS ok github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/redis/tests 2127.824s * Fix linting issue
1 parent e03c1bc commit 45857ef

6 files changed

+54
-2
lines changed

azurerm/internal/services/redis/data_source_redis_cache.go

+19-1
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,18 @@ func dataSourceArmRedisCache() *schema.Resource {
196196
Sensitive: true,
197197
},
198198

199+
"primary_connection_string": {
200+
Type: schema.TypeString,
201+
Computed: true,
202+
Sensitive: true,
203+
},
204+
205+
"secondary_connection_string": {
206+
Type: schema.TypeString,
207+
Computed: true,
208+
Sensitive: true,
209+
},
210+
199211
"tags": tags.SchemaDataSource(),
200212
},
201213
}
@@ -233,7 +245,8 @@ func dataSourceArmRedisCacheRead(d *schema.ResourceData, meta interface{}) error
233245
d.Set("sku_name", sku.Name)
234246
}
235247

236-
if props := resp.Properties; props != nil {
248+
props := resp.Properties
249+
if props != nil {
237250
d.Set("ssl_port", props.SslPort)
238251
d.Set("hostname", props.HostName)
239252
d.Set("minimum_tls_version", string(props.MinimumTLSVersion))
@@ -275,5 +288,10 @@ func dataSourceArmRedisCacheRead(d *schema.ResourceData, meta interface{}) error
275288
d.Set("primary_access_key", keys.PrimaryKey)
276289
d.Set("secondary_access_key", keys.SecondaryKey)
277290

291+
if props != nil {
292+
d.Set("primary_connection_string", getRedisConnectionString(*props.HostName, *props.SslPort, *keys.PrimaryKey, *props.EnableNonSslPort))
293+
d.Set("secondary_connection_string", getRedisConnectionString(*props.HostName, *props.SslPort, *keys.SecondaryKey, *props.EnableNonSslPort))
294+
}
295+
278296
return tags.FlattenAndSet(d, resp.Tags)
279297
}

azurerm/internal/services/redis/resource_arm_redis_cache.go

+23-1
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,18 @@ func resourceArmRedisCache() *schema.Resource {
257257
Sensitive: true,
258258
},
259259

260+
"primary_connection_string": {
261+
Type: schema.TypeString,
262+
Computed: true,
263+
Sensitive: true,
264+
},
265+
266+
"secondary_connection_string": {
267+
Type: schema.TypeString,
268+
Computed: true,
269+
Sensitive: true,
270+
},
271+
260272
"tags": tags.Schema(),
261273
},
262274
}
@@ -540,7 +552,8 @@ func resourceArmRedisCacheRead(d *schema.ResourceData, meta interface{}) error {
540552
d.Set("sku_name", sku.Name)
541553
}
542554

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

580+
if props != nil {
581+
d.Set("primary_connection_string", getRedisConnectionString(*props.HostName, *props.SslPort, *keysResp.PrimaryKey, *props.EnableNonSslPort))
582+
d.Set("secondary_connection_string", getRedisConnectionString(*props.HostName, *props.SslPort, *keysResp.SecondaryKey, *props.EnableNonSslPort))
583+
}
584+
567585
return tags.FlattenAndSet(d, resp.Tags)
568586
}
569587

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

911929
return warnings, errors
912930
}
931+
932+
func getRedisConnectionString(redisHostName string, sslPort int32, accessKey string, enableSslPort bool) string {
933+
return fmt.Sprintf("%s:%d,password=%s,ssl=%t,abortConnect=False", redisHostName, sslPort, accessKey, enableSslPort)
934+
}

azurerm/internal/services/redis/tests/data_source_redis_cache_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ func TestAccDataSourceAzureRMRedisCache_standard(t *testing.T) {
2727
resource.TestCheckResourceAttr(data.ResourceName, "resource_group_name", resourceGroupName),
2828
resource.TestCheckResourceAttr(data.ResourceName, "ssl_port", "6380"),
2929
resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "production"),
30+
resource.TestCheckResourceAttrSet(data.ResourceName, "primary_connection_string"),
31+
resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_connection_string"),
3032
),
3133
},
3234
},

azurerm/internal/services/redis/tests/resource_arm_redis_cache_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ func TestAccAzureRMRedisCache_basic(t *testing.T) {
2525
Check: resource.ComposeTestCheckFunc(
2626
testCheckAzureRMRedisCacheExists(data.ResourceName),
2727
resource.TestCheckResourceAttrSet(data.ResourceName, "minimum_tls_version"),
28+
resource.TestCheckResourceAttrSet(data.ResourceName, "primary_connection_string"),
29+
resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_connection_string"),
2830
),
2931
},
3032
data.ImportStep(),

website/docs/d/redis_cache.html.markdown

+4
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ output "hostname" {
6363

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

66+
* `primary_connection_string` - The primary connection string of the Redis Instance.
67+
68+
* `secondary_connection_string` - The secondary connection string of the Redis Instance.
69+
6670
* `redis_configuration` - A `redis_configuration` block as defined below.
6771

6872
---

website/docs/r/redis_cache.html.markdown

+4
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ The following attributes are exported:
153153

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

156+
* `primary_connection_string` - The primary connection string of the Redis Instance.
157+
158+
* `secondary_connection_string` - The secondary connection string of the Redis Instance.
159+
156160
* `redis_configuration` - A `redis_configuration` block as defined below:
157161

158162
---

0 commit comments

Comments
 (0)