Created
September 19, 2018 16:18
-
-
Save archmangler/0042b3a5528195579e72397b1d9cb54c to your computer and use it in GitHub Desktop.
Simpleton's example starting point for azure VM in Terraform
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
/*Tested Ok example of Azure VM deployment*/ | |
variable "prefix" { | |
default = "tfvmex" | |
} | |
/*Create a resource group in a region*/ | |
resource "azurerm_resource_group" "main" { | |
name = "${var.prefix}-resources" | |
location = "West US 2" | |
} | |
/*create a primary virtual network*/ | |
resource "azurerm_virtual_network" "main" { | |
name = "${var.prefix}-network" | |
address_space = ["10.0.0.0/16"] | |
location = "${azurerm_resource_group.main.location}" | |
resource_group_name = "${azurerm_resource_group.main.name}" | |
} | |
/*Create a subnet on a virtual network in a resource group*/ | |
resource "azurerm_subnet" "internal" { | |
name = "internal" | |
resource_group_name = "${azurerm_resource_group.main.name}" | |
virtual_network_name = "${azurerm_virtual_network.main.name}" | |
address_prefix = "10.0.2.0/24" | |
} | |
/*create a primary network interface (before the VM is created)*/ | |
resource "azurerm_network_interface" "main" { | |
name = "${var.prefix}-nic" | |
location = "${azurerm_resource_group.main.location}" | |
resource_group_name = "${azurerm_resource_group.main.name}" | |
ip_configuration { | |
name = "testconfiguration1" | |
subnet_id = "${azurerm_subnet.internal.id}" | |
private_ip_address_allocation = "dynamic" | |
} | |
} | |
/*Create a virtual machine in the defined resource group with the | |
created primary interface in the defined network on the designated | |
subnet :-) */ | |
resource "azurerm_virtual_machine" "main" { | |
name = "${var.prefix}-vm" | |
location = "${azurerm_resource_group.main.location}" | |
resource_group_name = "${azurerm_resource_group.main.name}" | |
network_interface_ids = ["${azurerm_network_interface.main.id}"] | |
vm_size = "Standard_DS1_v2" | |
# Uncomment this line to delete the OS disk automatically when deleting the VM | |
delete_os_disk_on_termination = true | |
# Uncomment this line to delete the data disks automatically when deleting the VM | |
#delete_data_disks_on_termination = true | |
storage_image_reference { | |
publisher = "Canonical" | |
offer = "UbuntuServer" | |
sku = "16.04-LTS" | |
version = "latest" | |
} | |
storage_os_disk { | |
name = "myosdisk1" | |
caching = "ReadWrite" | |
create_option = "FromImage" | |
managed_disk_type = "Standard_LRS" | |
} | |
os_profile { | |
computer_name = "hostname" | |
admin_username = "testadmin" | |
admin_password = "Password1234!" | |
} | |
os_profile_linux_config { | |
disable_password_authentication = false | |
} | |
boot_diagnostics { | |
enabled = "true" | |
storage_uri = "${azurerm_storage_account.diagstorage2.primary_blob_endpoint}" | |
} | |
tags { | |
environment = "development" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment