-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Changes from 11 commits
767d12a
2a42c3d
3a52e26
bec5dba
e8b5879
2157381
9c3e470
1374308
89f7dfd
aed25a2
d6b7076
cbc01aa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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" | ||
|
||
# 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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question here about vm size. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as above - this'll become |
||
|
||
# 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,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. |
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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question as above vm size. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as above - this'll become |
||
|
||
# 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. |
There was a problem hiding this comment.
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?