Allow custom location and fix issues (#135)

This commit is contained in:
Yuping Wei 2020-06-18 17:17:41 +08:00 коммит произвёл GitHub
Родитель 512b5dbfe9
Коммит f88f65204f
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
8 изменённых файлов: 33 добавлений и 22 удалений

Просмотреть файл

@ -51,12 +51,9 @@ module "windowsservers" {
module "network" {
source = "Azure/network/azurerm"
version = "3.0.0"
resource_group_name = azurerm_resource_group.example.name
allow_rdp_traffic = "true"
allow_ssh_traffic = "true"
subnet_prefixes = ["10.0.1.0/24"]
subnet_names = ["subnet1"]
}
output "linux_vm_public_name" {
@ -153,10 +150,9 @@ module "windowsservers" {
module "network" {
source = "Azure/network/azurerm"
version = "3.0.1"
resource_group_name = azurerm_resource_group.example.name
subnet_prefixes = ["10.0.1.0/24"]
subnet_names = ["subnet1"]
}
output "linux_vm_private_ips" {

18
main.tf
Просмотреть файл

@ -19,17 +19,17 @@ resource "azurerm_storage_account" "vm-sa" {
count = var.boot_diagnostics ? 1 : 0
name = "bootdiag${lower(random_id.vm-sa.hex)}"
resource_group_name = data.azurerm_resource_group.vm.name
location = data.azurerm_resource_group.vm.location
location = coalesce(var.location, data.azurerm_resource_group.vm.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 ? var.nb_instances : 0
count = ! contains(list(var.vm_os_simple, var.vm_os_offer), "WindowsServer") && ! var.is_windows_image ? var.nb_instances : 0
name = "${var.vm_hostname}-vmLinux-${count.index}"
resource_group_name = data.azurerm_resource_group.vm.name
location = data.azurerm_resource_group.vm.location
location = coalesce(var.location, data.azurerm_resource_group.vm.location)
availability_set_id = azurerm_availability_set.vm.id
vm_size = var.vm_size
network_interface_ids = [element(azurerm_network_interface.vm.*.id, count.index)]
@ -89,10 +89,10 @@ resource "azurerm_virtual_machine" "vm-linux" {
}
resource "azurerm_virtual_machine" "vm-windows" {
count = (var.is_windows_image || contains(list(var.vm_os_simple, var.vm_os_offer), "Windows")) ? var.nb_instances : 0
count = (var.is_windows_image || contains(list(var.vm_os_simple, var.vm_os_offer), "WindowsServer")) ? var.nb_instances : 0
name = "${var.vm_hostname}-vmWindows-${count.index}"
resource_group_name = data.azurerm_resource_group.vm.name
location = data.azurerm_resource_group.vm.location
location = coalesce(var.location, data.azurerm_resource_group.vm.location)
availability_set_id = azurerm_availability_set.vm.id
vm_size = var.vm_size
network_interface_ids = [element(azurerm_network_interface.vm.*.id, count.index)]
@ -145,7 +145,7 @@ resource "azurerm_virtual_machine" "vm-windows" {
resource "azurerm_availability_set" "vm" {
name = "${var.vm_hostname}-avset"
resource_group_name = data.azurerm_resource_group.vm.name
location = data.azurerm_resource_group.vm.location
location = coalesce(var.location, data.azurerm_resource_group.vm.location)
platform_fault_domain_count = 2
platform_update_domain_count = 2
managed = true
@ -156,7 +156,7 @@ resource "azurerm_public_ip" "vm" {
count = var.nb_public_ip
name = "${var.vm_hostname}-pip-${count.index}"
resource_group_name = data.azurerm_resource_group.vm.name
location = data.azurerm_resource_group.vm.location
location = coalesce(var.location, data.azurerm_resource_group.vm.location)
allocation_method = var.allocation_method
domain_name_label = element(var.public_ip_dns, count.index)
tags = var.tags
@ -165,7 +165,7 @@ resource "azurerm_public_ip" "vm" {
resource "azurerm_network_security_group" "vm" {
name = "${var.vm_hostname}-nsg"
resource_group_name = data.azurerm_resource_group.vm.name
location = data.azurerm_resource_group.vm.location
location = coalesce(var.location, data.azurerm_resource_group.vm.location)
tags = var.tags
}
@ -189,7 +189,7 @@ resource "azurerm_network_interface" "vm" {
count = var.nb_instances
name = "${var.vm_hostname}-nic-${count.index}"
resource_group_name = data.azurerm_resource_group.vm.name
location = data.azurerm_resource_group.vm.location
location = coalesce(var.location, data.azurerm_resource_group.vm.location)
enable_accelerated_networking = var.enable_accelerated_networking
ip_configuration {

Просмотреть файл

@ -5,12 +5,12 @@ variable "vm_os_simple" {
# Definition of the standard OS with "SimpleName" = "publisher,offer,sku"
variable "standard_os" {
default = {
"UbuntuServer" = "Canonical,UbuntuServer,16.04-LTS"
"WindowsServer" = "MicrosoftWindowsServer,WindowsServer,2016-Datacenter"
"RHEL" = "RedHat,RHEL,7.5"
"openSUSE-Leap" = "SUSE,openSUSE-Leap,42.2"
"UbuntuServer" = "Canonical,UbuntuServer,18.04-LTS"
"WindowsServer" = "MicrosoftWindowsServer,WindowsServer,2019-Datacenter"
"RHEL" = "RedHat,RHEL,8.2"
"openSUSE-Leap" = "SUSE,openSUSE-Leap,15.1"
"CentOS" = "OpenLogic,CentOS,7.6"
"Debian" = "credativ,Debian,8"
"Debian" = "credativ,Debian,9"
"CoreOS" = "CoreOS,CoreOS,Stable"
"SLES" = "SUSE,SLES,12-SP2"
}

Просмотреть файл

@ -42,3 +42,8 @@ output "availability_set_id" {
description = "id of the availability set where the vms are provisioned."
value = azurerm_availability_set.vm.id
}
output "vm_zones" {
description = "map with key `Virtual Machine Id`, value `list of the Availability Zone` which the Virtual Machine should be allocated in."
value = zipmap(concat(azurerm_virtual_machine.vm-windows.*.id, azurerm_virtual_machine.vm-linux.*.id), concat(azurerm_virtual_machine.vm-windows.*.zones, azurerm_virtual_machine.vm-linux.*.zones))
}

Просмотреть файл

@ -13,7 +13,7 @@ resource "azurerm_resource_group" "test" {
resource "azurerm_virtual_network" "vnet" {
name = "host${random_id.ip_dns.hex}-vn"
location = var.location
location = var.location_alt
address_space = ["10.0.0.0/16"]
resource_group_name = azurerm_resource_group.test.name
}
@ -43,6 +43,7 @@ module "ubuntuservers" {
source = "../../"
vm_hostname = "${random_id.ip_dns.hex}-u"
resource_group_name = azurerm_resource_group.test.name
location = var.location_alt
admin_username = var.admin_username
admin_password = var.admin_password
vm_os_simple = var.vm_os_simple_1
@ -59,6 +60,7 @@ module "debianservers" {
source = "../../"
vm_hostname = "${random_id.ip_dns.hex}-d"
resource_group_name = azurerm_resource_group.test.name
location = var.location_alt
admin_username = var.admin_username
admin_password = var.admin_password
custom_data = var.custom_data
@ -73,10 +75,11 @@ module "windowsservers" {
source = "../../"
vm_hostname = "${random_id.ip_dns.hex}-w" // line can be removed if only one VM module per resource group
resource_group_name = azurerm_resource_group.test.name
location = var.location_alt
is_windows_image = true
admin_username = var.admin_username
admin_password = var.admin_password
vm_os_simple = "WindowsServer"
public_ip_dns = ["winsimplevmips"] // change to a unique name per datacenter region
public_ip_dns = ["winsimplevmips-${random_id.ip_dns.hex}"] // change to a unique name per datacenter region
vnet_subnet_id = azurerm_subnet.subnet3.id
}

Просмотреть файл

@ -1,4 +1,5 @@
location = "eastus"
location_alt = "eastus2"
vm_os_simple_1 = "UbuntuServer"
vm_os_simple_2 = "Debian"
admin_username = "azureuser"

Просмотреть файл

@ -1,4 +1,5 @@
variable "location" {}
variable "location_alt" {}
variable "vm_os_simple_1" {}
variable "vm_os_simple_2" {}
variable "admin_username" {}

Просмотреть файл

@ -2,6 +2,11 @@ variable "resource_group_name" {
description = "The name of the resource group in which the resources will be created"
}
variable "location" {
description = "(Optional) The location in which the resources will be created"
default = ""
}
variable "vnet_subnet_id" {
description = "The subnet id of the virtual network where the virtual machines will reside."
}