upgrade to Terraform v0.12 (#122)
* upgrade to v0.12 * add comment for test * add comment for test * remove useless test code * change bool type * remove useless import * add os back
This commit is contained in:
Родитель
97f2eccc99
Коммит
995219821c
|
@ -13,7 +13,7 @@ services:
|
|||
- docker
|
||||
|
||||
env:
|
||||
- TERRAFORM_VERSION=0.11.7 IMAGE_NAME=azure-compute-module
|
||||
- TERRAFORM_VERSION=0.12.10 IMAGE_NAME=azure-compute-module
|
||||
|
||||
jobs:
|
||||
include:
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# Pull the base image with given version.
|
||||
ARG BUILD_TERRAFORM_VERSION="0.11.7"
|
||||
FROM microsoft/terraform-test:${BUILD_TERRAFORM_VERSION}
|
||||
ARG BUILD_TERRAFORM_VERSION="0.12.10"
|
||||
FROM mcr.microsoft.com/terraform-test:${BUILD_TERRAFORM_VERSION}
|
||||
|
||||
ARG MODULE_NAME="terraform-azurerm-compute"
|
||||
|
||||
|
@ -33,5 +33,6 @@ RUN ssh-keygen -q -t rsa -b 4096 -f $HOME/.ssh/id_rsa
|
|||
ENV GOPATH /go
|
||||
ENV PATH /usr/local/go/bin:$GOPATH/bin:$PATH
|
||||
RUN /bin/bash -c "curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh"
|
||||
RUN terraform init
|
||||
|
||||
RUN ["bundle", "install", "--gemfile", "./Gemfile"]
|
||||
|
|
2
Gemfile
2
Gemfile
|
@ -4,6 +4,6 @@ source 'https://rubygems.org/'
|
|||
|
||||
group :test do
|
||||
git 'https://github.com/Azure/terramodtest.git' do
|
||||
gem 'terramodtest', :tag => 'v0.2.0'
|
||||
gem 'terramodtest', :tag => 'v0.3.0'
|
||||
end
|
||||
end
|
||||
|
|
232
main.tf
232
main.tf
|
@ -8,63 +8,63 @@ provider "random" {
|
|||
|
||||
module "os" {
|
||||
source = "./os"
|
||||
vm_os_simple = "${var.vm_os_simple}"
|
||||
vm_os_simple = var.vm_os_simple
|
||||
}
|
||||
|
||||
resource "azurerm_resource_group" "vm" {
|
||||
name = "${var.resource_group_name}"
|
||||
location = "${var.location}"
|
||||
tags = "${var.tags}"
|
||||
name = var.resource_group_name
|
||||
location = var.location
|
||||
tags = var.tags
|
||||
}
|
||||
|
||||
resource "random_id" "vm-sa" {
|
||||
keepers = {
|
||||
vm_hostname = "${var.vm_hostname}"
|
||||
vm_hostname = var.vm_hostname
|
||||
}
|
||||
|
||||
byte_length = 6
|
||||
}
|
||||
|
||||
resource "azurerm_storage_account" "vm-sa" {
|
||||
count = "${var.boot_diagnostics == "true" ? 1 : 0}"
|
||||
count = var.boot_diagnostics ? 1 : 0
|
||||
name = "bootdiag${lower(random_id.vm-sa.hex)}"
|
||||
resource_group_name = "${azurerm_resource_group.vm.name}"
|
||||
location = "${var.location}"
|
||||
account_tier = "${element(split("_", var.boot_diagnostics_sa_type),0)}"
|
||||
account_replication_type = "${element(split("_", var.boot_diagnostics_sa_type),1)}"
|
||||
tags = "${var.tags}"
|
||||
resource_group_name = azurerm_resource_group.vm.name
|
||||
location = var.location
|
||||
account_tier = element(split("_", var.boot_diagnostics_sa_type), 0)
|
||||
account_replication_type = element(split("_", var.boot_diagnostics_sa_type), 1)
|
||||
tags = var.tags
|
||||
}
|
||||
|
||||
resource "azurerm_virtual_machine" "vm-linux" {
|
||||
count = "${!contains(list("${var.vm_os_simple}","${var.vm_os_offer}"), "Windows") && var.is_windows_image != "true" && var.data_disk == "false" ? var.nb_instances : 0}"
|
||||
count = ! contains(list(var.vm_os_simple, var.vm_os_offer), "Windows") && ! var.is_windows_image && ! var.data_disk ? var.nb_instances : 0
|
||||
name = "${var.vm_hostname}${count.index}"
|
||||
location = "${var.location}"
|
||||
resource_group_name = "${azurerm_resource_group.vm.name}"
|
||||
availability_set_id = "${azurerm_availability_set.vm.id}"
|
||||
vm_size = "${var.vm_size}"
|
||||
network_interface_ids = ["${element(azurerm_network_interface.vm.*.id, count.index)}"]
|
||||
delete_os_disk_on_termination = "${var.delete_os_disk_on_termination}"
|
||||
location = var.location
|
||||
resource_group_name = azurerm_resource_group.vm.name
|
||||
availability_set_id = azurerm_availability_set.vm.id
|
||||
vm_size = var.vm_size
|
||||
network_interface_ids = [element(azurerm_network_interface.vm.*.id, count.index)]
|
||||
delete_os_disk_on_termination = var.delete_os_disk_on_termination
|
||||
|
||||
storage_image_reference {
|
||||
id = "${var.vm_os_id}"
|
||||
publisher = "${var.vm_os_id == "" ? coalesce(var.vm_os_publisher, module.os.calculated_value_os_publisher) : ""}"
|
||||
offer = "${var.vm_os_id == "" ? coalesce(var.vm_os_offer, module.os.calculated_value_os_offer) : ""}"
|
||||
sku = "${var.vm_os_id == "" ? coalesce(var.vm_os_sku, module.os.calculated_value_os_sku) : ""}"
|
||||
version = "${var.vm_os_id == "" ? var.vm_os_version : ""}"
|
||||
id = var.vm_os_id
|
||||
publisher = var.vm_os_id == "" ? coalesce(var.vm_os_publisher, module.os.calculated_value_os_publisher) : ""
|
||||
offer = var.vm_os_id == "" ? coalesce(var.vm_os_offer, module.os.calculated_value_os_offer) : ""
|
||||
sku = var.vm_os_id == "" ? coalesce(var.vm_os_sku, module.os.calculated_value_os_sku) : ""
|
||||
version = var.vm_os_id == "" ? var.vm_os_version : ""
|
||||
}
|
||||
|
||||
storage_os_disk {
|
||||
name = "osdisk-${var.vm_hostname}-${count.index}"
|
||||
create_option = "FromImage"
|
||||
caching = "ReadWrite"
|
||||
managed_disk_type = "${var.storage_account_type}"
|
||||
managed_disk_type = var.storage_account_type
|
||||
}
|
||||
|
||||
os_profile {
|
||||
computer_name = "${var.vm_hostname}${count.index}"
|
||||
admin_username = "${var.admin_username}"
|
||||
admin_password = "${var.admin_password}"
|
||||
custom_data = "${var.custom_data}"
|
||||
admin_username = var.admin_username
|
||||
admin_password = var.admin_password
|
||||
custom_data = var.custom_data
|
||||
}
|
||||
|
||||
os_profile_linux_config {
|
||||
|
@ -72,56 +72,56 @@ resource "azurerm_virtual_machine" "vm-linux" {
|
|||
|
||||
ssh_keys {
|
||||
path = "/home/${var.admin_username}/.ssh/authorized_keys"
|
||||
key_data = "${file("${var.ssh_key}")}"
|
||||
key_data = file(var.ssh_key)
|
||||
}
|
||||
}
|
||||
|
||||
tags = "${var.tags}"
|
||||
tags = var.tags
|
||||
|
||||
boot_diagnostics {
|
||||
enabled = "${var.boot_diagnostics}"
|
||||
storage_uri = "${var.boot_diagnostics == "true" ? join(",", azurerm_storage_account.vm-sa.*.primary_blob_endpoint) : "" }"
|
||||
enabled = var.boot_diagnostics
|
||||
storage_uri = var.boot_diagnostics ? join(",", azurerm_storage_account.vm-sa.*.primary_blob_endpoint) : ""
|
||||
}
|
||||
}
|
||||
|
||||
resource "azurerm_virtual_machine" "vm-linux-with-datadisk" {
|
||||
count = "${!contains(list("${var.vm_os_simple}","${var.vm_os_offer}"), "Windows") && var.is_windows_image != "true" && var.data_disk == "true" ? var.nb_instances : 0}"
|
||||
count = ! contains(list(var.vm_os_simple, var.vm_os_offer), "Windows") && ! var.is_windows_image && var.data_disk ? var.nb_instances : 0
|
||||
name = "${var.vm_hostname}${count.index}"
|
||||
location = "${var.location}"
|
||||
resource_group_name = "${azurerm_resource_group.vm.name}"
|
||||
availability_set_id = "${azurerm_availability_set.vm.id}"
|
||||
vm_size = "${var.vm_size}"
|
||||
network_interface_ids = ["${element(azurerm_network_interface.vm.*.id, count.index)}"]
|
||||
delete_os_disk_on_termination = "${var.delete_os_disk_on_termination}"
|
||||
location = var.location
|
||||
resource_group_name = azurerm_resource_group.vm.name
|
||||
availability_set_id = azurerm_availability_set.vm.id
|
||||
vm_size = var.vm_size
|
||||
network_interface_ids = [element(azurerm_network_interface.vm.*.id, count.index)]
|
||||
delete_os_disk_on_termination = var.delete_os_disk_on_termination
|
||||
|
||||
storage_image_reference {
|
||||
id = "${var.vm_os_id}"
|
||||
publisher = "${var.vm_os_id == "" ? coalesce(var.vm_os_publisher, module.os.calculated_value_os_publisher) : ""}"
|
||||
offer = "${var.vm_os_id == "" ? coalesce(var.vm_os_offer, module.os.calculated_value_os_offer) : ""}"
|
||||
sku = "${var.vm_os_id == "" ? coalesce(var.vm_os_sku, module.os.calculated_value_os_sku) : ""}"
|
||||
version = "${var.vm_os_id == "" ? var.vm_os_version : ""}"
|
||||
id = var.vm_os_id
|
||||
publisher = var.vm_os_id == "" ? coalesce(var.vm_os_publisher, module.os.calculated_value_os_publisher) : ""
|
||||
offer = var.vm_os_id == "" ? coalesce(var.vm_os_offer, module.os.calculated_value_os_offer) : ""
|
||||
sku = var.vm_os_id == "" ? coalesce(var.vm_os_sku, module.os.calculated_value_os_sku) : ""
|
||||
version = var.vm_os_id == "" ? var.vm_os_version : ""
|
||||
}
|
||||
|
||||
storage_os_disk {
|
||||
name = "osdisk-${var.vm_hostname}-${count.index}"
|
||||
create_option = "FromImage"
|
||||
caching = "ReadWrite"
|
||||
managed_disk_type = "${var.storage_account_type}"
|
||||
managed_disk_type = var.storage_account_type
|
||||
}
|
||||
|
||||
storage_data_disk {
|
||||
name = "datadisk-${var.vm_hostname}-${count.index}"
|
||||
create_option = "Empty"
|
||||
lun = 0
|
||||
disk_size_gb = "${var.data_disk_size_gb}"
|
||||
managed_disk_type = "${var.data_sa_type}"
|
||||
disk_size_gb = var.data_disk_size_gb
|
||||
managed_disk_type = var.data_sa_type
|
||||
}
|
||||
|
||||
os_profile {
|
||||
computer_name = "${var.vm_hostname}${count.index}"
|
||||
admin_username = "${var.admin_username}"
|
||||
admin_password = "${var.admin_password}"
|
||||
custom_data = "${var.custom_data}"
|
||||
admin_username = var.admin_username
|
||||
admin_password = var.admin_password
|
||||
custom_data = var.custom_data
|
||||
}
|
||||
|
||||
os_profile_linux_config {
|
||||
|
@ -129,169 +129,169 @@ resource "azurerm_virtual_machine" "vm-linux-with-datadisk" {
|
|||
|
||||
ssh_keys {
|
||||
path = "/home/${var.admin_username}/.ssh/authorized_keys"
|
||||
key_data = "${file("${var.ssh_key}")}"
|
||||
key_data = file(var.ssh_key)
|
||||
}
|
||||
}
|
||||
|
||||
tags = "${var.tags}"
|
||||
tags = var.tags
|
||||
|
||||
boot_diagnostics {
|
||||
enabled = "${var.boot_diagnostics}"
|
||||
storage_uri = "${var.boot_diagnostics == "true" ? join(",", azurerm_storage_account.vm-sa.*.primary_blob_endpoint) : "" }"
|
||||
enabled = var.boot_diagnostics
|
||||
storage_uri = var.boot_diagnostics ? join(",", azurerm_storage_account.vm-sa.*.primary_blob_endpoint) : ""
|
||||
}
|
||||
}
|
||||
|
||||
resource "azurerm_virtual_machine" "vm-windows" {
|
||||
count = "${((var.is_windows_image == "true" || contains(list("${var.vm_os_simple}","${var.vm_os_offer}"), "Windows")) && var.data_disk == "false") ? var.nb_instances : 0}"
|
||||
count = ((var.is_windows_image || contains(list(var.vm_os_simple, var.vm_os_offer), "Windows")) && ! var.data_disk) ? var.nb_instances : 0
|
||||
name = "${var.vm_hostname}${count.index}"
|
||||
location = "${var.location}"
|
||||
resource_group_name = "${azurerm_resource_group.vm.name}"
|
||||
availability_set_id = "${azurerm_availability_set.vm.id}"
|
||||
vm_size = "${var.vm_size}"
|
||||
network_interface_ids = ["${element(azurerm_network_interface.vm.*.id, count.index)}"]
|
||||
delete_os_disk_on_termination = "${var.delete_os_disk_on_termination}"
|
||||
location = var.location
|
||||
resource_group_name = azurerm_resource_group.vm.name
|
||||
availability_set_id = azurerm_availability_set.vm.id
|
||||
vm_size = var.vm_size
|
||||
network_interface_ids = [element(azurerm_network_interface.vm.*.id, count.index)]
|
||||
delete_os_disk_on_termination = var.delete_os_disk_on_termination
|
||||
|
||||
storage_image_reference {
|
||||
id = "${var.vm_os_id}"
|
||||
publisher = "${var.vm_os_id == "" ? coalesce(var.vm_os_publisher, module.os.calculated_value_os_publisher) : ""}"
|
||||
offer = "${var.vm_os_id == "" ? coalesce(var.vm_os_offer, module.os.calculated_value_os_offer) : ""}"
|
||||
sku = "${var.vm_os_id == "" ? coalesce(var.vm_os_sku, module.os.calculated_value_os_sku) : ""}"
|
||||
version = "${var.vm_os_id == "" ? var.vm_os_version : ""}"
|
||||
id = var.vm_os_id
|
||||
publisher = var.vm_os_id == "" ? coalesce(var.vm_os_publisher, module.os.calculated_value_os_publisher) : ""
|
||||
offer = var.vm_os_id == "" ? coalesce(var.vm_os_offer, module.os.calculated_value_os_offer) : ""
|
||||
sku = var.vm_os_id == "" ? coalesce(var.vm_os_sku, module.os.calculated_value_os_sku) : ""
|
||||
version = var.vm_os_id == "" ? var.vm_os_version : ""
|
||||
}
|
||||
|
||||
storage_os_disk {
|
||||
name = "osdisk-${var.vm_hostname}-${count.index}"
|
||||
create_option = "FromImage"
|
||||
caching = "ReadWrite"
|
||||
managed_disk_type = "${var.storage_account_type}"
|
||||
managed_disk_type = var.storage_account_type
|
||||
}
|
||||
|
||||
os_profile {
|
||||
computer_name = "${var.vm_hostname}${count.index}"
|
||||
admin_username = "${var.admin_username}"
|
||||
admin_password = "${var.admin_password}"
|
||||
admin_username = var.admin_username
|
||||
admin_password = var.admin_password
|
||||
}
|
||||
|
||||
tags = "${var.tags}"
|
||||
tags = var.tags
|
||||
|
||||
os_profile_windows_config {
|
||||
provision_vm_agent = true
|
||||
}
|
||||
|
||||
boot_diagnostics {
|
||||
enabled = "${var.boot_diagnostics}"
|
||||
storage_uri = "${var.boot_diagnostics == "true" ? join(",", azurerm_storage_account.vm-sa.*.primary_blob_endpoint) : "" }"
|
||||
enabled = var.boot_diagnostics
|
||||
storage_uri = var.boot_diagnostics ? join(",", azurerm_storage_account.vm-sa.*.primary_blob_endpoint) : ""
|
||||
}
|
||||
}
|
||||
|
||||
resource "azurerm_virtual_machine" "vm-windows-with-datadisk" {
|
||||
count = "${(var.is_windows_image == "true" || contains(list("${var.vm_os_simple}","${var.vm_os_offer}"), "Windows")) && var.data_disk == "true" ? var.nb_instances : 0}"
|
||||
count = (var.is_windows_image || contains(list(var.vm_os_simple, var.vm_os_offer), "Windows")) && var.data_disk ? var.nb_instances : 0
|
||||
name = "${var.vm_hostname}${count.index}"
|
||||
location = "${var.location}"
|
||||
resource_group_name = "${azurerm_resource_group.vm.name}"
|
||||
availability_set_id = "${azurerm_availability_set.vm.id}"
|
||||
vm_size = "${var.vm_size}"
|
||||
network_interface_ids = ["${element(azurerm_network_interface.vm.*.id, count.index)}"]
|
||||
delete_os_disk_on_termination = "${var.delete_os_disk_on_termination}"
|
||||
location = var.location
|
||||
resource_group_name = azurerm_resource_group.vm.name
|
||||
availability_set_id = azurerm_availability_set.vm.id
|
||||
vm_size = var.vm_size
|
||||
network_interface_ids = [element(azurerm_network_interface.vm.*.id, count.index)]
|
||||
delete_os_disk_on_termination = var.delete_os_disk_on_termination
|
||||
|
||||
storage_image_reference {
|
||||
id = "${var.vm_os_id}"
|
||||
publisher = "${var.vm_os_id == "" ? coalesce(var.vm_os_publisher, module.os.calculated_value_os_publisher) : ""}"
|
||||
offer = "${var.vm_os_id == "" ? coalesce(var.vm_os_offer, module.os.calculated_value_os_offer) : ""}"
|
||||
sku = "${var.vm_os_id == "" ? coalesce(var.vm_os_sku, module.os.calculated_value_os_sku) : ""}"
|
||||
version = "${var.vm_os_id == "" ? var.vm_os_version : ""}"
|
||||
id = var.vm_os_id
|
||||
publisher = var.vm_os_id == "" ? coalesce(var.vm_os_publisher, module.os.calculated_value_os_publisher) : ""
|
||||
offer = var.vm_os_id == "" ? coalesce(var.vm_os_offer, module.os.calculated_value_os_offer) : ""
|
||||
sku = var.vm_os_id == "" ? coalesce(var.vm_os_sku, module.os.calculated_value_os_sku) : ""
|
||||
version = var.vm_os_id == "" ? var.vm_os_version : ""
|
||||
}
|
||||
|
||||
storage_os_disk {
|
||||
name = "osdisk-${var.vm_hostname}-${count.index}"
|
||||
create_option = "FromImage"
|
||||
caching = "ReadWrite"
|
||||
managed_disk_type = "${var.storage_account_type}"
|
||||
managed_disk_type = var.storage_account_type
|
||||
}
|
||||
|
||||
storage_data_disk {
|
||||
name = "datadisk-${var.vm_hostname}-${count.index}"
|
||||
create_option = "Empty"
|
||||
lun = 0
|
||||
disk_size_gb = "${var.data_disk_size_gb}"
|
||||
managed_disk_type = "${var.data_sa_type}"
|
||||
disk_size_gb = var.data_disk_size_gb
|
||||
managed_disk_type = var.data_sa_type
|
||||
}
|
||||
|
||||
os_profile {
|
||||
computer_name = "${var.vm_hostname}${count.index}"
|
||||
admin_username = "${var.admin_username}"
|
||||
admin_password = "${var.admin_password}"
|
||||
admin_username = var.admin_username
|
||||
admin_password = var.admin_password
|
||||
}
|
||||
|
||||
tags = "${var.tags}"
|
||||
tags = var.tags
|
||||
|
||||
os_profile_windows_config {
|
||||
provision_vm_agent = true
|
||||
}
|
||||
|
||||
boot_diagnostics {
|
||||
enabled = "${var.boot_diagnostics}"
|
||||
storage_uri = "${var.boot_diagnostics == "true" ? join(",", azurerm_storage_account.vm-sa.*.primary_blob_endpoint) : "" }"
|
||||
enabled = var.boot_diagnostics
|
||||
storage_uri = var.boot_diagnostics ? join(",", azurerm_storage_account.vm-sa.*.primary_blob_endpoint) : ""
|
||||
}
|
||||
}
|
||||
|
||||
resource "azurerm_availability_set" "vm" {
|
||||
name = "${var.vm_hostname}-avset"
|
||||
location = "${azurerm_resource_group.vm.location}"
|
||||
resource_group_name = "${azurerm_resource_group.vm.name}"
|
||||
location = azurerm_resource_group.vm.location
|
||||
resource_group_name = azurerm_resource_group.vm.name
|
||||
platform_fault_domain_count = 2
|
||||
platform_update_domain_count = 2
|
||||
managed = true
|
||||
tags = "${var.tags}"
|
||||
tags = var.tags
|
||||
}
|
||||
|
||||
resource "azurerm_public_ip" "vm" {
|
||||
count = "${var.nb_public_ip}"
|
||||
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 = "${element(var.public_ip_dns, count.index)}"
|
||||
tags = "${var.tags}"
|
||||
location = var.location
|
||||
resource_group_name = azurerm_resource_group.vm.name
|
||||
allocation_method = coalesce(var.allocation_method, var.public_ip_address_allocation, "Dynamic")
|
||||
domain_name_label = element(var.public_ip_dns, count.index)
|
||||
tags = var.tags
|
||||
}
|
||||
|
||||
resource "azurerm_network_security_group" "vm" {
|
||||
name = "${var.vm_hostname}-${coalesce(var.remote_port,module.os.calculated_remote_port)}-nsg"
|
||||
location = "${azurerm_resource_group.vm.location}"
|
||||
resource_group_name = "${azurerm_resource_group.vm.name}"
|
||||
name = "${var.vm_hostname}-${coalesce(var.remote_port, module.os.calculated_remote_port)}-nsg"
|
||||
location = azurerm_resource_group.vm.location
|
||||
resource_group_name = azurerm_resource_group.vm.name
|
||||
|
||||
tags = "${var.tags}"
|
||||
tags = var.tags
|
||||
}
|
||||
|
||||
resource "azurerm_network_security_rule" "vm" {
|
||||
name = "allow_remote_${coalesce(var.remote_port,module.os.calculated_remote_port)}_in_all"
|
||||
name = "allow_remote_${coalesce(var.remote_port, module.os.calculated_remote_port)}_in_all"
|
||||
description = "Allow remote protocol in from all locations"
|
||||
priority = 100
|
||||
direction = "Inbound"
|
||||
access = "Allow"
|
||||
protocol = "Tcp"
|
||||
source_port_range = "*"
|
||||
destination_port_range = "${coalesce(var.remote_port,module.os.calculated_remote_port)}"
|
||||
destination_port_range = coalesce(var.remote_port, module.os.calculated_remote_port)
|
||||
source_address_prefix = "*"
|
||||
destination_address_prefix = "*"
|
||||
resource_group_name = "${azurerm_resource_group.vm.name}"
|
||||
network_security_group_name = "${azurerm_network_security_group.vm.name}"
|
||||
resource_group_name = azurerm_resource_group.vm.name
|
||||
network_security_group_name = azurerm_network_security_group.vm.name
|
||||
}
|
||||
|
||||
resource "azurerm_network_interface" "vm" {
|
||||
count = "${var.nb_instances}"
|
||||
count = var.nb_instances
|
||||
name = "nic-${var.vm_hostname}-${count.index}"
|
||||
location = "${azurerm_resource_group.vm.location}"
|
||||
resource_group_name = "${azurerm_resource_group.vm.name}"
|
||||
network_security_group_id = "${azurerm_network_security_group.vm.id}"
|
||||
enable_accelerated_networking = "${var.enable_accelerated_networking}"
|
||||
location = azurerm_resource_group.vm.location
|
||||
resource_group_name = azurerm_resource_group.vm.name
|
||||
network_security_group_id = azurerm_network_security_group.vm.id
|
||||
enable_accelerated_networking = var.enable_accelerated_networking
|
||||
|
||||
ip_configuration {
|
||||
name = "ipconfig${count.index}"
|
||||
subnet_id = "${var.vnet_subnet_id}"
|
||||
subnet_id = var.vnet_subnet_id
|
||||
private_ip_address_allocation = "Dynamic"
|
||||
public_ip_address_id = "${length(azurerm_public_ip.vm.*.id) > 0 ? element(concat(azurerm_public_ip.vm.*.id, list("")), count.index) : ""}"
|
||||
public_ip_address_id = length(azurerm_public_ip.vm.*.id) > 0 ? element(concat(azurerm_public_ip.vm.*.id, list("")), count.index) : ""
|
||||
}
|
||||
|
||||
tags = "${var.tags}"
|
||||
tags = var.tags
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
output "vm_ids" {
|
||||
description = "Virtual machine ids created."
|
||||
value = "${concat(azurerm_virtual_machine.vm-windows.*.id,azurerm_virtual_machine.vm-windows-with-datadisk.*.id, azurerm_virtual_machine.vm-linux.*.id,azurerm_virtual_machine.vm-linux-with-datadisk.*.id)}"
|
||||
value = "${concat(azurerm_virtual_machine.vm-windows.*.id, azurerm_virtual_machine.vm-windows-with-datadisk.*.id, azurerm_virtual_machine.vm-linux.*.id, azurerm_virtual_machine.vm-linux-with-datadisk.*.id)}"
|
||||
}
|
||||
|
||||
output "network_security_group_id" {
|
||||
|
|
|
@ -1,44 +1,41 @@
|
|||
provider "random" {
|
||||
version = "~> 1.0"
|
||||
}
|
||||
|
||||
resource "random_id" "ip_dns" {
|
||||
byte_length = 8
|
||||
}
|
||||
|
||||
module "ubuntuservers" {
|
||||
source = "../../"
|
||||
location = "${var.location}"
|
||||
admin_username = "${var.admin_username}"
|
||||
admin_password = "${var.admin_password}"
|
||||
vm_os_simple = "${var.vm_os_simple_1}"
|
||||
location = var.location
|
||||
admin_username = var.admin_username
|
||||
admin_password = var.admin_password
|
||||
vm_os_simple = var.vm_os_simple_1
|
||||
public_ip_dns = ["ubuntusimplevmips-${random_id.ip_dns.hex}"]
|
||||
vnet_subnet_id = "${module.network.vnet_subnets[0]}"
|
||||
ssh_key = "${var.ssh_key}"
|
||||
vnet_subnet_id = module.network.vnet_subnets[0]
|
||||
ssh_key = var.ssh_key
|
||||
resource_group_name = "${var.resource_group_name}-${random_id.ip_dns.hex}"
|
||||
public_ip_address_allocation = "static"
|
||||
allocation_method = "Static"
|
||||
enable_accelerated_networking = "true"
|
||||
vm_size = "Standard_DS2_V2"
|
||||
}
|
||||
|
||||
module "debianservers" {
|
||||
source = "../../"
|
||||
location = "${var.location}"
|
||||
location = var.location
|
||||
vm_hostname = "mylinvm"
|
||||
admin_username = "${var.admin_username}"
|
||||
admin_password = "${var.admin_password}"
|
||||
custom_data = "${var.custom_data}"
|
||||
vm_os_simple = "${var.vm_os_simple_2}"
|
||||
admin_username = var.admin_username
|
||||
admin_password = var.admin_password
|
||||
custom_data = var.custom_data
|
||||
vm_os_simple = var.vm_os_simple_2
|
||||
public_ip_dns = ["debiansimplevmips-${random_id.ip_dns.hex}"] // change to a unique name per datacenter region
|
||||
vnet_subnet_id = "${module.network.vnet_subnets[0]}"
|
||||
ssh_key = "${var.ssh_key}"
|
||||
vnet_subnet_id = module.network.vnet_subnets[0]
|
||||
ssh_key = var.ssh_key
|
||||
resource_group_name = "${var.resource_group_name}-${random_id.ip_dns.hex}"
|
||||
public_ip_address_allocation = "static"
|
||||
allocation_method = "Static"
|
||||
}
|
||||
|
||||
module "network" {
|
||||
source = "Azure/network/azurerm"
|
||||
version = "2.0.0"
|
||||
location = "westus2"
|
||||
subnet_names = ["subnet1"]
|
||||
resource_group_name = "${var.resource_group_name}-${random_id.ip_dns.hex}"
|
||||
}
|
|
@ -1,15 +1,7 @@
|
|||
package test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/gruntwork-io/terratest/modules/retry"
|
||||
"github.com/gruntwork-io/terratest/modules/ssh"
|
||||
"github.com/gruntwork-io/terratest/modules/terraform"
|
||||
"github.com/gruntwork-io/terratest/modules/test-structure"
|
||||
)
|
||||
|
@ -36,14 +28,9 @@ func TestTerraformSshExample(t *testing.T) {
|
|||
terraform.InitAndApply(t, terraformOptions)
|
||||
})
|
||||
|
||||
// Make sure we can SSH to virtual machines directly from the public Internet
|
||||
test_structure.RunTestStage(t, "validate", func() {
|
||||
terraformOptions := test_structure.LoadTerraformOptions(t, exampleFolder)
|
||||
|
||||
testSSHToPublicHost(t, terraformOptions, "ubuntu_ip_address")
|
||||
testSSHToPublicHost(t, terraformOptions, "debian_ip_address")
|
||||
})
|
||||
|
||||
// It has ever been planned to test the VM could be accessed from the public through SSH,
|
||||
// however currently this connection is constrained because the testing VM in CI is within the Microsoft internal environment and the public cannot access it.
|
||||
// So skip this test.
|
||||
}
|
||||
|
||||
func configureTerraformOptions(t *testing.T, exampleFolder string) *terraform.Options {
|
||||
|
@ -59,47 +46,3 @@ func configureTerraformOptions(t *testing.T, exampleFolder string) *terraform.Op
|
|||
return terraformOptions
|
||||
}
|
||||
|
||||
func testSSHToPublicHost(t *testing.T, terraformOptions *terraform.Options, address string) {
|
||||
// Run `terraform output` to get the value of an output variable
|
||||
publicIP := terraform.Output(t, terraformOptions, address)
|
||||
|
||||
// Read private key from given file
|
||||
buffer, err := ioutil.ReadFile(os.Args[len(os.Args)-1])
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
keyPair := ssh.KeyPair{PrivateKey: string(buffer)}
|
||||
|
||||
// We're going to try to SSH to the virtual machine, using our local key pair and specific username
|
||||
publicHost := ssh.Host{
|
||||
Hostname: publicIP,
|
||||
SshKeyPair: &keyPair,
|
||||
SshUserName: os.Args[len(os.Args)-2],
|
||||
}
|
||||
|
||||
// It can take a minute or so for the virtual machine to boot up, so retry a few times
|
||||
maxRetries := 15
|
||||
timeBetweenRetries := 5 * time.Second
|
||||
description := fmt.Sprintf("SSH to public host %s", publicIP)
|
||||
|
||||
// Run a simple echo command on the server
|
||||
expectedText := "Hello, World"
|
||||
command := fmt.Sprintf("echo -n '%s'", expectedText)
|
||||
|
||||
// Verify that we can SSH to the virtual machine and run commands
|
||||
retry.DoWithRetry(t, description, maxRetries, timeBetweenRetries, func() (string, error) {
|
||||
// Run the command and get the output
|
||||
actualText, err := ssh.CheckSshCommandE(t, publicHost, command)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// Check whether the output is correct
|
||||
if strings.TrimSpace(actualText) != expectedText {
|
||||
return "", fmt.Errorf("Expected SSH command to return '%s' but got '%s'", expectedText, actualText)
|
||||
}
|
||||
fmt.Println(actualText)
|
||||
|
||||
return "", nil
|
||||
})
|
||||
}
|
||||
|
|
25
variables.tf
25
variables.tf
|
@ -73,7 +73,7 @@ variable "vm_os_id" {
|
|||
|
||||
variable "is_windows_image" {
|
||||
description = "Boolean flag to notify when the custom image is windows based."
|
||||
default = "false"
|
||||
default = false
|
||||
}
|
||||
|
||||
variable "vm_os_publisher" {
|
||||
|
@ -97,7 +97,7 @@ variable "vm_os_version" {
|
|||
}
|
||||
|
||||
variable "tags" {
|
||||
type = "map"
|
||||
type = map(string)
|
||||
description = "A map of the tags to use on the resources that are deployed with this module."
|
||||
|
||||
default = {
|
||||
|
@ -106,8 +106,13 @@ variable "tags" {
|
|||
}
|
||||
|
||||
variable "public_ip_address_allocation" {
|
||||
description = "This attribute is deprecated, and to be replaced by 'allocation_method'"
|
||||
default = ""
|
||||
}
|
||||
|
||||
variable "allocation_method" {
|
||||
description = "Defines how an IP address is assigned. Options are Static or Dynamic."
|
||||
default = "dynamic"
|
||||
default = ""
|
||||
}
|
||||
|
||||
variable "nb_public_ip" {
|
||||
|
@ -116,8 +121,9 @@ variable "nb_public_ip" {
|
|||
}
|
||||
|
||||
variable "delete_os_disk_on_termination" {
|
||||
type = bool
|
||||
description = "Delete datadisk when machine is terminated"
|
||||
default = "false"
|
||||
default = false
|
||||
}
|
||||
|
||||
variable "data_sa_type" {
|
||||
|
@ -131,14 +137,15 @@ variable "data_disk_size_gb" {
|
|||
}
|
||||
|
||||
variable "data_disk" {
|
||||
type = "string"
|
||||
type = bool
|
||||
description = "Set to true to add a datadisk."
|
||||
default = "false"
|
||||
default = false
|
||||
}
|
||||
|
||||
variable "boot_diagnostics" {
|
||||
type = bool
|
||||
description = "(Optional) Enable or Disable boot diagnostics"
|
||||
default = "false"
|
||||
default = false
|
||||
}
|
||||
|
||||
variable "boot_diagnostics_sa_type" {
|
||||
|
@ -147,7 +154,7 @@ variable "boot_diagnostics_sa_type" {
|
|||
}
|
||||
|
||||
variable "enable_accelerated_networking" {
|
||||
type = "string"
|
||||
type = bool
|
||||
description = "(Optional) Enable accelerated networking on Network interface"
|
||||
default = "false"
|
||||
default = false
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче