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 support for the extendedLocation property #14159

Closed
wants to merge 13 commits into from
Closed
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
15 changes: 15 additions & 0 deletions helpers/azure/extended_location.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package azure

import (
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
)

func SchemaExtendedLocation() *pluginsdk.Schema {
return &pluginsdk.Schema{
Type: pluginsdk.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringIsNotEmpty,
}
}
13 changes: 13 additions & 0 deletions internal/services/compute/linux_virtual_machine_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ func resourceLinuxVirtualMachine() *pluginsdk.Resource {
}, false),
},

"extended_location": azure.SchemaExtendedLocation(),

"extensions_time_budget": {
Type: pluginsdk.TypeString,
Optional: true,
Expand Down Expand Up @@ -468,6 +470,13 @@ func resourceLinuxVirtualMachineCreate(d *pluginsdk.ResourceData, meta interface
Tags: tags.Expand(t),
}

if v, ok := d.GetOk("extended_location"); ok {
params.ExtendedLocation = &compute.ExtendedLocation{
Name: utils.String(v.(string)),
Type: compute.ExtendedLocationTypesEdgeZone,
}
}

if v, ok := d.GetOk("patch_mode"); ok {
if v == string(compute.LinuxVMGuestPatchModeAutomaticByPlatform) && !provisionVMAgent {
return fmt.Errorf("%q cannot be set to %q when %q is set to %q", "patch_mode", "AutomaticByPlatform", "provision_vm_agent", "false")
Expand Down Expand Up @@ -638,6 +647,10 @@ func resourceLinuxVirtualMachineRead(d *pluginsdk.ResourceData, meta interface{}
d.Set("location", azure.NormalizeLocation(*location))
}

if resp.ExtendedLocation != nil && resp.ExtendedLocation.Name != nil {
d.Set("extended_location", resp.ExtendedLocation.Name)
}

identity, err := flattenVirtualMachineIdentity(resp.Identity)
if err != nil {
return fmt.Errorf("flattening `identity`: %+v", err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,28 @@ func TestAccLinuxVirtualMachine_otherVTpmEnabled(t *testing.T) {
})
}

func TestAccLinuxVirtualMachine_otherExtendedLocation(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine", "test")
r := LinuxVirtualMachineResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.otherExtendedLocation(data, "Test1"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.otherExtendedLocation(data, "Test2"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func TestAccLinuxVirtualMachine_otherPatchModeAutomaticByPlatform(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine", "test")
r := LinuxVirtualMachineResource{}
Expand Down Expand Up @@ -2038,3 +2060,84 @@ resource "azurerm_linux_virtual_machine" "test" {
}
`, r.template(data), data.RandomInteger)
}

func (r LinuxVirtualMachineResource) otherExtendedLocation(data acceptance.TestData, tag string) string {
return fmt.Sprintf(`
# note: whilst these aren't used in all tests, it saves us redefining these everywhere
locals {
first_public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC+wWK73dCr+jgQOAxNsHAnNNNMEMWOHYEccp6wJm2gotpr9katuF/ZAdou5AaW1C61slRkHRkpRRX9FA9CYBiitZgvCCz+3nWNN7l/Up54Zps/pHWGZLHNJZRYyAB6j5yVLMVHIHriY49d/GZTZVNB8GoJv9Gakwc/fuEZYYl4YDFiGMBP///TzlI4jhiJzjKnEvqPFki5p2ZRJqcbCiF4pJrxUQR/RXqVFQdbRLZgYfJ8xGB878RENq3yQ39d8dVOkq4edbkzwcUmwwwkYVPIoDGsYLaRHnG+To7FvMeyO7xDVQkMKzopTQV8AuKpyvpqu0a9pWOMaiCyDytO7GGN [email protected]"
second_public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC0/NDMj2wG6bSa6jbn6E3LYlUsYiWMp1CQ2sGAijPALW6OrSu30lz7nKpoh8Qdw7/A4nAJgweI5Oiiw5/BOaGENM70Go+VM8LQMSxJ4S7/8MIJEZQp5HcJZ7XDTcEwruknrd8mllEfGyFzPvJOx6QAQocFhXBW6+AlhM3gn/dvV5vdrO8ihjET2GoDUqXPYC57ZuY+/Fz6W3KV8V97BvNUhpY5yQrP5VpnyvvXNFQtzDfClTvZFPuoHQi3/KYPi6O0FSD74vo8JOBZZY09boInPejkm9fvHQqfh0bnN7B6XJoUwC1Qprrx+XIy7ust5AEn5XL7d4lOvcR14MxDDKEp [email protected]"
}

resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"

// There is no supported extended location in "West Europe"
location = "westus"
}

data "azurerm_extended_locations" "test" {
location = azurerm_resource_group.test.location
}

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 = "internal"
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_network_interface" "test" {
name = "acctestnic-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name

ip_configuration {
name = "internal"
subnet_id = azurerm_subnet.test.id
private_ip_address_allocation = "Dynamic"
}
}

resource "azurerm_linux_virtual_machine" "test" {
name = "acctestVM-%d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
size = "Standard_D2s_v3"
admin_username = "adminuser"
extended_location = data.azurerm_extended_locations.test.extended_locations.0

network_interface_ids = [
azurerm_network_interface.test.id,
]

admin_ssh_key {
username = "adminuser"
public_key = local.first_public_key
}

os_disk {
caching = "ReadWrite"
storage_account_type = "Premium_LRS"
}

source_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "18.04-LTS"
version = "latest"
}

tags = {
ENV = "%s"
}
}
`, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, tag)
}
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,28 @@ func TestAccLinuxVirtualMachineScaleSet_otherVTpmEnabled(t *testing.T) {
})
}

func TestAccLinuxVirtualMachineScaleSet_otherExtendedLocation(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test")
r := LinuxVirtualMachineScaleSetResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.otherExtendedLocation(data, "Test1"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("admin_password"),
{
Config: r.otherExtendedLocation(data, "Test2"),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("admin_password"),
})
}

func (r LinuxVirtualMachineScaleSetResource) otherBootDiagnostics(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
Expand Down Expand Up @@ -2589,3 +2611,78 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" {
}
`, r.template(data), data.RandomInteger)
}

func (r LinuxVirtualMachineScaleSetResource) otherExtendedLocation(data acceptance.TestData, tag string) string {
return fmt.Sprintf(`
# note: whilst these aren't used in all tests, it saves us redefining these everywhere
locals {
first_public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC+wWK73dCr+jgQOAxNsHAnNNNMEMWOHYEccp6wJm2gotpr9katuF/ZAdou5AaW1C61slRkHRkpRRX9FA9CYBiitZgvCCz+3nWNN7l/Up54Zps/pHWGZLHNJZRYyAB6j5yVLMVHIHriY49d/GZTZVNB8GoJv9Gakwc/fuEZYYl4YDFiGMBP///TzlI4jhiJzjKnEvqPFki5p2ZRJqcbCiF4pJrxUQR/RXqVFQdbRLZgYfJ8xGB878RENq3yQ39d8dVOkq4edbkzwcUmwwwkYVPIoDGsYLaRHnG+To7FvMeyO7xDVQkMKzopTQV8AuKpyvpqu0a9pWOMaiCyDytO7GGN [email protected]"
second_public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC0/NDMj2wG6bSa6jbn6E3LYlUsYiWMp1CQ2sGAijPALW6OrSu30lz7nKpoh8Qdw7/A4nAJgweI5Oiiw5/BOaGENM70Go+VM8LQMSxJ4S7/8MIJEZQp5HcJZ7XDTcEwruknrd8mllEfGyFzPvJOx6QAQocFhXBW6+AlhM3gn/dvV5vdrO8ihjET2GoDUqXPYC57ZuY+/Fz6W3KV8V97BvNUhpY5yQrP5VpnyvvXNFQtzDfClTvZFPuoHQi3/KYPi6O0FSD74vo8JOBZZY09boInPejkm9fvHQqfh0bnN7B6XJoUwC1Qprrx+XIy7ust5AEn5XL7d4lOvcR14MxDDKEp [email protected]"
}

resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"

// There is no supported extended location in "West Europe"
location = "westus"
}

data "azurerm_extended_locations" "test" {
location = azurerm_resource_group.test.location
}

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 = "internal"
resource_group_name = azurerm_resource_group.test.name
virtual_network_name = azurerm_virtual_network.test.name
address_prefixes = ["10.0.2.0/24"]
}

resource "azurerm_linux_virtual_machine_scale_set" "test" {
name = "acctestvmss-%d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
sku = "Standard_D2s_v3"
instances = 1
admin_username = "adminuser"
admin_password = "P@ssword1234!"
extended_location = data.azurerm_extended_locations.test.extended_locations.0

disable_password_authentication = false

source_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "18.04-LTS"
version = "latest"
}

os_disk {
storage_account_type = "Premium_LRS"
caching = "ReadWrite"
}

network_interface {
name = "example"
primary = true

ip_configuration {
name = "internal"
primary = true
subnet_id = azurerm_subnet.test.id
}
}

tags = {
ENV = "%s"
}
}
`, data.RandomInteger, data.RandomInteger, data.RandomInteger, tag)
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ func resourceLinuxVirtualMachineScaleSet() *pluginsdk.Resource {
}, false),
},

"extended_location": azure.SchemaExtendedLocation(),

"extension": VirtualMachineScaleSetExtensionsSchema(),

"extensions_time_budget": {
Expand Down Expand Up @@ -573,6 +575,13 @@ func resourceLinuxVirtualMachineScaleSetCreate(d *pluginsdk.ResourceData, meta i
props.Zones = azure.ExpandZones(zonesRaw)
}

if v, ok := d.GetOk("extended_location"); ok {
props.ExtendedLocation = &compute.ExtendedLocation{
Name: utils.String(v.(string)),
Type: compute.ExtendedLocationTypesEdgeZone,
}
}

if v, ok := d.GetOk("platform_fault_domain_count"); ok {
props.VirtualMachineScaleSetProperties.PlatformFaultDomainCount = utils.Int32(int32(v.(int)))
}
Expand Down Expand Up @@ -946,6 +955,10 @@ func resourceLinuxVirtualMachineScaleSetRead(d *pluginsdk.ResourceData, meta int
d.Set("location", location.NormalizeNilable(resp.Location))
d.Set("zones", zones.Flatten(resp.Zones))

if resp.ExtendedLocation != nil && resp.ExtendedLocation.Name != nil {
d.Set("extended_location", resp.ExtendedLocation.Name)
}

var skuName *string
var instances int
if resp.Sku != nil {
Expand Down
13 changes: 13 additions & 0 deletions internal/services/compute/managed_disk_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ func resourceManagedDisk() *pluginsdk.Resource {

"encryption_settings": encryptionSettingsSchema(),

"extended_location": azure.SchemaExtendedLocation(),

"network_access_policy": {
Type: pluginsdk.TypeString,
Optional: true,
Expand Down Expand Up @@ -483,6 +485,13 @@ func resourceManagedDiskCreate(d *pluginsdk.ResourceData, meta interface{}) erro
createDisk.Zones = azure.ExpandZones(d.Get("zones").([]interface{}))
}

if v, ok := d.GetOk("extended_location"); ok {
createDisk.ExtendedLocation = &compute.ExtendedLocation{
Name: utils.String(v.(string)),
Type: compute.ExtendedLocationTypesEdgeZone,
}
}

future, err := client.CreateOrUpdate(ctx, resourceGroup, name, createDisk)
if err != nil {
return fmt.Errorf("creating/updating Managed Disk %q (Resource Group %q): %+v", name, resourceGroup, err)
Expand Down Expand Up @@ -836,6 +845,10 @@ func resourceManagedDiskRead(d *pluginsdk.ResourceData, meta interface{}) error
d.Set("zones", utils.FlattenStringSlice(resp.Zones))
}

if resp.ExtendedLocation != nil && resp.ExtendedLocation.Name != nil {
d.Set("extended_location", resp.ExtendedLocation.Name)
}

if sku := resp.Sku; sku != nil {
d.Set("storage_account_type", string(sku.Name))
}
Expand Down
Loading