Skip to content

Commit

Permalink
Merge pull request #811 from nordbergm/availability-zones
Browse files Browse the repository at this point in the history
Add availability zone support
  • Loading branch information
tombuildsstuff authored Mar 6, 2018
2 parents 987127e + 5bc57f1 commit 218dc6e
Show file tree
Hide file tree
Showing 24 changed files with 453 additions and 3 deletions.
4 changes: 4 additions & 0 deletions azurerm/data_source_managed_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ func dataSourceArmManagedDisk() *schema.Resource {

"resource_group_name": resourceGroupNameForDataSourceSchema(),

"zones": zonesSchemaComputed(),

"storage_account_type": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -84,6 +86,8 @@ func dataSourceArmManagedDiskRead(d *schema.ResourceData, meta interface{}) erro
flattenAzureRmManagedDiskCreationData(d, resp.CreationData)
}

d.Set("zones", resp.Zones)

flattenAndSetTags(d, resp.Tags)

return nil
Expand Down
3 changes: 3 additions & 0 deletions azurerm/data_source_managed_disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ func TestAccDataSourceAzureRMManagedDisk_basic(t *testing.T) {
resource.TestCheckResourceAttr(dataSourceName, "disk_size_gb", "10"),
resource.TestCheckResourceAttr(dataSourceName, "tags.%", "1"),
resource.TestCheckResourceAttr(dataSourceName, "tags.environment", "acctest"),
resource.TestCheckResourceAttr(dataSourceName, "zones.#", "1"),
resource.TestCheckResourceAttr(dataSourceName, "zones.0", "2"),
),
},
},
Expand All @@ -50,6 +52,7 @@ resource "azurerm_managed_disk" "test" {
storage_account_type = "Premium_LRS"
create_option = "Empty"
disk_size_gb = "10"
zones = ["2"]
tags {
environment = "acctest"
Expand Down
25 changes: 25 additions & 0 deletions azurerm/import_arm_loadbalancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,28 @@ func TestAccAzureRMLoadBalancer_importFrontEnd(t *testing.T) {
},
})
}

func TestAccAzureRMLoadBalancer_importFrontEnd_withZone(t *testing.T) {
resourceName := "azurerm_lb.test"
ri := acctest.RandInt()
config := testAccAzureRMLoadBalancer_frontEndConfig_withZone(ri, testLocation())

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMLoadBalancerDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "frontend_ip_configuration.#", "2"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
21 changes: 21 additions & 0 deletions azurerm/import_arm_managed_disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,24 @@ func TestAccAzureRMManagedDisk_importEmpty(t *testing.T) {
},
})
}

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

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMManagedDiskDestroy,
Steps: []resource.TestStep{
{
Config: config,
},
{
ResourceName: "azurerm_managed_disk.test",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
23 changes: 23 additions & 0 deletions azurerm/import_arm_public_ip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,29 @@ func TestAccAzureRMPublicIpStatic_importBasic(t *testing.T) {
})
}

func TestAccAzureRMPublicIpStatic_importBasic_withZone(t *testing.T) {
resourceName := "azurerm_public_ip.test"

ri := acctest.RandInt()
config := testAccAzureRMPublicIPStatic_basic_withZone(ri, testLocation())

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMPublicIpDestroy,
Steps: []resource.TestStep{
{
Config: config,
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAzureRMPublicIpStatic_importIdError(t *testing.T) {
resourceName := "azurerm_public_ip.test"

Expand Down
24 changes: 24 additions & 0 deletions azurerm/import_arm_virtual_machine_scale_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,30 @@ func TestAccAzureRMVirtualMachineScaleSet_importBasic_managedDisk(t *testing.T)
})
}

func TestAccAzureRMVirtualMachineScaleSet_importBasic_managedDisk_withZones(t *testing.T) {
resourceName := "azurerm_virtual_machine_scale_set.test"

ri := acctest.RandInt()
config := testAccAzureRMVirtualMachineScaleSet_basicLinux_managedDisk_withZones(ri, testLocation())

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMVirtualMachineScaleSetDestroy,
Steps: []resource.TestStep{
{
Config: config,
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"os_profile.0.admin_password"},
},
},
})
}

func TestAccAzureRMVirtualMachineScaleSet_importLinux(t *testing.T) {
resourceName := "azurerm_virtual_machine_scale_set.test"

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

func TestAccAzureRMVirtualMachine_importBasic_withZone(t *testing.T) {
resourceName := "azurerm_virtual_machine.test"

ri := acctest.RandInt()
config := testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_implicit_withZone(ri, testLocation())

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
Steps: []resource.TestStep{
{
Config: config,
},

{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"delete_data_disks_on_termination",
"delete_os_disk_on_termination",
},
},
},
})
}

func TestAccAzureRMVirtualMachine_importBasic_managedDisk(t *testing.T) {
resourceName := "azurerm_virtual_machine.test"

Expand Down
12 changes: 12 additions & 0 deletions azurerm/resource_arm_loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ func resourceArmLoadBalancer() *schema.Resource {
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
},

"zones": singleZonesSchema(),
},
},
},
Expand Down Expand Up @@ -290,9 +292,11 @@ func expandAzureRmLoadBalancerFrontendIpConfigurations(d *schema.ResourceData) *
}

name := data["name"].(string)
zones := expandZones(data["zones"].([]interface{}))
frontEndConfig := network.FrontendIPConfiguration{
Name: &name,
FrontendIPConfigurationPropertiesFormat: &properties,
Zones: zones,
}

frontEndConfigs = append(frontEndConfigs, frontEndConfig)
Expand All @@ -307,6 +311,14 @@ func flattenLoadBalancerFrontendIpConfiguration(ipConfigs *[]network.FrontendIPC
ipConfig := make(map[string]interface{})
ipConfig["name"] = *config.Name

zones := make([]string, 0)
if zs := config.Zones; zs != nil {
for _, zone := range *zs {
zones = append(zones, zone)
}
}
ipConfig["zones"] = zones

if props := config.FrontendIPConfigurationPropertiesFormat; props != nil {
ipConfig["private_ip_address_allocation"] = props.PrivateIPAllocationMethod

Expand Down
40 changes: 40 additions & 0 deletions azurerm/resource_arm_loadbalancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,46 @@ resource "azurerm_lb" "test" {
}`, rInt, location, rInt, rInt, rInt, rInt, rInt)
}

func testAccAzureRMLoadBalancer_frontEndConfig_withZone(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestrg-%d"
location = "%s"
}
resource "azurerm_virtual_network" "test" {
name = "acctvn-%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 = "acctsub-%d"
resource_group_name = "${azurerm_resource_group.test.name}"
virtual_network_name = "${azurerm_virtual_network.test.name}"
address_prefix = "10.0.2.0/24"
}
resource "azurerm_lb" "test" {
name = "arm-test-loadbalancer-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
frontend_ip_configuration {
name = "one-%d"
subnet_id = "${azurerm_subnet.test.id}"
zones = ["1"]
}
frontend_ip_configuration {
name = "two-%d"
subnet_id = "${azurerm_subnet.test.id}"
zones = ["1"]
}
}`, rInt, location, rInt, rInt, rInt, rInt, rInt)
}

func testAccAzureRMLoadBalancer_frontEndConfigRemovalWithIP(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
Expand Down
7 changes: 6 additions & 1 deletion azurerm/resource_arm_managed_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ func resourceArmManagedDisk() *schema.Resource {

"resource_group_name": resourceGroupNameSchema(),

"zones": singleZonesSchema(),

"storage_account_type": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -119,6 +121,7 @@ func resourceArmManagedDiskCreate(d *schema.ResourceData, meta interface{}) erro
osType := d.Get("os_type").(string)
tags := d.Get("tags").(map[string]interface{})
expandedTags := expandTags(tags)
zones := expandZones(d.Get("zones").([]interface{}))

var skuName compute.StorageAccountTypes
if strings.ToLower(storageAccountType) == strings.ToLower(string(compute.PremiumLRS)) {
Expand All @@ -136,7 +139,8 @@ func resourceArmManagedDiskCreate(d *schema.ResourceData, meta interface{}) erro
Sku: &compute.DiskSku{
Name: (skuName),
},
Tags: expandedTags,
Tags: expandedTags,
Zones: zones,
}

if v := d.Get("disk_size_gb"); v != 0 {
Expand Down Expand Up @@ -222,6 +226,7 @@ func resourceArmManagedDiskRead(d *schema.ResourceData, meta interface{}) error

d.Set("name", resp.Name)
d.Set("resource_group_name", resGroup)
d.Set("zones", resp.Zones)

if location := resp.Location; location != nil {
d.Set("location", azureRMNormalizeLocation(*location))
Expand Down
24 changes: 24 additions & 0 deletions azurerm/resource_arm_managed_disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,30 @@ resource "azurerm_managed_disk" "test" {
`, rInt, location, rInt)
}

func testAccAzureRMManagedDisk_empty_withZone(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}
resource "azurerm_managed_disk" "test" {
name = "acctestd-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
storage_account_type = "Standard_LRS"
create_option = "Empty"
disk_size_gb = "1"
zones = ["1"]
tags {
environment = "acctest"
cost-center = "ops"
}
}
`, rInt, location, rInt)
}

func testAccAzureRMManagedDisk_import(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
Expand Down
7 changes: 6 additions & 1 deletion azurerm/resource_arm_public_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ func resourceArmPublicIp() *schema.Resource {

"resource_group_name": resourceGroupNameSchema(),

"zones": singleZonesSchema(),

"public_ip_address_allocation": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -115,6 +117,7 @@ func resourceArmPublicIpCreate(d *schema.ResourceData, meta interface{}) error {
Name: network.PublicIPAddressSkuName(d.Get("sku").(string)),
}
tags := d.Get("tags").(map[string]interface{})
zones := expandZones(d.Get("zones").([]interface{}))

ipAllocationMethod := network.IPAllocationMethod(d.Get("public_ip_address_allocation").(string))

Expand Down Expand Up @@ -157,7 +160,8 @@ func resourceArmPublicIpCreate(d *schema.ResourceData, meta interface{}) error {
Location: &location,
Sku: &sku,
PublicIPAddressPropertiesFormat: &properties,
Tags: expandTags(tags),
Tags: expandTags(tags),
Zones: zones,
}

future, err := client.CreateOrUpdate(ctx, resGroup, name, publicIp)
Expand Down Expand Up @@ -206,6 +210,7 @@ func resourceArmPublicIpRead(d *schema.ResourceData, meta interface{}) error {

d.Set("name", resp.Name)
d.Set("resource_group_name", resGroup)
d.Set("zones", resp.Zones)
if location := resp.Location; location != nil {
d.Set("location", azureRMNormalizeLocation(*location))
}
Expand Down
17 changes: 17 additions & 0 deletions azurerm/resource_arm_public_ip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,23 @@ resource "azurerm_public_ip" "test" {
`, rInt, location, rInt)
}

func testAccAzureRMPublicIPStatic_basic_withZone(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}
resource "azurerm_public_ip" "test" {
name = "acctestpublicip-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
public_ip_address_allocation = "static"
zones = ["1"]
}
`, rInt, location, rInt)
}

func testAccAzureRMPublicIPStatic_standard(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
Expand Down
Loading

0 comments on commit 218dc6e

Please sign in to comment.