Created
June 20, 2018 11:55
-
-
Save rohrerb/cae15f3ea19c6337c5ac0b44ccd1b89e to your computer and use it in GitHub Desktop.
Simple VM Creation File
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
variable "environment_code" { | |
default = "US" | |
} | |
variable "deployment_code" { | |
default = "T" | |
} | |
variable "location_code" { | |
default = "V" | |
} | |
variable "count" { | |
default = 1 | |
} | |
provider "azurerm" { | |
subscription_id = "<subid>" | |
environment = "usgovernemnt" | |
} | |
resource "azurerm_resource_group" "rg" { | |
count = "${var.count}" | |
name = "${format("%s%s%s-Web", upper(var.environment_code), upper(var.deployment_code), upper(var.location_code))}" | |
location = "USGov Virginia" | |
} | |
resource "azurerm_virtual_network" "network" { | |
count = "${var.count}" | |
name = "myVnet" | |
address_space = ["10.0.0.0/16"] | |
location = "${azurerm_resource_group.rg.location}" | |
resource_group_name = "${azurerm_resource_group.rg.name}" | |
} | |
resource "azurerm_subnet" "subnet" { | |
count = "${var.count}" | |
name = "mySubnet" | |
resource_group_name = "${azurerm_resource_group.rg.name}" | |
virtual_network_name = "${azurerm_virtual_network.network.name}" | |
address_prefix = "10.0.1.0/24" | |
} | |
resource "azurerm_network_interface" "nic" { | |
count = "${var.count}" | |
name = "myNIC" | |
location = "${azurerm_resource_group.rg.location}" | |
resource_group_name = "${azurerm_resource_group.rg.name}" | |
ip_configuration { | |
name = "myNicConfiguration" | |
subnet_id = "${azurerm_subnet.subnet.id}" | |
private_ip_address_allocation = "dynamic" | |
} | |
} | |
resource "azurerm_availability_set" "av_set" { | |
count = "${var.count}" | |
name = "myAvSet" | |
location = "${azurerm_resource_group.rg.location}" | |
resource_group_name = "${azurerm_resource_group.rg.name}" | |
managed = true | |
platform_fault_domain_count = 2 | |
platform_update_domain_count = 20 | |
} | |
resource "azurerm_virtual_machine" "vm" { | |
count = "${var.count}" | |
name = "myVMx1" | |
location = "${azurerm_resource_group.rg.location}" | |
resource_group_name = "${azurerm_resource_group.rg.name}" | |
network_interface_ids = ["${azurerm_network_interface.nic.id}"] | |
availability_set_id = "${azurerm_availability_set.av_set.id}" | |
vm_size = "Standard_D1" | |
storage_os_disk { | |
name = "myOsDisk" | |
caching = "ReadWrite" | |
create_option = "FromImage" | |
managed_disk_type = "Standard_LRS" | |
} | |
storage_image_reference { | |
publisher = "Canonical" | |
offer = "UbuntuServer" | |
sku = "16.04.0-LTS" | |
version = "latest" | |
} | |
os_profile { | |
computer_name = "myvm" | |
admin_username = "azureuser" | |
} | |
os_profile_linux_config { | |
disable_password_authentication = true | |
ssh_keys { | |
path = "/home/azureuser/.ssh/authorized_keys" | |
key_data = "ssh-rsa AAAAB3+ocZTGV" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment