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

Add availability zone support #811

Merged
merged 13 commits into from
Mar 6, 2018
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
5 changes: 5 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 := zoneValuesToStrings(data["zones"].([]interface{}))
frontEndConfig := network.FrontendIPConfiguration{
Name: &name,
FrontendIPConfigurationPropertiesFormat: &properties,
Zones: zones,
Copy link
Contributor

Choose a reason for hiding this comment

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

from what I can see, this will be the same issue as below (where a user isn't opted into the Preview, this fails) - can we update it to use the pattern identified below?

}

frontEndConfigs = append(frontEndConfigs, frontEndConfig)
Expand All @@ -306,6 +310,7 @@ func flattenLoadBalancerFrontendIpConfiguration(ipConfigs *[]network.FrontendIPC
for _, config := range *ipConfigs {
ipConfig := make(map[string]interface{})
ipConfig["name"] = *config.Name
ipConfig["zones"] = *config.Zones
Copy link
Contributor

Choose a reason for hiding this comment

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

so there's a crash here if config.Zones is nil - can we make this:

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

ipConfig["zones"] = zones

Copy link
Contributor

Choose a reason for hiding this comment

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

I hope you don't mind, but I've pushed a commit to fix this


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 @@ -118,6 +120,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 := zoneValuesToStrings(d.Get("zones").([]interface{}))

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

Choose a reason for hiding this comment

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

Given we set this value always - if a user isn't opted into the Preview most deployments will fail:

* azurerm_managed_disk.test: compute.DisksClient#CreateOrUpdate: Failure sending request: StatusCode=400 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="ResourceTypeNotSupportAvailabilityZones" Message="The resource type 'disks' does not support availability zones at location 'westeurope' and api-version '2017-03-30'."

Can we instead change this to assign Zones only if the field is set? e.g.

if v, ok := d.Get("zones"); ok {
  zones := expandZones(v.([]interface{}))
  createDisk.Zones = zones
}

which should remove this error

}

if v := d.Get("disk_size_gb"); v != 0 {
Expand Down Expand Up @@ -221,6 +225,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 @@ -304,6 +304,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"]
Copy link
Contributor

Choose a reason for hiding this comment

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

minor can we fix the spacing here?


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
13 changes: 9 additions & 4 deletions 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 := zoneValuesToStrings(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,
Copy link
Contributor

Choose a reason for hiding this comment

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

from what I can see, this will be the same issue as above (where a user isn't opted into the Preview, this fails) - can we update it to use the pattern identified below?

}

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 All @@ -223,10 +228,10 @@ func resourceArmPublicIpRead(d *schema.ResourceData, meta interface{}) error {
if fqdn := settings.Fqdn; fqdn != nil {
d.Set("fqdn", fqdn)
}
}

if ip := props.IPAddress; ip != nil {
d.Set("ip_address", ip)
}
if ip := props.IPAddress; ip != nil {
d.Set("ip_address", ip)
}
}

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 @@ -344,6 +344,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"]
Copy link
Contributor

Choose a reason for hiding this comment

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

minor could we make the spacing consistent here?

}
`, rInt, location, rInt)
}

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