-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Examples of using Remote-Exec Provisioners for Windows and Linux (#1665)
* Adding an example of using a remote-exec provisioner on linux * Adding an example of using WinRM to run commands on a machine * Adding an example of a VM with Unmanaged Disks * Example of provisioning a Managed Disks VM from a Custom Image (ported from the VM Docs) * Example of provisioning a Basic VM with Managed Disks * Correctly documenting the delete methods * Adding an example of attaching data disks to a vm * Fixing the readme * Updating the VM Docs to be clearer * Fixing a bug in the attach disks demo * additional validation for the vm resource * Switching over to Standard_F2's for the examples
- Loading branch information
1 parent
377b243
commit d88d774
Showing
32 changed files
with
1,079 additions
and
368 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
examples/virtual-machines/managed-disks/attaching-external-disks/1-dependencies.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
examples/virtual-machines/managed-disks/attaching-external-disks/2-virtual-machine.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_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}" | ||
} |
17 changes: 17 additions & 0 deletions
17
examples/virtual-machines/managed-disks/attaching-external-disks/3-external-disks.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
14 changes: 14 additions & 0 deletions
14
examples/virtual-machines/managed-disks/attaching-external-disks/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`. |
18 changes: 18 additions & 0 deletions
18
examples/virtual-machines/managed-disks/attaching-external-disks/variables.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
33 changes: 33 additions & 0 deletions
33
examples/virtual-machines/managed-disks/basic-osdisk/1-dependencies.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
examples/virtual-machines/managed-disks/basic-osdisk/2-virtual-machine.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_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
13
examples/virtual-machines/managed-disks/basic-osdisk/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
13
examples/virtual-machines/managed-disks/basic-osdisk/variables.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
33 changes: 33 additions & 0 deletions
33
examples/virtual-machines/managed-disks/from-custom-image/1-dependencies.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
examples/virtual-machines/managed-disks/from-custom-image/2-virtual-machine.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_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}" | ||
} |
17 changes: 17 additions & 0 deletions
17
examples/virtual-machines/managed-disks/from-custom-image/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
Oops, something went wrong.