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

Redis Cache: support for clusters on the internal network #1086

Merged
merged 7 commits into from
Apr 11, 2018
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
6 changes: 3 additions & 3 deletions azurerm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
"github.com/Azure/azure-sdk-for-go/services/operationalinsights/mgmt/2015-11-01-preview/operationalinsights"
"github.com/Azure/azure-sdk-for-go/services/operationsmanagement/mgmt/2015-11-01-preview/operationsmanagement"
"github.com/Azure/azure-sdk-for-go/services/postgresql/mgmt/2017-04-30-preview/postgresql"
"github.com/Azure/azure-sdk-for-go/services/redis/mgmt/2016-04-01/redis"
"github.com/Azure/azure-sdk-for-go/services/redis/mgmt/2018-03-01/redis"
"github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2016-06-01/subscriptions"
"github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2016-09-01/locks"
"github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2016-12-01/policy"
Expand Down Expand Up @@ -89,7 +89,7 @@ type ArmClient struct {
solutionsClient operationsmanagement.SolutionsClient

redisClient redis.Client
redisFirewallClient redis.FirewallRuleClient
redisFirewallClient redis.FirewallRulesClient
redisPatchSchedulesClient redis.PatchSchedulesClient

// Application Insights
Expand Down Expand Up @@ -791,7 +791,7 @@ func (c *ArmClient) registerRedisClients(endpoint, subscriptionId string, auth a
c.configureClient(&redisClient.Client, auth)
c.redisClient = redisClient

firewallRuleClient := redis.NewFirewallRuleClientWithBaseURI(endpoint, subscriptionId)
firewallRuleClient := redis.NewFirewallRulesClientWithBaseURI(endpoint, subscriptionId)
c.configureClient(&firewallRuleClient.Client, auth)
c.redisFirewallClient = firewallRuleClient

Expand Down
53 changes: 38 additions & 15 deletions azurerm/resource_arm_redis_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strings"
"time"

"github.com/Azure/azure-sdk-for-go/services/redis/mgmt/2016-04-01/redis"
"github.com/Azure/azure-sdk-for-go/services/redis/mgmt/2018-03-01/redis"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
Expand Down Expand Up @@ -74,6 +74,19 @@ func resourceArmRedisCache() *schema.Resource {
Optional: true,
},

"subnet_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},

"private_static_ip_address": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},

"redis_configuration": {
Type: schema.TypeList,
Required: true,
Expand Down Expand Up @@ -211,12 +224,11 @@ func resourceArmRedisCacheCreate(d *schema.ResourceData, meta interface{}) error
}

parameters := redis.CreateParameters{
Name: &name,
Location: &location,
Location: utils.String(location),
CreateProperties: &redis.CreateProperties{
EnableNonSslPort: &enableNonSSLPort,
EnableNonSslPort: utils.Bool(enableNonSSLPort),
Sku: &redis.Sku{
Capacity: &capacity,
Capacity: utils.Int32(capacity),
Family: family,
Name: sku,
},
Expand All @@ -230,6 +242,14 @@ func resourceArmRedisCacheCreate(d *schema.ResourceData, meta interface{}) error
parameters.ShardCount = &shardCount
}

if v, ok := d.GetOk("private_static_ip_address"); ok {
parameters.StaticIP = utils.String(v.(string))
}

if v, ok := d.GetOk("subnet_id"); ok {
parameters.SubnetID = utils.String(v.(string))
}

future, err := client.Create(ctx, resGroup, name, parameters)
if err != nil {
return err
Expand Down Expand Up @@ -292,9 +312,9 @@ func resourceArmRedisCacheUpdate(d *schema.ResourceData, meta interface{}) error

parameters := redis.UpdateParameters{
UpdateProperties: &redis.UpdateProperties{
EnableNonSslPort: &enableNonSSLPort,
EnableNonSslPort: utils.Bool(enableNonSSLPort),
Sku: &redis.Sku{
Capacity: &capacity,
Capacity: utils.Int32(capacity),
Family: family,
Name: sku,
},
Expand Down Expand Up @@ -406,19 +426,22 @@ func resourceArmRedisCacheRead(d *schema.ResourceData, meta interface{}) error {
d.Set("location", azureRMNormalizeLocation(*location))
}

d.Set("ssl_port", resp.SslPort)
d.Set("hostname", resp.HostName)
d.Set("port", resp.Port)
d.Set("enable_non_ssl_port", resp.EnableNonSslPort)

if sku := resp.Sku; sku != nil {
d.Set("capacity", sku.Capacity)
d.Set("family", sku.Family)
d.Set("sku_name", sku.Name)
}

if resp.ShardCount != nil {
d.Set("shard_count", resp.ShardCount)
if props := resp.Properties; props != nil {
d.Set("ssl_port", props.SslPort)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we build a helper method to flatten it ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope - we only do that for complex (e.g. nested) field, a single field isn't necessary

d.Set("hostname", props.HostName)
d.Set("port", props.Port)
d.Set("enable_non_ssl_port", props.EnableNonSslPort)
if props.ShardCount != nil {
d.Set("shard_count", props.ShardCount)
}
d.Set("private_static_ip_address", props.StaticIP)
d.Set("subnet_id", props.SubnetID)
}

redisConfiguration := flattenRedisConfiguration(resp.RedisConfiguration)
Expand Down Expand Up @@ -470,7 +493,7 @@ func redisStateRefreshFunc(ctx context.Context, client redis.Client, resourceGro
return nil, "", fmt.Errorf("Error issuing read request in redisStateRefreshFunc to Azure ARM for Redis Cache Instance '%s' (RG: '%s'): %s", sgName, resourceGroupName, err)
}

return res, *res.ProvisioningState, nil
return res, string(res.ProvisioningState), nil
}
}

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

func TestAccAzureRMRedisCache_InternalSubnet(t *testing.T) {
ri := acctest.RandInt()
config := testAccAzureRMRedisCache_internalSubnet(ri, testLocation())

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMRedisCacheDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMRedisCacheExists("azurerm_redis_cache.test"),
),
},
},
})
}

func TestAccAzureRMRedisCache_InternalSubnetStaticIP(t *testing.T) {
ri := acctest.RandInt()
config := testAccAzureRMRedisCache_internalSubnetStaticIP(ri, testLocation())

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMRedisCacheDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMRedisCacheExists("azurerm_redis_cache.test"),
),
},
},
})
}

func testCheckAzureRMRedisCacheExists(name string) resource.TestCheckFunc {
return func(s *terraform.State) error {
// Ensure we have enough information in state to look up in API
Expand Down Expand Up @@ -635,3 +673,77 @@ resource "azurerm_redis_cache" "test" {
}
`, rInt, location, rString, rInt)
}
func testAccAzureRMRedisCache_internalSubnet(ri int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}

resource "azurerm_virtual_network" "test" {
name = "acctestnw-%d"
address_space = ["10.0.0.0/16"]
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
}

resource "azurerm_subnet" "test" {
name = "testsubnet"
resource_group_name = "${azurerm_resource_group.test.name}"
virtual_network_name = "${azurerm_virtual_network.test.name}"
address_prefix = "10.0.1.0/24"
}

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 = "P"
sku_name = "Premium"
enable_non_ssl_port = false
subnet_id = "${azurerm_subnet.test.id}"
redis_configuration {
maxclients = "256"
}
}
`, ri, location, ri, ri)
}

func testAccAzureRMRedisCache_internalSubnetStaticIP(ri int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}

resource "azurerm_virtual_network" "test" {
name = "acctestnw-%d"
address_space = ["10.0.0.0/16"]
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
}

resource "azurerm_subnet" "test" {
name = "testsubnet"
resource_group_name = "${azurerm_resource_group.test.name}"
virtual_network_name = "${azurerm_virtual_network.test.name}"
address_prefix = "10.0.1.0/24"
}

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 = "P"
sku_name = "Premium"
enable_non_ssl_port = false
subnet_id = "${azurerm_subnet.test.id}"
private_static_ip_address = "10.0.1.20"
redis_configuration {
maxclients = "256"
}
}
`, ri, location, ri, ri)
}
5 changes: 2 additions & 3 deletions azurerm/resource_arm_redis_firewall_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"regexp"

"github.com/Azure/azure-sdk-for-go/services/redis/mgmt/2016-04-01/redis"
"github.com/Azure/azure-sdk-for-go/services/redis/mgmt/2018-03-01/redis"
"github.com/hashicorp/terraform/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)
Expand Down Expand Up @@ -58,8 +58,7 @@ func resourceArmRedisFirewallRuleCreateUpdate(d *schema.ResourceData, meta inter
startIP := d.Get("start_ip").(string)
endIP := d.Get("end_ip").(string)

parameters := redis.FirewallRule{
Name: &name,
parameters := redis.FirewallRuleCreateParameters{
FirewallRuleProperties: &redis.FirewallRuleProperties{
StartIP: utils.String(startIP),
EndIP: utils.String(endIP),
Expand Down
Loading