Removal of resource group & azurerm 2.0 (#124)

This commit is contained in:
Yuping Wei 2020-03-16 10:53:33 +08:00 коммит произвёл GitHub
Родитель 995219821c
Коммит 80cab6f464
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
9 изменённых файлов: 273 добавлений и 303 удалений

197
README.md
Просмотреть файл

@ -21,41 +21,47 @@ This contains the bare minimum options to be configured for the VM to be provisi
Provisions an Ubuntu Server 16.04-LTS VM and a Windows 2016 Datacenter Server VM using `vm_os_simple` to a new VNet and opens up ports 22 for SSH and 3389 for RDP access via the attached public IP to each VM. All resources are provisioned into the default resource group called `terraform-compute`. The Ubuntu Server will use the ssh key found in the default location `~/.ssh/id_rsa.pub`.
```hcl
module "linuxservers" {
source = "Azure/compute/azurerm"
location = "West US 2"
vm_os_simple = "UbuntuServer"
public_ip_dns = ["linsimplevmips"] // change to a unique name per datacenter region
vnet_subnet_id = "${module.network.vnet_subnets[0]}"
}
resource "azurerm_resource_group" "example" {
name = "example-resources"
location = "West Europe"
}
module "windowsservers" {
source = "Azure/compute/azurerm"
location = "West US 2"
vm_hostname = "mywinvm" // line can be removed if only one VM module per resource group
admin_password = "ComplxP@ssw0rd!"
vm_os_simple = "WindowsServer"
is_windows_image = "true"
public_ip_dns = ["winsimplevmips"] // change to a unique name per datacenter region
vnet_subnet_id = "${module.network.vnet_subnets[0]}"
}
module "linuxservers" {
source = "Azure/compute/azurerm"
resource_group_name = azurerm_resource_group.example.name
vm_os_simple = "UbuntuServer"
public_ip_dns = ["linsimplevmips"] // change to a unique name per datacenter region
vnet_subnet_id = module.network.vnet_subnets[0]
}
module "network" {
source = "Azure/network/azurerm"
version = "~> 1.1.1"
location = "West US 2"
allow_rdp_traffic = "true"
allow_ssh_traffic = "true"
resource_group_name = "terraform-compute"
}
module "windowsservers" {
source = "Azure/compute/azurerm"
resource_group_name = azurerm_resource_group.example.name
is_windows_image = true
vm_hostname = "mywinvm" // line can be removed if only one VM module per resource group
admin_password = "ComplxP@ssw0rd!"
vm_os_simple = "WindowsServer"
public_ip_dns = ["winsimplevmips"] // change to a unique name per datacenter region
vnet_subnet_id = module.network.vnet_subnets[1]
}
output "linux_vm_public_name"{
value = "${module.linuxservers.public_ip_dns_name}"
}
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", "10.0.2.0/24"]
output "windows_vm_public_name"{
value = "${module.windowsservers.public_ip_dns_name}"
}
}
output "linux_vm_public_name" {
value = module.linuxservers.public_ip_dns_name
}
output "windows_vm_public_name" {
value = module.windowsservers.public_ip_dns_name
}
```
## Advanced Usage
@ -80,75 +86,86 @@ More specifically this provisions:
- Two Public IP addresses (one for each VM)
- Opens up port 3389 for RDP access using the password as shown
3 - New features are supported in v3.0.0:
- "nb_data_disk" Number of the data disks attached to each virtual machine
- "enable_ssh_key" Enable ssh key authentication in Linux virtual Machine
```hcl
module "linuxservers" {
source = "Azure/compute/azurerm"
resource_group_name = "terraform-advancedvms"
location = "westus2"
vm_hostname = "mylinuxvm"
nb_public_ip = "0"
remote_port = "22"
nb_instances = "2"
vm_os_publisher = "Canonical"
vm_os_offer = "UbuntuServer"
vm_os_sku = "14.04.2-LTS"
vnet_subnet_id = "${module.network.vnet_subnets[0]}"
boot_diagnostics = "true"
delete_os_disk_on_termination = "true"
data_disk = "true"
data_disk_size_gb = "64"
data_sa_type = "Premium_LRS"
resource "azurerm_resource_group" "example" {
name = "example-resources"
location = "West Europe"
}
tags = {
environment = "dev"
costcenter = "it"
}
module "linuxservers" {
source = "Azure/compute/azurerm"
resource_group_name = azurerm_resource_group.example.name
vm_hostname = "mylinuxvm"
nb_public_ip = 0
remote_port = "22"
nb_instances = 2
vm_os_publisher = "Canonical"
vm_os_offer = "UbuntuServer"
vm_os_sku = "14.04.2-LTS"
vnet_subnet_id = module.network.vnet_subnets[0]
boot_diagnostics = true
delete_os_disk_on_termination = true
nb_data_disk = 2
data_disk_size_gb = 64
data_sa_type = "Premium_LRS"
enable_ssh_key = true
enable_accelerated_networking = "true"
tags = {
environment = "dev"
costcenter = "it"
}
module "windowsservers" {
source = "Azure/compute/azurerm"
resource_group_name = "terraform-advancedvms"
location = "westus2"
vm_hostname = "mywinvm"
admin_password = "ComplxP@ssw0rd!"
public_ip_dns = ["winterravmip", "winterravmip1"]
nb_public_ip = "2"
remote_port = "3389"
nb_instances = "2"
vm_os_publisher = "MicrosoftWindowsServer"
vm_os_offer = "WindowsServer"
vm_os_sku = "2012-R2-Datacenter"
vm_size = "Standard_DS2_V2"
vnet_subnet_id = "${module.network.vnet_subnets[0]}"
enable_accelerated_networking = "true"
}
enable_accelerated_networking = true
}
module "network" {
source = "Azure/network/azurerm"
version = "~> 1.1.1"
location = "westus2"
allow_rdp_traffic = "true"
allow_ssh_traffic = "true"
resource_group_name = "terraform-advancedvms"
}
module "windowsservers" {
source = "Azure/compute/azurerm"
resource_group_name = azurerm_resource_group.example.name
vm_hostname = "mywinvm"
admin_password = "ComplxP@ssw0rd!"
public_ip_dns = ["winterravmip", "winterravmip1"]
nb_public_ip = 2
remote_port = "3389"
nb_instances = 2
vm_os_publisher = "MicrosoftWindowsServer"
vm_os_offer = "WindowsServer"
vm_os_sku = "2012-R2-Datacenter"
vm_size = "Standard_DS2_V2"
vnet_subnet_id = module.network.vnet_subnets[1]
enable_accelerated_networking = true
}
output "linux_vm_private_ips" {
value = "${module.linuxservers.network_interface_private_ip}"
}
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", "10.0.2.0/24"]
output "windows_vm_public_name"{
value = "${module.windowsservers.public_ip_dns_name}"
}
}
output "windows_vm_public_ip" {
value = "${module.windowsservers.public_ip_address}"
}
output "linux_vm_private_ips" {
value = module.linuxservers.network_interface_private_ip
}
output "windows_vm_private_ips" {
value = "${module.windowsservers.network_interface_private_ip}"
}
output "windows_vm_public_name" {
value = module.windowsservers.public_ip_dns_name
}
output "windows_vm_public_ip" {
value = module.windowsservers.public_ip_address
}
output "windows_vm_private_ips" {
value = module.windowsservers.network_interface_private_ip
}
```

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

@ -26,7 +26,7 @@ namespace :integration do
end
end
task :test do
success = system ("go test -v ./test/ -timeout 20m -args azureuser ~/.ssh/id_rsa")
success = system ("go test -v ./test/ -timeout 30m -args azureuser ~/.ssh/id_rsa")
if not success
raise "ERROR: Go test failed!\n".red
end

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

@ -1,20 +1,10 @@
provider "azurerm" {
version = ">= 1.1.0"
}
provider "random" {
version = "~> 2.1"
}
module "os" {
source = "./os"
vm_os_simple = var.vm_os_simple
}
resource "azurerm_resource_group" "vm" {
name = var.resource_group_name
location = var.location
tags = var.tags
data "azurerm_resource_group" "vm" {
name = var.resource_group_name
}
resource "random_id" "vm-sa" {
@ -28,18 +18,18 @@ resource "random_id" "vm-sa" {
resource "azurerm_storage_account" "vm-sa" {
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
resource_group_name = data.azurerm_resource_group.vm.name
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.data_disk ? var.nb_instances : 0
name = "${var.vm_hostname}${count.index}"
location = var.location
resource_group_name = azurerm_resource_group.vm.name
count = ! contains(list(var.vm_os_simple, var.vm_os_offer), "Windows") && ! 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
availability_set_id = azurerm_availability_set.vm.id
vm_size = var.vm_size
network_interface_ids = [element(azurerm_network_interface.vm.*.id, count.index)]
@ -60,76 +50,33 @@ resource "azurerm_virtual_machine" "vm-linux" {
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
}
os_profile_linux_config {
disable_password_authentication = true
ssh_keys {
path = "/home/${var.admin_username}/.ssh/authorized_keys"
key_data = file(var.ssh_key)
dynamic storage_data_disk {
for_each = range(var.nb_data_disk)
content {
name = "${var.vm_hostname}-datadisk-${count.index}-${storage_data_disk.value}"
create_option = "Empty"
lun = storage_data_disk.value
disk_size_gb = var.data_disk_size_gb
managed_disk_type = var.data_sa_type
}
}
tags = var.tags
boot_diagnostics {
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 && 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
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 : ""
}
storage_os_disk {
name = "osdisk-${var.vm_hostname}-${count.index}"
create_option = "FromImage"
caching = "ReadWrite"
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
}
os_profile {
computer_name = "${var.vm_hostname}${count.index}"
computer_name = "myLinux"
admin_username = var.admin_username
admin_password = var.admin_password
custom_data = var.custom_data
}
os_profile_linux_config {
disable_password_authentication = true
disable_password_authentication = var.enable_ssh_key
ssh_keys {
path = "/home/${var.admin_username}/.ssh/authorized_keys"
key_data = file(var.ssh_key)
dynamic ssh_keys {
for_each = var.enable_ssh_key ? [var.ssh_key] : []
content {
path = "/home/${var.admin_username}/.ssh/authorized_keys"
key_data = file(var.ssh_key)
}
}
}
@ -142,10 +89,10 @@ resource "azurerm_virtual_machine" "vm-linux-with-datadisk" {
}
resource "azurerm_virtual_machine" "vm-windows" {
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
count = (var.is_windows_image || contains(list(var.vm_os_simple, var.vm_os_offer), "Windows")) ? 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
availability_set_id = azurerm_availability_set.vm.id
vm_size = var.vm_size
network_interface_ids = [element(azurerm_network_interface.vm.*.id, count.index)]
@ -160,65 +107,25 @@ resource "azurerm_virtual_machine" "vm-windows" {
}
storage_os_disk {
name = "osdisk-${var.vm_hostname}-${count.index}"
name = "${var.vm_hostname}-osdisk-${count.index}"
create_option = "FromImage"
caching = "ReadWrite"
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
}
tags = var.tags
os_profile_windows_config {
provision_vm_agent = true
}
boot_diagnostics {
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 || 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
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 : ""
}
storage_os_disk {
name = "osdisk-${var.vm_hostname}-${count.index}"
create_option = "FromImage"
caching = "ReadWrite"
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
dynamic storage_data_disk {
for_each = range(var.nb_data_disk)
content {
name = "${var.vm_hostname}-datadisk-${count.index}-${storage_data_disk.value}"
create_option = "Empty"
lun = storage_data_disk.value
disk_size_gb = var.data_disk_size_gb
managed_disk_type = var.data_sa_type
}
}
os_profile {
computer_name = "${var.vm_hostname}${count.index}"
computer_name = "myWindows"
admin_username = var.admin_username
admin_password = var.admin_password
}
@ -237,8 +144,8 @@ resource "azurerm_virtual_machine" "vm-windows-with-datadisk" {
resource "azurerm_availability_set" "vm" {
name = "${var.vm_hostname}-avset"
location = azurerm_resource_group.vm.location
resource_group_name = azurerm_resource_group.vm.name
resource_group_name = data.azurerm_resource_group.vm.name
location = data.azurerm_resource_group.vm.location
platform_fault_domain_count = 2
platform_update_domain_count = 2
managed = true
@ -247,24 +154,25 @@ resource "azurerm_availability_set" "vm" {
resource "azurerm_public_ip" "vm" {
count = var.nb_public_ip
name = "${var.vm_hostname}-${count.index}-publicIP"
location = var.location
resource_group_name = azurerm_resource_group.vm.name
allocation_method = coalesce(var.allocation_method, var.public_ip_address_allocation, "Dynamic")
name = "${var.vm_hostname}-pip-${count.index}"
resource_group_name = data.azurerm_resource_group.vm.name
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
}
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}-nsg"
resource_group_name = data.azurerm_resource_group.vm.name
location = data.azurerm_resource_group.vm.location
tags = var.tags
}
resource "azurerm_network_security_rule" "vm" {
name = "allow_remote_${coalesce(var.remote_port, module.os.calculated_remote_port)}_in_all"
resource_group_name = data.azurerm_resource_group.vm.name
description = "Allow remote protocol in from all locations"
priority = 100
direction = "Inbound"
@ -274,24 +182,28 @@ resource "azurerm_network_security_rule" "vm" {
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 "azurerm_network_interface" "vm" {
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
name = "${var.vm_hostname}-nic-${count.index}"
resource_group_name = data.azurerm_resource_group.vm.name
location = data.azurerm_resource_group.vm.location
enable_accelerated_networking = var.enable_accelerated_networking
ip_configuration {
name = "ipconfig${count.index}"
name = "${var.vm_hostname}-ip-${count.index}"
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) : ""
}
tags = var.tags
}
resource "azurerm_network_interface_security_group_association" "test" {
count = var.nb_instances
network_interface_id = azurerm_network_interface.vm[count.index].id
network_security_group_id = azurerm_network_security_group.vm.id
}

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

@ -1,44 +1,44 @@
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-linux.*.id)
}
output "network_security_group_id" {
description = "id of the security group provisioned"
value = "${azurerm_network_security_group.vm.id}"
value = azurerm_network_security_group.vm.id
}
output "network_security_group_name" {
description = "name of the security group provisioned"
value = "${azurerm_network_security_group.vm.name}"
value = azurerm_network_security_group.vm.name
}
output "network_interface_ids" {
description = "ids of the vm nics provisoned."
value = "${azurerm_network_interface.vm.*.id}"
value = azurerm_network_interface.vm.*.id
}
output "network_interface_private_ip" {
description = "private ip addresses of the vm nics"
value = "${azurerm_network_interface.vm.*.private_ip_address}"
value = azurerm_network_interface.vm.*.private_ip_address
}
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" {
description = "id of the availability set where the vms are provisioned."
value = "${azurerm_availability_set.vm.id}"
value = azurerm_availability_set.vm.id
}

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

@ -1,41 +1,82 @@
provider "azurerm" {
features {}
}
resource "random_id" "ip_dns" {
byte_length = 8
}
resource "azurerm_resource_group" "test" {
name = "host${random_id.ip_dns.hex}-rg"
location = var.location
}
resource "azurerm_virtual_network" "vnet" {
name = "host${random_id.ip_dns.hex}-vn"
location = var.location
address_space = ["10.0.0.0/16"]
resource_group_name = azurerm_resource_group.test.name
}
resource "azurerm_subnet" "subnet1" {
name = "host${random_id.ip_dns.hex}-sn-1"
virtual_network_name = azurerm_virtual_network.vnet.name
resource_group_name = azurerm_resource_group.test.name
address_prefix = "10.0.1.0/24"
}
resource "azurerm_subnet" "subnet2" {
name = "host${random_id.ip_dns.hex}-sn-2"
virtual_network_name = azurerm_virtual_network.vnet.name
resource_group_name = azurerm_resource_group.test.name
address_prefix = "10.0.2.0/24"
}
resource "azurerm_subnet" "subnet3" {
name = "host${random_id.ip_dns.hex}-sn-3"
virtual_network_name = azurerm_virtual_network.vnet.name
resource_group_name = azurerm_resource_group.test.name
address_prefix = "10.0.3.0/24"
}
module "ubuntuservers" {
source = "../../"
location = var.location
vm_hostname = "host${random_id.ip_dns.hex}-ubuntu"
resource_group_name = azurerm_resource_group.test.name
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
resource_group_name = "${var.resource_group_name}-${random_id.ip_dns.hex}"
vnet_subnet_id = azurerm_subnet.subnet1.id
allocation_method = "Static"
enable_accelerated_networking = "true"
enable_accelerated_networking = true
vm_size = "Standard_DS2_V2"
nb_data_disk = 2
enable_ssh_key = false
}
module "debianservers" {
source = "../../"
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
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
resource_group_name = "${var.resource_group_name}-${random_id.ip_dns.hex}"
allocation_method = "Static"
source = "../../"
vm_hostname = "host${random_id.ip_dns.hex}-debian"
resource_group_name = azurerm_resource_group.test.name
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 = azurerm_subnet.subnet2.id
allocation_method = "Static"
enable_ssh_key = true
}
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}"
module "windowsservers" {
source = "../../"
vm_hostname = "host${random_id.ip_dns.hex}-windows" // line can be removed if only one VM module per resource group
resource_group_name = azurerm_resource_group.test.name
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
vnet_subnet_id = azurerm_subnet.subnet3.id
}

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

@ -1,15 +1,23 @@
output "ubuntu_vm_public_name" {
value = "${module.ubuntuservers.public_ip_dns_name}"
value = module.ubuntuservers.public_ip_dns_name
}
output "debian_vm_public_name" {
value = "${module.debianservers.public_ip_dns_name}"
value = module.debianservers.public_ip_dns_name
}
output "windows_vm_public_name" {
value = module.windowsservers.public_ip_dns_name
}
output "ubuntu_ip_address" {
value = "${module.ubuntuservers.public_ip_address}"
value = module.ubuntuservers.public_ip_address
}
output "debian_ip_address" {
value = "${module.debianservers.public_ip_address}"
value = module.debianservers.public_ip_address
}
output "windows_ip_address" {
value = module.windowsservers.public_ip_address
}

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

@ -1,8 +1,6 @@
location = "westus2"
ssh_key = "~/.ssh/id_rsa.pub"
resource_group_name = "terraform-compute"
vm_os_simple_1 = "UbuntuServer"
vm_os_simple_2 = "Debian"
admin_username = "azureuser"
admin_password = "P@ssw0rd12345!"
custom_data = ""
location = "eastus"
vm_os_simple_1 = "UbuntuServer"
vm_os_simple_2 = "Debian"
admin_username = "azureuser"
admin_password = "P@ssw0rd12345!"
custom_data = ""

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

@ -1,6 +1,4 @@
variable "location" {}
variable "ssh_key" {}
variable "resource_group_name" {}
variable "vm_os_simple_1" {}
variable "vm_os_simple_2" {}
variable "admin_username" {}

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

@ -1,10 +1,5 @@
variable "resource_group_name" {
description = "The name of the resource group in which the resources will be created"
default = "terraform-compute"
}
variable "location" {
description = "The location/region where the virtual network is created. Changing this forces a new resource to be created."
}
variable "vnet_subnet_id" {
@ -48,7 +43,7 @@ variable "storage_account_type" {
variable "vm_size" {
description = "Specifies the size of the virtual machine."
default = "Standard_DS1_V2"
default = "Standard_D2s_v3"
}
variable "nb_instances" {
@ -63,6 +58,7 @@ variable "vm_hostname" {
variable "vm_os_simple" {
description = "Specify UbuntuServer, WindowsServer, RHEL, openSUSE-Leap, CentOS, Debian, CoreOS and SLES to get the latest image version of the specified os. Do not provide this value if a custom value is used for vm_os_publisher, vm_os_offer, and vm_os_sku."
type = string
default = ""
}
@ -105,14 +101,9 @@ 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 = ""
default = "Dynamic"
}
variable "nb_public_ip" {
@ -133,13 +124,7 @@ variable "data_sa_type" {
variable "data_disk_size_gb" {
description = "Storage data disk size size"
default = ""
}
variable "data_disk" {
type = bool
description = "Set to true to add a datadisk."
default = false
default = 30
}
variable "boot_diagnostics" {
@ -158,3 +143,14 @@ variable "enable_accelerated_networking" {
description = "(Optional) Enable accelerated networking on Network interface"
default = false
}
variable "enable_ssh_key" {
type = bool
description = "(Optional) Enable ssh key authentication in Linux virtual Machine"
default = true
}
variable "nb_data_disk" {
description = "(Optional) Number of the data disks attached to each virtual machine"
default = 0
}