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

Conversation

nordbergm
Copy link
Contributor

Hey all,

This PR adds availability zone support to resources that are included in the AZ public preview. I'm unclear on what the policy is on preview features in Terraform, but it would be great if we could get this in.

It should also address feature request #370.

Updated Resources

  • azurerm_virtual_machine
  • azurerm_virtual_machine_scale_set
  • azurerm_public_ip
  • azurerm_managed_disk
  • azurerm_lb

Updated Data Sources

  • azurerm_managed_disk

@metacpp metacpp added this to the 1.1.2 milestone Feb 8, 2018
@metacpp metacpp self-assigned this Feb 9, 2018
@metacpp metacpp self-requested a review February 9, 2018 18:18
@metacpp metacpp removed their assignment Feb 9, 2018
Copy link
Contributor

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

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

hey @nordbergm

Thanks for opening this PR :)

I've taken a look through and left some comments in-line - but this mostly looks good to me. Since this functionality is in Public Preview (where users can self register) - we should be able to add this functionality providing we add an info box stating how users can join in the Preview (I've added an example info box in a comment).

Thanks!

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?

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?


os_profile_linux_config {
disable_password_authentication = false
}
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?

}

storage_profile_os_disk {
name = ""
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this is defaulted if not set, so I don't think we need to specify this?

azurerm/zones.go Outdated
}
}

func zoneValuesToStrings(v []interface{}) *[]string {
Copy link
Contributor

Choose a reason for hiding this comment

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

we'd tend to name this expandZones (since it's parsing the values out) - can we update this to match?

@@ -246,6 +246,7 @@ The following arguments are supported:
* `network_interface_ids` - (Required) Specifies the list of resource IDs for the network interfaces associated with the virtual machine.
* `primary_network_interface_id` - (Optional) Specifies the resource ID for the primary network interface associated with the virtual machine.
* `tags` - (Optional) A mapping of tags to assign to the resource.
* `zones` - (Optional) A collection containing the availability zone to allocate the Virtual Machine in.
Copy link
Contributor

Choose a reason for hiding this comment

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

can we add a note (blue box) that this functionality is in Preview:

-> **Please Note**: Availability Zones are [in Preview and only supported in several regions at this time](https://docs.microsoft.com/en-us/azure/availability-zones/az-overview) - as such you must be opted into the Preview to use this functionality. You can [opt into the Availability Zones Preview in the Azure Portal](http://aka.ms/azenroll).

@@ -60,6 +60,8 @@ The following arguments are supported:

* `tags` - (Optional) A mapping of tags to assign to the resource.

* `zones` - (Optional) A collection containing the availability zone to allocate the Public IP in.
Copy link
Contributor

Choose a reason for hiding this comment

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

can we add a note (blue box) that this functionality is in Preview:

-> **Please Note**: Availability Zones are [in Preview and only supported in several regions at this time](https://docs.microsoft.com/en-us/azure/availability-zones/az-overview) - as such you must be opted into the Preview to use this functionality. You can [opt into the Availability Zones Preview in the Azure Portal](http://aka.ms/azenroll).

@@ -106,6 +106,8 @@ The following arguments are supported:

* `tags` - (Optional) A mapping of tags to assign to the resource.

* `zones` - (Optional) A collection containing the availability zone to allocate the Managed Disk in.
Copy link
Contributor

Choose a reason for hiding this comment

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

can we add a note (blue box) that this functionality is in Preview:

-> **Please Note**: Availability Zones are [in Preview and only supported in several regions at this time](https://docs.microsoft.com/en-us/azure/availability-zones/az-overview) - as such you must be opted into the Preview to use this functionality. You can [opt into the Availability Zones Preview in the Azure Portal](http://aka.ms/azenroll).

@@ -58,6 +58,7 @@ The following arguments are supported:
* `private_ip_address` - (Optional) Private IP Address to assign to the Load Balancer. The last one and first four IPs in any range are reserved and cannot be manually assigned.
* `private_ip_address_allocation` - (Optional) Defines how a private IP address is assigned. Options are Static or Dynamic.
* `public_ip_address_id` - (Optional) Reference to Public IP address to be associated with the Load Balancer.
* `zones` - (Optional) A collection containing the availability zone to allocate the IP in.
Copy link
Contributor

Choose a reason for hiding this comment

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

can we add a note (blue box) that this functionality is in Preview:

-> **Please Note**: Availability Zones are [in Preview and only supported in several regions at this time](https://docs.microsoft.com/en-us/azure/availability-zones/az-overview) - as such you must be opted into the Preview to use this functionality. You can [opt into the Availability Zones Preview in the Azure Portal](http://aka.ms/azenroll).

@@ -111,3 +111,4 @@ resource "azurerm_virtual_machine" "test" {
* `os_type` - The operating system for managed disk. Valid values are `Linux` or `Windows`
* `disk_size_gb` - The size of the managed disk in gigabytes.
* `tags` - A mapping of tags assigned to the resource.
* `zones` - (Optional) A collection containing the availability zone the managed disk is allocated in.
Copy link
Contributor

Choose a reason for hiding this comment

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

can we add a note (blue box) that this functionality is in Preview:

-> **Please Note**: Availability Zones are [in Preview and only supported in several regions at this time](https://docs.microsoft.com/en-us/azure/availability-zones/az-overview) - as such you must be opted into the Preview to use this functionality. You can [opt into the Availability Zones Preview in the Azure Portal](http://aka.ms/azenroll).

@tombuildsstuff
Copy link
Contributor

Fixes #370

@nordbergm
Copy link
Contributor Author

hey @tombuildsstuff,

Thanks for the review! Your pointers should be sorted now, but let me know if there's anything else.

@@ -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

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?

@@ -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?

@@ -577,7 +580,8 @@ func resourceArmVirtualMachineCreate(d *schema.ResourceData, meta interface{}) e
Name: &name,
Location: &location,
VirtualMachineProperties: &properties,
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.

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?

@@ -564,6 +566,7 @@ func resourceArmVirtualMachineScaleSetCreate(d *schema.ResourceData, meta interf
location := d.Get("location").(string)
resGroup := d.Get("resource_group_name").(string)
tags := d.Get("tags").(map[string]interface{})
zones := expandZones(d.Get("zones").([]interface{}))
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?

@@ -632,6 +635,7 @@ func resourceArmVirtualMachineScaleSetCreate(d *schema.ResourceData, meta interf
Tags: expandTags(tags),
Sku: sku,
VirtualMachineScaleSetProperties: &scaleSetProps,
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?

@tombuildsstuff
Copy link
Contributor

hey @nordbergm

Thanks for pushing those updates - I kicked off the test suite here without the Preview enabled (to confirm the existing tests work) - however the existing tests fail as we're setting the Zones field regardless:

* 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 update the assignment of the Zones field to check if there's any items before setting it, as shown in this comment which would fix the issue. Once that's done - both the existing and the new tests should pass as expected :)

Thanks!

@nordbergm
Copy link
Contributor Author

hey @tombuildsstuff,

Sorry about those test failures. I initially looked at the Azure Go client and how Zones marshalling is defined as omitempty.

Zones           *[]string `json:"zones,omitempty"`

My expectation was that it would omit an empty array from the request. After some testing it seems this is generally the case, but since the field is defined as a pointer, the pointer has to be nil to be omitted.

A perhaps simpler and more central change, would be to have expandZones return nil in case the array is empty. How do you feel about that approach? I'm rather new with Go, so maybe this is some big no no.

@tombuildsstuff tombuildsstuff modified the milestones: 1.1.2, 1.1.3 Feb 15, 2018
@nordbergm
Copy link
Contributor Author

@tombuildsstuff I pushed an example of my suggested approach. Let me know what you think, and if you still experience any issues with the tests.

@tombuildsstuff tombuildsstuff modified the milestones: 1.1.3, 1.1.4 Feb 28, 2018
@agup006
Copy link

agup006 commented Mar 4, 2018

@tombuildsstuff is the approach @nordbergm pushed ok? Any updates are appreciated

@tombuildsstuff
Copy link
Contributor

@agup006 @nordbergm sorry for the delay in re-reviewing this - we're trying to work through the review backlog - I'm taking a look into this now.

@@ -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

@tombuildsstuff
Copy link
Contributor

hey @nordbergm @agup006

Thanks for pushing the latest updates - apologies about the delayed review here! The latest updates looks good, however running the tests there appears to be a crash in the Load Balancer resource (which I've commented in-line about)

If we can sort that out, we'll take another look through/kick of the tests - but this should be good :)

Thanks!


Tests:

Data Source tests pass:

screenshot-1-data-source

Managed Disk resource tests pass:

screenshot-2-managed-disks

Public Ip tests pass:

screenshot-3-public-ip

Reminder of the test prefixes for me, for later:

refs/pull/811/merge

TestAccDataSourceAzureRMManagedDisk_
TestAccAzureRMLoadBalancer_
TestAccAzureRMManagedDisk_
TestAccAzureRMPublicIp
TestAccAzureRMVirtualMachineScaleSet_
TestAccAzureRMVirtualMachine_

Tests pass:

```
$ acctests azurerm TestAccAzureRMLoadBalancer_basic
=== RUN   TestAccAzureRMLoadBalancer_basic
--- PASS: TestAccAzureRMLoadBalancer_basic (59.25s)
PASS
ok  	github.com/terraform-providers/terraform-provider-azurerm/azurerm	59.281s
```
@tombuildsstuff
Copy link
Contributor

Load Balancer tests pass:

screen shot 2018-03-06 at 09 41 54

@tombuildsstuff
Copy link
Contributor

VM/VMSS tests pass, ignoring a transient Azure failure:

screen shot 2018-03-06 at 10 50 59

Copy link
Contributor

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

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

Hey @nordbergm

I've pushed a commit to fix the crash identified in the tests and ran the tests - and this now LGTM 👍

Thanks!

@tombuildsstuff tombuildsstuff merged commit 218dc6e into hashicorp:master Mar 6, 2018
tombuildsstuff added a commit that referenced this pull request Mar 6, 2018
@nordbergm
Copy link
Contributor Author

Thanks @tombuildsstuff!

@ghost
Copy link

ghost commented Mar 6, 2019

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks!

@ghost ghost locked and limited conversation to collaborators Mar 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants