Skip to content

Commit

Permalink
Add public_network_access_enabled to azurerm_redis_cache (#10410)
Browse files Browse the repository at this point in the history
To address issue #9307. Marking this as [WIP] for I'm still running regression acctest under Redis. Once things could pass I would remove the [WIP]. Below paste the run pass result for the newly added test case.

=== RUN   TestAccRedisCache_PublicNetworkAccessDisabledEnabled
=== PAUSE TestAccRedisCache_PublicNetworkAccessDisabledEnabled
=== CONT  TestAccRedisCache_PublicNetworkAccessDisabledEnabled
--- PASS: TestAccRedisCache_PublicNetworkAccessDisabledEnabled (1965.03s)
PASS

Process finished with exit code 0
  • Loading branch information
mybayern1974 authored Feb 2, 2021
1 parent 7de29a9 commit 0842afc
Show file tree
Hide file tree
Showing 20 changed files with 1,122 additions and 190 deletions.
2 changes: 1 addition & 1 deletion azurerm/internal/services/redis/client/client.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package client

import (
"github.com/Azure/azure-sdk-for-go/services/redis/mgmt/2018-03-01/redis"
"github.com/Azure/azure-sdk-for-go/services/redis/mgmt/2020-06-01/redis"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/common"
)

Expand Down
28 changes: 25 additions & 3 deletions azurerm/internal/services/redis/redis_cache_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"
"time"

"github.com/Azure/azure-sdk-for-go/services/redis/mgmt/2018-03-01/redis"
"github.com/Azure/azure-sdk-for-go/services/redis/mgmt/2020-06-01/redis"
"github.com/hashicorp/go-azure-helpers/response"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
Expand Down Expand Up @@ -273,6 +273,12 @@ func resourceRedisCache() *schema.Resource {
Sensitive: true,
},

"public_network_access_enabled": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},

"tags": tags.Schema(),
},
}
Expand Down Expand Up @@ -313,6 +319,11 @@ func resourceRedisCacheCreate(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("parsing Redis Configuration: %+v", err)
}

publicNetworkAccess := redis.Enabled
if !d.Get("public_network_access_enabled").(bool) {
publicNetworkAccess = redis.Disabled
}

parameters := redis.CreateParameters{
Location: utils.String(location),
CreateProperties: &redis.CreateProperties{
Expand All @@ -322,8 +333,9 @@ func resourceRedisCacheCreate(d *schema.ResourceData, meta interface{}) error {
Family: family,
Name: sku,
},
MinimumTLSVersion: redis.TLSVersion(d.Get("minimum_tls_version").(string)),
RedisConfiguration: redisConfiguration,
MinimumTLSVersion: redis.TLSVersion(d.Get("minimum_tls_version").(string)),
RedisConfiguration: redisConfiguration,
PublicNetworkAccess: publicNetworkAccess,
},
Tags: expandedTags,
}
Expand Down Expand Up @@ -430,6 +442,14 @@ func resourceRedisCacheUpdate(d *schema.ResourceData, meta interface{}) error {
}
}

if d.HasChange("public_network_access_enabled") {
publicNetworkAccess := redis.Enabled
if !d.Get("public_network_access_enabled").(bool) {
publicNetworkAccess = redis.Disabled
}
parameters.PublicNetworkAccess = publicNetworkAccess
}

if d.HasChange("redis_configuration") {
redisConfiguration, err := expandRedisConfiguration(d)
if err != nil {
Expand Down Expand Up @@ -540,6 +560,8 @@ func resourceRedisCacheRead(d *schema.ResourceData, meta interface{}) error {
subnetId = parsed.ID()
}
d.Set("subnet_id", subnetId)

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

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

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

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

func TestAccRedisCache_InternalSubnet(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_redis_cache", "test")
r := RedisCacheResource{}
Expand Down Expand Up @@ -746,6 +775,31 @@ resource "azurerm_redis_cache" "test" {
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}

func (RedisCacheResource) publicNetworkAccessDisabled(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 = 1
family = "C"
sku_name = "Basic"
minimum_tls_version = "1.2"
enable_non_ssl_port = false
public_network_access_enabled = false
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}

func (RedisCacheResource) subscribeAllEvents(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"log"
"time"

"github.com/Azure/azure-sdk-for-go/services/redis/mgmt/2018-03-01/redis"
"github.com/Azure/azure-sdk-for-go/services/redis/mgmt/2020-06-01/redis"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"log"
"time"

"github.com/Azure/azure-sdk-for-go/services/redis/mgmt/2018-03-01/redis"
"github.com/Azure/azure-sdk-for-go/services/redis/mgmt/2020-06-01/redis"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
Expand Down

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0842afc

Please sign in to comment.