Created
August 17, 2020 05:42
-
-
Save magodo/1eae5a5ac7f7cdcb78fd4b43ece8050c to your computer and use it in GitHub Desktop.
terraform-provider-azurerm-8105
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
provider "azurerm" { | |
version = "=2.22.0" | |
features {} | |
} | |
variable "vm-size" { | |
type = string | |
description = "Preferred VM Size" | |
default = "Standard_E8_v3" | |
} | |
variable "number_of_vms" { | |
type = number | |
description = "Number of VMs to create" | |
default = 1 | |
} | |
variable "nics_per_vm" { | |
type = number | |
description = "Number of NICs to attach to each created VM" | |
default = 2 | |
} | |
resource "azurerm_resource_group" "rg" { | |
name = "test-myrg" | |
location = "eastus2" | |
} | |
resource "azurerm_virtual_network" "vm_network" { | |
name = "my_network" | |
address_space = ["10.0.0.0/16"] | |
location = azurerm_resource_group.rg.location | |
resource_group_name = azurerm_resource_group.rg.name | |
} | |
resource "azurerm_subnet" "vm_subnet" { | |
name = "internal" | |
resource_group_name = azurerm_resource_group.rg.name | |
virtual_network_name = azurerm_virtual_network.vm_network.name | |
address_prefixes = ["10.0.2.0/24"] | |
} | |
resource "azurerm_public_ip" "pip" { | |
count = (var.number_of_vms * var.nics_per_vm) | |
name = "pip-${count.index}" | |
resource_group_name = azurerm_resource_group.rg.name | |
location = azurerm_resource_group.rg.location | |
allocation_method = "Dynamic" | |
} | |
resource "azurerm_network_interface" "sender_ni" { | |
count = (var.number_of_vms * var.nics_per_vm) | |
name = "my-nic-${count.index}" | |
location = azurerm_resource_group.rg.location | |
resource_group_name = azurerm_resource_group.rg.name | |
enable_accelerated_networking = true | |
ip_configuration { | |
name = "internal" | |
subnet_id = azurerm_subnet.vm_subnet.id | |
private_ip_address_allocation = "Dynamic" | |
public_ip_address_id = azurerm_public_ip.pip[count.index].id | |
} | |
} | |
resource "azurerm_linux_virtual_machine" "vm" { | |
count = var.number_of_vms | |
name = "myvm.${count.index}" | |
resource_group_name = azurerm_resource_group.rg.name | |
location = azurerm_resource_group.rg.location | |
size = var.vm-size | |
admin_username = "adminuser" | |
network_interface_ids = slice(azurerm_network_interface.sender_ni[*].id, var.nics_per_vm * count.index, (var.nics_per_vm * count.index) + var.nics_per_vm) | |
admin_ssh_key { | |
username = "adminuser" | |
public_key = file("~/.ssh/id_rsa.pub") | |
} | |
os_disk { | |
caching = "ReadWrite" | |
storage_account_type = "Standard_LRS" | |
} | |
source_image_reference { | |
publisher = "Canonical" | |
offer = "UbuntuServer" | |
sku = "18.04-LTS" | |
version = "latest" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment