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

Examples of using Remote-Exec Provisioners for Windows and Linux #1665

Merged
merged 12 commits into from
Jul 30, 2018
Merged
Show file tree
Hide file tree
Changes from 11 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
18 changes: 17 additions & 1 deletion azurerm/resource_arm_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,11 @@ func resourceArmVirtualMachine() *schema.Resource {
"protocol": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{
"HTTP",
"HTTPS",
}, true),
DiffSuppressFunc: ignoreCaseDiffSuppressFunc,
},
"certificate_url": {
Type: schema.TypeString,
Expand All @@ -425,17 +430,28 @@ func resourceArmVirtualMachine() *schema.Resource {
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
// TODO: should we make `pass` and `component` Optional + Defaulted?
"pass": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{
"oobeSystem",
}, false),
},
"component": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{
"Microsoft-Windows-Shell-Setup",
}, false),
},
"setting_name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{
"AutoLogon",
"FirstLogonCommands",
}, false),
},
"content": {
Type: schema.TypeString,
Expand Down Expand Up @@ -472,7 +488,7 @@ func resourceArmVirtualMachine() *schema.Resource {
},
"key_data": {
Type: schema.TypeString,
Optional: true,
Required: true,
},
},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
resource "azurerm_resource_group" "main" {
name = "${var.prefix}-resources"
location = "${var.location}"
tags = "${var.tags}"
}

resource "azurerm_virtual_network" "main" {
name = "${var.prefix}-network"
address_space = ["10.0.0.0/16"]
location = "${azurerm_resource_group.main.location}"
resource_group_name = "${azurerm_resource_group.main.name}"
tags = "${var.tags}"
}

resource "azurerm_subnet" "internal" {
name = "internal"
resource_group_name = "${azurerm_resource_group.main.name}"
virtual_network_name = "${azurerm_virtual_network.main.name}"
address_prefix = "10.0.2.0/24"
}

resource "azurerm_network_interface" "main" {
name = "${var.prefix}-nic"
location = "${azurerm_resource_group.main.location}"
resource_group_name = "${azurerm_resource_group.main.name}"
tags = "${var.tags}"

ip_configuration {
name = "testconfiguration1"
subnet_id = "${azurerm_subnet.internal.id}"
private_ip_address_allocation = "dynamic"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
resource "azurerm_virtual_machine" "main" {
name = "${var.prefix}-vm"
location = "${azurerm_resource_group.main.location}"
resource_group_name = "${azurerm_resource_group.main.name}"
network_interface_ids = ["${azurerm_network_interface.main.id}"]
vm_size = "Standard_DS1_v2"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't we use the Standard_DS2_v2 size here?


# This means the OS Disk will be deleted when Terraform destroys the Virtual Machine
# NOTE: This may not be optimal in all cases.
delete_os_disk_on_termination = true

# This means the Data Disk Disk will be deleted when Terraform destroys the Virtual Machine
# NOTE: This may not be optimal in all cases.
delete_data_disks_on_termination = true

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

storage_os_disk {
name = "myosdisk1"
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Standard_LRS"
}

os_profile {
computer_name = "hostname"
admin_username = "testadmin"
admin_password = "Password1234!"
}

os_profile_linux_config {
disable_password_authentication = false
}

tags = "${var.tags}"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
resource "azurerm_managed_disk" "external" {
count = "${var.number_of_disks}"
name = "${var.prefix}-disk${count.index+1}"
location = "${azurerm_resource_group.main.location}"
resource_group_name = "${azurerm_resource_group.main.name}"
storage_account_type = "Standard_LRS"
create_option = "Empty"
disk_size_gb = "10"
}

resource "azurerm_virtual_machine_data_disk_attachment" "external" {
count = "${var.number_of_disks}"
managed_disk_id = "${azurerm_managed_disk.external.*.id[count.index]}"
virtual_machine_id = "${azurerm_virtual_machine.main.id}"
lun = "${10+count.index}"
caching = "ReadWrite"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## Example: Virtual Machine with Data Disks

This example provisions a Virtual Machine with 2 Data Disks and an OS Disk all of which are Managed Disks.

Notes:

- The files involved in this example are split out to make it easier to read, however all of the resources could be combined into a single file if needed.

### Variables

* `prefix` - (Required) The Prefix used for all resources in this example.
* `location` - (Required) The Azure Region in which the resources in this example should exist.
* `tags` - (Optional) Any tags which should be assigned to the resources in this example.
* `number_of_disks` - (Optional) The number of Data Disks which should be attached, defaults to `2`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
variable "prefix" {
description = "The Prefix used for all resources in this example"
}

variable "location" {
description = "The Azure Region in which the resources in this example should exist"
}

variable "tags" {
type = "map"
default = {}
description = "Any tags which should be assigned to the resources in this example"
}

variable "number_of_disks" {
description = "The number of Data Disks which should be attached"
default = 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
resource "azurerm_resource_group" "main" {
name = "${var.prefix}-resources"
location = "${var.location}"
tags = "${var.tags}"
}

resource "azurerm_virtual_network" "main" {
name = "${var.prefix}-network"
address_space = ["10.0.0.0/16"]
location = "${azurerm_resource_group.main.location}"
resource_group_name = "${azurerm_resource_group.main.name}"
tags = "${var.tags}"
}

resource "azurerm_subnet" "internal" {
name = "internal"
resource_group_name = "${azurerm_resource_group.main.name}"
virtual_network_name = "${azurerm_virtual_network.main.name}"
address_prefix = "10.0.2.0/24"
}

resource "azurerm_network_interface" "main" {
name = "${var.prefix}-nic"
location = "${azurerm_resource_group.main.location}"
resource_group_name = "${azurerm_resource_group.main.name}"
tags = "${var.tags}"

ip_configuration {
name = "testconfiguration1"
subnet_id = "${azurerm_subnet.internal.id}"
private_ip_address_allocation = "dynamic"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
resource "azurerm_virtual_machine" "test" {
name = "${var.prefix}-vm"
location = "${azurerm_resource_group.main.location}"
resource_group_name = "${azurerm_resource_group.main.name}"
network_interface_ids = ["${azurerm_network_interface.main.id}"]
vm_size = "Standard_DS1_v2"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same question here about vm size.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

as above - this'll become Standard_F2


# This means the OS Disk will be deleted when Terraform destroys the Virtual Machine
# NOTE: This may not be optimal in all cases.
delete_os_disk_on_termination = true

# This means the Data Disk Disk will be deleted when Terraform destroys the Virtual Machine
# NOTE: This may not be optimal in all cases.
delete_data_disks_on_termination = true

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

storage_os_disk {
name = "myosdisk1"
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Standard_LRS"
}

os_profile {
computer_name = "hostname"
admin_username = "testadmin"
admin_password = "Password1234!"
}

os_profile_linux_config {
disable_password_authentication = false
}

tags = "${var.tags}"
}
13 changes: 13 additions & 0 deletions examples/virtual-machines/managed-disks/basic-osdisk/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## Example: Basic Virtual Machine using a Managed Disk

This example provisions a Virtual Machine with no Data Disks with a Managed Disk as the main OS Disk.

Notes:

- The files involved in this example are split out to make it easier to read, however all of the resources could be combined into a single file if needed.

### Variables

* `prefix` - (Required) The Prefix used for all resources in this example.
* `location` - (Required) The Azure Region in which the resources in this example should exist.
* `tags` - (Optional) Any tags which should be assigned to the resources in this example.
13 changes: 13 additions & 0 deletions examples/virtual-machines/managed-disks/basic-osdisk/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
variable "prefix" {
description = "The Prefix used for all resources in this example"
}

variable "location" {
description = "The Azure Region in which the resources in this example should exist"
}

variable "tags" {
type = "map"
default = {}
description = "Any tags which should be assigned to the resources in this example"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
resource "azurerm_resource_group" "main" {
name = "${var.prefix}-resources"
location = "${var.location}"
tags = "${var.tags}"
}

resource "azurerm_virtual_network" "main" {
name = "${var.prefix}-network"
address_space = ["10.0.0.0/16"]
location = "${azurerm_resource_group.main.location}"
resource_group_name = "${azurerm_resource_group.main.name}"
tags = "${var.tags}"
}

resource "azurerm_subnet" "internal" {
name = "internal"
resource_group_name = "${azurerm_resource_group.main.name}"
virtual_network_name = "${azurerm_virtual_network.main.name}"
address_prefix = "10.0.2.0/24"
}

resource "azurerm_network_interface" "main" {
name = "${var.prefix}-nic"
location = "${azurerm_resource_group.main.location}"
resource_group_name = "${azurerm_resource_group.main.name}"
tags = "${var.tags}"

ip_configuration {
name = "testconfiguration1"
subnet_id = "${azurerm_subnet.internal.id}"
private_ip_address_allocation = "dynamic"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# we assume that this Custom Image already exists
data "azurerm_image" "custom" {
name = "${var.custom_image_name}"
resource_group_name = "${var.custom_image_resource_group_name}"
}

resource "azurerm_virtual_machine" "test" {
name = "${var.prefix}-vm"
location = "${azurerm_resource_group.main.location}"
resource_group_name = "${azurerm_resource_group.main.name}"
network_interface_ids = ["${azurerm_network_interface.main.id}"]
vm_size = "Standard_DS1_v2"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same question as above vm size.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

as above - this'll become Standard_F2


# This means the OS Disk will be deleted when Terraform destroys the Virtual Machine
# NOTE: This may not be optimal in all cases.
delete_os_disk_on_termination = true

# This means the Data Disk Disk will be deleted when Terraform destroys the Virtual Machine
# NOTE: This may not be optimal in all cases.
delete_data_disks_on_termination = true

storage_image_reference {
id = "${data.azurerm_image.custom.id}"
}

storage_os_disk {
name = "osdisk"
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Standard_LRS"
}

os_profile {
computer_name = "hostname"
admin_username = "testadmin"
admin_password = "Password1234!"
}

os_profile_linux_config {
disable_password_authentication = false
}

tags = "${var.tags}"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## Example: Virtual Machine with Managed Disks from a Custom Image

This example provisions a Virtual Machine with Managed Disks from a Custom Image that already exists.

Notes:

- The files involved in this example are split out to make it easier to read, however all of the resources could be combined into a single file if needed.
- This example assumes the Custom Image specified exists - if it doesn't this example will fail.

### Variables

* `prefix` - (Required) The Prefix used for all resources in this example.
* `location` - (Required) The Azure Region in which the resources in this example should exist.
* `tags` - (Optional) Any tags which should be assigned to the resources in this example.

* `custom_image_resource_group_name` - (Required) The name of the Resource Group in which the Custom Image exists.
* `custom_image_name` - (Required) The name of the Custom Image to provision this Virtual Machine from.
Loading