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

New resource: azurerm_orchestrated_virtual_machine_scale_set #6626

Merged
merged 29 commits into from
May 21, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b48bd4b
Refine VM ID parse functions
ArcturusZhang Apr 8, 2020
4f30719
Some follow ups on VM ID refactor
ArcturusZhang Apr 8, 2020
5658d03
VMSS and extension refactor
ArcturusZhang Apr 8, 2020
6facd42
VM extension refactor
ArcturusZhang Apr 8, 2020
94236b9
Managed disk ID
ArcturusZhang Apr 8, 2020
865f825
Fix CI
ArcturusZhang Apr 8, 2020
988a70c
Fix another missed one
ArcturusZhang Apr 8, 2020
48a2e32
go imports
ArcturusZhang Apr 9, 2020
d54f13f
Goimports again...
ArcturusZhang Apr 9, 2020
b873afe
Add new resource of VMSS in VMO mode
ArcturusZhang Apr 8, 2020
5a4cf2c
Modify VM to support create VM in VMSS VMO mode
ArcturusZhang Apr 8, 2020
79ddbbe
Fix some problems
ArcturusZhang Apr 9, 2020
b69881f
Initial commit of acc test
ArcturusZhang Apr 10, 2020
9d33259
Merge remote-tracking branch 'origin/master' into Orchestration-mode
ArcturusZhang Apr 10, 2020
0cb68ac
Finalize tests and doc
ArcturusZhang Apr 10, 2020
85d2761
Merge remote-tracking branch 'origin/master' into Orchestration-mode
ArcturusZhang Apr 10, 2020
86ea743
Merge remote-tracking branch 'origin/master' into Orchestration-mode
ArcturusZhang Apr 15, 2020
cec54f6
Finalize orchestration mode
ArcturusZhang Apr 22, 2020
8397ec4
Merge remote-tracking branch 'origin/master' into Orchestration-mode
ArcturusZhang Apr 22, 2020
aa5bb58
terrafmt
ArcturusZhang Apr 22, 2020
bd796fc
Resolve comments
ArcturusZhang Apr 26, 2020
cdcfa20
gofmt
ArcturusZhang Apr 26, 2020
b5bd514
terrafmt
ArcturusZhang Apr 26, 2020
4c43f60
Merge remote-tracking branch 'origin/master' into Orchestration-mode
ArcturusZhang May 8, 2020
23f8129
Rename virtual_machine_scale_set_orchestrator_vm to orchestrated_virt…
ArcturusZhang May 8, 2020
a7abdc5
Resolve comments
ArcturusZhang May 15, 2020
8351c72
Fix the bad link
ArcturusZhang May 15, 2020
8e7a2bd
Merge remote-tracking branch 'origin/master' into Orchestration-mode
ArcturusZhang May 18, 2020
563322f
Fix bad test cases
ArcturusZhang May 21, 2020
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
Prev Previous commit
Next Next commit
Resolve comments
  • Loading branch information
ArcturusZhang committed Apr 26, 2020
commit bd796fc408df0d0290bfc0fcf123a17c49d368f3
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ func TestAccDataSourceAzureRMWindowsVirtualMachineScaleSetOrchestratorVM_basic(t
{
Config: testAccDataSourceAzureRMWindowsVirtualMachineScaleSetOrchestratorVM_basic(data),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(data.ResourceName, "location"),
resource.TestCheckResourceAttrSet(data.ResourceName, "unique_id"),
resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"),
resource.TestCheckResourceAttr(data.ResourceName, "tags.ENV", "Test"),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,58 @@ func TestAccAzureRMWindowsVirtualMachineScaleSetOrchestratorVM_multipleWindows(t
})
}

func TestAccAzureRMWindowsVirtualMachineScaleSetOrchestratorVM_basicLinuxUpdate(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set_orchestrator_vm", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetOrchestratorVMDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMWindowsVirtualMachineScaleSetOrchestratorVM_basicLinux(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMWindowsVirtualMachineScaleSetOrchestratorVMExists(data.ResourceName),
),
},
data.ImportStep(),
{
Config: testAccAzureRMWindowsVirtualMachineScaleSetOrchestratorVM_basicLinuxUpdate(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMWindowsVirtualMachineScaleSetOrchestratorVMExists(data.ResourceName),
),
},
data.ImportStep(),
{
Config: testAccAzureRMWindowsVirtualMachineScaleSetOrchestratorVM_basicLinux(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMWindowsVirtualMachineScaleSetOrchestratorVMExists(data.ResourceName),
),
},
data.ImportStep(),
},
})
}

func TestAccAzureRMWindowsVirtualMachineScaleSetOrchestratorVM_requiresImport(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set_orchestrator_vm", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {acceptance.PreCheck(t)},
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetOrchestratorVMDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMWindowsVirtualMachineScaleSetOrchestratorVM_basicLinux(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMWindowsVirtualMachineScaleSetOrchestratorVMExists(data.ResourceName),
),
},
data.RequiresImportErrorStep(testAccAzureRMWindowsVirtualMachineScaleSetOrchestratorVM_requiresImport),
},
})
}

func testCheckAzureRMWindowsVirtualMachineScaleSetOrchestratorVMDestroy(s *terraform.State) error {
client := acceptance.AzureProvider.Meta().(*clients.Client).Compute.VMScaleSetClient
ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext
Expand Down Expand Up @@ -205,6 +257,22 @@ resource "azurerm_linux_virtual_machine" "test" {
`, template, data.RandomInteger)
}

func testAccAzureRMWindowsVirtualMachineScaleSetOrchestratorVM_requiresImport(data acceptance.TestData) string {
template := testAccAzureRMWindowsVirtualMachineScaleSetOrchestratorVM_basicLinux(data)
return fmt.Sprintf(`
%s

resource "azurerm_virtual_machine_scale_set_orchestrator_vm" "import" {
name = azurerm_virtual_machine_scale_set_orchestrator_vm.test.name
location = azurerm_virtual_machine_scale_set_orchestrator_vm.test.location
resource_group_name = azurerm_virtual_machine_scale_set_orchestrator_vm.test.resource_group_name

platform_fault_domain_count = azurerm_virtual_machine_scale_set_orchestrator_vm.test.platform_fault_domain_count
single_placement_group = azurerm_virtual_machine_scale_set_orchestrator_vm.test.single_placement_group
}
`, template)
}

func testAccAzureRMWindowsVirtualMachineScaleSetOrchestratorVM_multipleLinux(data acceptance.TestData) string {
template := testAccAzureRMWindowsVirtualMachineScaleSetOrchestratorVM_template(data)
return fmt.Sprintf(`
Expand Down Expand Up @@ -492,3 +560,65 @@ resource "azurerm_subnet" "test" {
}
`, data.RandomInteger, location)
}

func testAccAzureRMWindowsVirtualMachineScaleSetOrchestratorVM_basicLinuxUpdate(data acceptance.TestData) string {
template := testAccAzureRMWindowsVirtualMachineScaleSetOrchestratorVM_template(data)
return fmt.Sprintf(`
%[1]s

resource "azurerm_network_interface" "test" {
name = "acctestnic-%[2]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_virtual_machine_scale_set_orchestrator_vm" "test" {
name = "acctestVMO-%[2]d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name

platform_fault_domain_count = 5
single_placement_group = true

zones = ["1"]

tags = {
ENV = "Test",
FOO = "Bar"
}
}

resource "azurerm_linux_virtual_machine" "test" {
name = "acctestVM-%[2]d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
size = "Standard_F2"
admin_username = "adminuser"
admin_password = "P@ssw0rd1234!"
disable_password_authentication = false
network_interface_ids = [
azurerm_network_interface.test.id,
]

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

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

virtual_machine_scale_set_id = azurerm_virtual_machine_scale_set_orchestrator_vm.test.id
}
`, template, data.RandomInteger)
}
5 changes: 5 additions & 0 deletions azurerm/internal/services/compute/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ func ValidateWindowsName(i interface{}, k string) (warnings []string, errors []e
return warnings, errors
}

// Currently the name validation for VMSS in orchestration mode VM is the same as Linux ones.
func ValidateVMSSOrchestratorVMName(i interface{}, k string) (warnings []string, errors []error) {
return ValidateLinuxName(i, k)
}

func validateDiskEncryptionSetName(i interface{}, k string) (warnings []string, errors []error) {
v, ok := i.(string)
if !ok {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func importVirtualMachineScaleSetOrchestratorVM(d *schema.ResourceData, meta int

vm, err := client.Get(ctx, id.ResourceGroup, id.Name)
if err != nil {
return []*schema.ResourceData{}, fmt.Errorf("Error retrieving Virtual Machine Scale Set %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err)
return []*schema.ResourceData{}, fmt.Errorf("retrieving Virtual Machine Scale Set %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err)
}

if err := assertVirtualMachineScaleSetOrchestratorVM(vm); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,18 @@ func dataSourceArmVirtualMachineScaleSetOrchestratorVM() *schema.Resource {
"name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: ValidateLinuxName,
ValidateFunc: ValidateVMSSOrchestratorVMName,
},

"resource_group_name": azure.SchemaResourceGroupNameForDataSource(),

"location": azure.SchemaLocationForDataSource(),

"unique_id": {
Type: schema.TypeString,
Computed: true,
},

"tags": tags.SchemaDataSource(),
},
}
Expand Down Expand Up @@ -66,6 +71,9 @@ func dataSourceArmVirtualMachineScaleSetOrchestratorVMRead(d *schema.ResourceDat
d.Set("name", name)
d.Set("resource_group_name", resourceGroup)
d.Set("location", location.NormalizeNilable(resp.Location))
if props := resp.VirtualMachineScaleSetProperties; props != nil {
d.Set("unique_id", props.UniqueID)
}

return tags.FlattenAndSet(d, resp.Tags)
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func resourceArmVirtualMachineScaleSetOrchestratorVM() *schema.Resource {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: ValidateLinuxName,
ValidateFunc: ValidateVMSSOrchestratorVMName,
},

"resource_group_name": azure.SchemaResourceGroupName(),
Expand All @@ -61,9 +61,10 @@ func resourceArmVirtualMachineScaleSetOrchestratorVM() *schema.Resource {
"single_placement_group": {
Type: schema.TypeBool,
Required: true,
ForceNew: true,
},

// the VMO mode can only be deployed into one zone, and its zone will also be assigned to all its VM instances
// the VMO mode can only be deployed into one zone for now, and its zone will also be assigned to all its VM instances
"zones": azure.SchemaSingleZone(),

"unique_id": {
Expand All @@ -88,12 +89,12 @@ func resourceArmVirtualMachineScaleSetOrchestratorVMCreateUpdate(d *schema.Resou
resp, err := client.Get(ctx, resourceGroup, name)
if err != nil {
if !utils.ResponseWasNotFound(resp.Response) {
return fmt.Errorf("checking for existing Windows Virtual Machine Scale Set %q (Resource Group %q): %+v", name, resourceGroup, err)
return fmt.Errorf("checking for existing Virtual Machine Scale Set Orchestrator VM %q (Resource Group %q): %+v", name, resourceGroup, err)
}
}

if !utils.ResponseWasNotFound(resp.Response) {
return tf.ImportAsExistsError("azurerm_windows_virtual_machine_scale_set", *resp.ID)
return tf.ImportAsExistsError("azurerm_virtual_machine_scale_set_orchestrator_vm", *resp.ID)
}
}

Expand All @@ -109,20 +110,20 @@ func resourceArmVirtualMachineScaleSetOrchestratorVMCreateUpdate(d *schema.Resou

future, err := client.CreateOrUpdate(ctx, resourceGroup, name, props)
if err != nil {
return fmt.Errorf("creating Virtual Machine Scale Set VM Mode %q (Resource Group %q): %+v", name, resourceGroup, err)
return fmt.Errorf("creating Virtual Machine Scale Set Orchestrator VM %q (Resource Group %q): %+v", name, resourceGroup, err)
}

if err := future.WaitForCompletionRef(ctx, client.Client); err != nil {
return fmt.Errorf("waiting for creation of Virtual Machine Scale Set VM Mode %q (Resource Group %q): %+v", name, resourceGroup, err)
return fmt.Errorf("waiting for creation of Virtual Machine Scale Set Orchestrator VM %q (Resource Group %q): %+v", name, resourceGroup, err)
}

resp, err := client.Get(ctx, resourceGroup, name)
if err != nil {
return fmt.Errorf("retrieving Virtual Machine Scale Set VM Mode %q (Resource Group %q): %+v", name, resourceGroup, err)
return fmt.Errorf("retrieving Virtual Machine Scale Set Orchestrator VM %q (Resource Group %q): %+v", name, resourceGroup, err)
}

if resp.ID == nil {
return fmt.Errorf("retrieving Virtual Machine Scale Set VM Mode %q (Resource Group %q): ID was nil", name, resourceGroup)
if resp.ID == nil || *resp.ID == "" {
return fmt.Errorf("retrieving Virtual Machine Scale Set Orchestrator VM %q (Resource Group %q): ID was empty", name, resourceGroup)
}
d.SetId(*resp.ID)

Expand All @@ -142,12 +143,12 @@ func resourceArmVirtualMachineScaleSetOrchestratorVMRead(d *schema.ResourceData,
resp, err := client.Get(ctx, id.ResourceGroup, id.Name)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
log.Printf("[DEBUG] Virtual Machine Scale Set VM Mode %q was not found in Resource Group %q - removing from state!", id.Name, id.ResourceGroup)
log.Printf("[DEBUG] Virtual Machine Scale Set Orchestrator VM %q was not found in Resource Group %q - removing from state!", id.Name, id.ResourceGroup)
d.SetId("")
return nil
}

return fmt.Errorf("retrieving Virtual Machine Scale Set VM Mode %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err)
return fmt.Errorf("retrieving Virtual Machine Scale Set Orchestrator VM %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err)
}

d.Set("name", id.Name)
Expand Down Expand Up @@ -183,16 +184,16 @@ func resourceArmVirtualMachineScaleSetOrchestratorVMDelete(d *schema.ResourceDat
return nil
}

return fmt.Errorf("retrieving Virtual Machine Scale Set VM Mode %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err)
return fmt.Errorf("retrieving Virtual Machine Scale Set Orchestrator VM %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err)
}

future, err := client.Delete(ctx, id.ResourceGroup, id.Name)
if err != nil {
return fmt.Errorf("deleting Virtual Machine Scale Set VM Mode %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err)
return fmt.Errorf("deleting Virtual Machine Scale Set Orchestrator VM %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err)
}

if err := future.WaitForCompletionRef(ctx, client.Client); err != nil {
return fmt.Errorf("waiting for deletion of Virtual Machine Scale Set VM Mode %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err)
return fmt.Errorf("waiting for deletion of Virtual Machine Scale Set Orchestrator VM %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err)
}

return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ output "id" {

* `tags` - A mapping of tags assigned to this Virtual Machine Scale Set Orchestrator VM.

* `unique_id` - The Unique ID of this Virtual Machine Scale Set Orchestrator VM.

## Timeouts

The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions:
Expand Down
4 changes: 4 additions & 0 deletions website/docs/r/linux_virtual_machine.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ The following arguments are supported:

* `tags` - (Optional) A mapping of tags which should be assigned to this Virtual Machine.

* `virtual_machine_scale_set_id` - (Optional) Specifies the Virtual Machine Scale Set that this Virtual Machine needs to be added.
ArcturusZhang marked this conversation as resolved.
Show resolved Hide resolved

~> **NOTE:** The referenced Virtual Machine Scale Set must be in the orchestration mode of `VM`. This could be only used accompany by `azurerm_virtual_machine_scale_set_orchestrator_vm`.

* `zone` - (Optional) The Zone in which this Virtual Machine should be created. Changing this forces a new resource to be created.

---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ description: |-

Manages a Virtual Machine Scale Set Orchestrator VM.

~> **NOTE:** This resource is part of the public preview feature of virtual machine scale set orchestration mode, and this resource manages a virtual machine scale set in VM orchestration mode. You can find more information about the orchestration mode in [this doc](https://docs.microsoft.com/en-us/azure/virtual-machine-scale-sets/orchestration-modes).
~> **NOTE:** This resource is part of the public preview feature of virtual machine scale set orchestration mode, which manages a virtual machine scale set in VM orchestration mode. You can find more information about the orchestration mode [here](https://docs.microsoft.com/en-us/azure/virtual-machine-scale-sets/orchestration-modes).

## Example Usage

Expand Down Expand Up @@ -99,13 +99,13 @@ The following arguments are supported:

* `resource_group_name` - (Required) The name of the Resource Group in which the Virtual Machine Scale Set Orchestrator VM should be exist. Changing this forces a new resource to be created.

* `platform_fault_domain_count` - (Required) Specifies the number of fault domains that are used by this Virtual Machine Scale Set Orchestrator VM.
* `platform_fault_domain_count` - (Required) Specifies the number of fault domains that are used by this Virtual Machine Scale Set Orchestrator VM. Changing this forces a new resource to be created.

~> **NOTE:** The number of Fault Domains varies depending on which Azure Region you're using - [a list can be found here](https://github.com/MicrosoftDocs/azure-docs/blob/master/includes/managed-disks-common-fault-domain-region-list.md).
~> **NOTE:** The number of Fault Domains varies depending on which Azure Region you're using - a list can be found [here](https://github.com/MicrosoftDocs/azure-docs/blob/master/includes/managed-disks-common-fault-domain-region-list.md).

* `single_placement_group` - (Required) Should the Virtual Machine Scale Set Orchestrator VM use single placement group?
* `single_placement_group` - (Required) Should the Virtual Machine Scale Set Orchestrator VM use single placement group? Changing this forces a new resource to be created.

~> **NOTE:** You can only assign `single_placement_group` `false` unless you have opted-in the private preview program of the orchestration mode of virtual machine scale sets.
~> **NOTE:** You cannot assign `single_placement_group` to `true` unless you have opted-in the private preview program of the orchestration mode of virtual machine scale sets.

* `zones` - (Optional) A list of Availability Zones in which the Virtual Machines in this Scale Set should be created in. Changing this forces a new resource to be created.

Expand Down
4 changes: 4 additions & 0 deletions website/docs/r/windows_virtual_machine.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ The following arguments are supported:

* `timezone` - (Optional) Specifies the Time Zone which should be used by the Virtual Machine, [the possible values are defined here](https://jackstromberg.com/2017/01/list-of-time-zones-consumed-by-azure/).

* `virtual_machine_scale_set_id` - (Optional) Specifies the Virtual Machine Scale Set that this Virtual Machine needs to be added.
ArcturusZhang marked this conversation as resolved.
Show resolved Hide resolved

~> **NOTE:** The referenced Virtual Machine Scale Set must be in the orchestration mode of `VM`. This could be only used accompany by `azurerm_virtual_machine_scale_set_orchestrator_vm`.

* `winrm_listener` - (Optional) One or more `winrm_listener` blocks as defined below.

* `zone` - (Optional) The Zone in which this Virtual Machine should be created. Changing this forces a new resource to be created.
Expand Down