Merge branch 'master' into add_datadisk
This commit is contained in:
Коммит
2e7f63d65d
56
README.md
56
README.md
|
@ -16,37 +16,35 @@ Usage
|
|||
Provisions 2 Windows 2016 Datacenter Server VMs using `vm_os_simple` to a new VNet and opens up port 3389 for RDP access:
|
||||
|
||||
```hcl
|
||||
module "mycompute" {
|
||||
source = "Azure/compute/azurerm"
|
||||
resource_group_name = "mycompute"
|
||||
location = "East US 2"
|
||||
admin_password = ComplxP@ssw0rd!
|
||||
vm_os_simple = "WindowsServer"
|
||||
public_ip_dns = "mywinsrv252"
|
||||
remote_port = "3389"
|
||||
nb_instances = 2
|
||||
vnet_subnet_id = "${module.network.vnet_subnets[0]}"
|
||||
}
|
||||
|
||||
module "network" {
|
||||
source = "Azure/network/azurerm"
|
||||
location = "East US 2"
|
||||
resource_group_name = "mycompute"
|
||||
}
|
||||
|
||||
output "vm_public_name"{
|
||||
value = "${module.mycompute.public_ip_dns_name}"
|
||||
}
|
||||
|
||||
output "vm_public_ip" {
|
||||
value = "${module.mycompute.public_ip_address}"
|
||||
}
|
||||
|
||||
output "vm_private_ips" {
|
||||
value = "${module.mycompute.network_interface_private_ip}"
|
||||
}
|
||||
module "mycompute" {
|
||||
source = "Azure/compute/azurerm"
|
||||
resource_group_name = "mycompute"
|
||||
location = "East US 2"
|
||||
admin_password = "ComplxP@ssw0rd!"
|
||||
vm_os_simple = "WindowsServer"
|
||||
public_ip_dns = "mywinsrv252"
|
||||
remote_port = "3389"
|
||||
nb_instances = 2
|
||||
vnet_subnet_id = "${module.network.vnet_subnets[0]}"
|
||||
}
|
||||
|
||||
module "network" {
|
||||
source = "Azure/network/azurerm"
|
||||
location = "East US 2"
|
||||
resource_group_name = "mycompute"
|
||||
}
|
||||
|
||||
output "vm_public_name"{
|
||||
value = "${module.mycompute.public_ip_dns_name}"
|
||||
}
|
||||
|
||||
output "vm_public_ip" {
|
||||
value = "${module.mycompute.public_ip_address}"
|
||||
}
|
||||
|
||||
output "vm_private_ips" {
|
||||
value = "${module.mycompute.network_interface_private_ip}"
|
||||
}
|
||||
```
|
||||
Provisions 2 Ubuntu 14.04 Server VMs using `vm_os_publisher`, `vm_os_offer` and `vm_os_sku` to a new VNet and opens up port 22 for SSH access with ~/.ssh/id_rsa.pub :
|
||||
|
||||
|
|
31
main.tf
31
main.tf
|
@ -13,6 +13,22 @@ resource "azurerm_resource_group" "vm" {
|
|||
tags = "${var.tags}"
|
||||
}
|
||||
|
||||
resource "random_id" "vm-sa" {
|
||||
keepers = {
|
||||
vm_hostname = "${var.vm_hostname}"
|
||||
}
|
||||
byte_length = 6
|
||||
}
|
||||
|
||||
resource "azurerm_storage_account" "vm-sa" {
|
||||
count = "${var.boot_diagnostics == "true" ? 1 : 0}"
|
||||
name = "bootdiag${lower(random_id.vm-sa.hex)}"
|
||||
resource_group_name = "${azurerm_resource_group.vm.name}"
|
||||
location = "${var.location}"
|
||||
account_type = "${var.boot_diagnostics_sa_type}"
|
||||
tags = "${var.tags}"
|
||||
}
|
||||
|
||||
resource "azurerm_virtual_machine" "vm-linux" {
|
||||
count = "${!contains(list("${var.vm_os_simple}","${var.vm_os_offer}"), "WindowsServer") && var.datadisk == "false" ? var.nb_instances : 0}"
|
||||
name = "${var.vm_hostname}${count.index}"
|
||||
|
@ -61,6 +77,10 @@ resource "azurerm_virtual_machine" "vm-linux" {
|
|||
key_data = "${file("${var.ssh_key}")}"
|
||||
}
|
||||
}
|
||||
boot_diagnostics {
|
||||
enabled = "${var.boot_diagnostics}"
|
||||
storage_uri = "${var.boot_diagnostics == "true" ? join(",", azurerm_storage_account.vm-sa.*.primary_blob_endpoint) : "" }"
|
||||
}
|
||||
}
|
||||
|
||||
resource "azurerm_virtual_machine" "vm-linux-with-datadisk" {
|
||||
|
@ -191,6 +211,10 @@ resource "azurerm_virtual_machine" "vm-windows-with-datadisk" {
|
|||
admin_username = "${var.admin_username}"
|
||||
admin_password = "${var.admin_password}"
|
||||
}
|
||||
boot_diagnostics {
|
||||
enabled = "${var.boot_diagnostics}"
|
||||
storage_uri = "${var.boot_diagnostics == "true" ? join(",", azurerm_storage_account.vm-sa.*.primary_blob_endpoint) : "" }"
|
||||
}
|
||||
}
|
||||
|
||||
resource "azurerm_availability_set" "vm" {
|
||||
|
@ -203,11 +227,12 @@ resource "azurerm_availability_set" "vm" {
|
|||
}
|
||||
|
||||
resource "azurerm_public_ip" "vm" {
|
||||
name = "${var.vm_hostname}-publicIP"
|
||||
count = "${var.nb_public_ip}"
|
||||
name = "${var.vm_hostname}-${count.index}-publicIP"
|
||||
location = "${var.location}"
|
||||
resource_group_name = "${azurerm_resource_group.vm.name}"
|
||||
public_ip_address_allocation = "${var.public_ip_address_allocation}"
|
||||
domain_name_label = "${var.public_ip_dns}"
|
||||
domain_name_label = "${element(var.public_ip_dns, count.index)}"
|
||||
}
|
||||
|
||||
resource "azurerm_network_security_group" "vm" {
|
||||
|
@ -240,6 +265,6 @@ resource "azurerm_network_interface" "vm" {
|
|||
name = "ipconfig${count.index}"
|
||||
subnet_id = "${var.vnet_subnet_id}"
|
||||
private_ip_address_allocation = "Dynamic"
|
||||
public_ip_address_id = "${count.index == 0 ? azurerm_public_ip.vm.id : ""}"
|
||||
public_ip_address_id = "${length(azurerm_public_ip.vm.*.id) > 0 ? element(concat(azurerm_public_ip.vm.*.id, list("")), count.index) : ""}"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,17 +20,17 @@ output "network_interface_private_ip"{
|
|||
|
||||
output "public_ip_id" {
|
||||
description = "id of the public ip address provisoned."
|
||||
value = "${azurerm_public_ip.vm.id}"
|
||||
value = "${azurerm_public_ip.vm.*.id}"
|
||||
}
|
||||
|
||||
output "public_ip_address" {
|
||||
description = "The actual ip address allocated for the resource."
|
||||
value = "${azurerm_public_ip.vm.ip_address}"
|
||||
value = "${azurerm_public_ip.vm.*.ip_address}"
|
||||
}
|
||||
|
||||
output "public_ip_dns_name" {
|
||||
description = "fqdn to connect to the first vm provisioned."
|
||||
value = "${azurerm_public_ip.vm.fqdn}"
|
||||
value = "${azurerm_public_ip.vm.*.fqdn}"
|
||||
}
|
||||
|
||||
output "availability_set_id" {
|
||||
|
|
20
variables.tf
20
variables.tf
|
@ -12,8 +12,8 @@ variable "vnet_subnet_id"{
|
|||
}
|
||||
|
||||
variable "public_ip_dns" {
|
||||
description = "Optional globally unique per datacenter region domain name label to apply to the public ip address. e.g. thisvar.varlocation.cloudapp.azure.com"
|
||||
default = ""
|
||||
description = "Optional globally unique per datacenter region domain name label to apply to each public ip address. e.g. thisvar.varlocation.cloudapp.azure.com where you specify only thisvar here. This is an array of names which will pair up sequentially to the number of public ips defined in var.nb_public_ip. One name or empty string is required for every public ip. If no public ip is desired, then set this to an array with a single empty string."
|
||||
default = [""]
|
||||
}
|
||||
|
||||
variable "admin_password" {
|
||||
|
@ -98,10 +98,16 @@ variable "public_ip_address_allocation" {
|
|||
default = "static"
|
||||
}
|
||||
|
||||
variable "nb_public_ip" {
|
||||
description = "Number of public IPs to assign corresponding to one IP per vm. Set to 0 to not assign any public IP addresses."
|
||||
default = "1"
|
||||
}
|
||||
|
||||
variable "delete_os_disk_on_termination" {
|
||||
description = "Delete datadisk when machine is terminated"
|
||||
default = "false"
|
||||
}
|
||||
|
||||
variable "data_sa_type" {
|
||||
description = "Data Disk Storage Account type"
|
||||
default = "Standard_LRS"
|
||||
|
@ -117,3 +123,13 @@ variable "datadisk" {
|
|||
description = "Set to true to add a datadisk."
|
||||
default = "false"
|
||||
}
|
||||
|
||||
variable "boot_diagnostics" {
|
||||
description = "(Optional) Enable or Disable boot diagnostics"
|
||||
default = "false"
|
||||
}
|
||||
|
||||
variable "boot_diagnostics_sa_type" {
|
||||
description = "(Optional) Storage account type for boot diagnostics"
|
||||
default = "Standard_LRS"
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче