Skip to content

Instantly share code, notes, and snippets.

@stevendborrelli
Created May 10, 2016 11:35
Show Gist options
  • Save stevendborrelli/f5567ee8bea0d37efe522dd49a57c275 to your computer and use it in GitHub Desktop.
Save stevendborrelli/f5567ee8bea0d37efe522dd49a57c275 to your computer and use it in GitHub Desktop.
variable name {
default = "terraform"
description = "Name of the virtual network"
}
variable location {
default = "Central US"
description = "Geographic location of the virtual network"
}
variable subnet_id {
description = "Subnet for the network interface"
}
variable private_ip_address_allocation {
default = "dynamic"
description = "IP assignment for the network interface. Can be static or dynamic: if using static please set private_ip_address"
}
variable private_ip_address {
default = ""
description = "Rrivate IP address for the network interface. Required if private_ip_address_allocation is static"
}
variable public_ip_address_id {
default = ""
description = "Optional Public IP address id to assign to the network interface"
}
variable resource_group_name {
description = "Resource group name"
}
variable network_security_group_id {
default = ""
description = "Optional network security group to attach to instance"
}
variable vm_name {
default = "vm"
description = "Name of the Virtual Machine"
}
variable vm_size {
default = "Standard_A1"
description = "Size of the VM. See https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-windows-sizes/"
}
# Storage account to use
variable storage_account_name {
description = "Azure storage account to use to store OS disk images"
}
variable storage_primary_blob_endpoint {
description = "Azure storage blob endpoint to use to store OS disk images"
}
# Images to use
# See https://github.com/Azure/azure-quickstart-templates/blob/master/101-vm-simple-windows/azuredeploy.json
variable image_publisher {
default = "MicrosoftWindowsServer"
description = "OS Image publisher"
}
variable image_offer {
default = "WindowsServer"
description = "OS Image offer"
}
variable image_sku {
default = "2012-R2-Datacenter"
description = "OS Image sku"
}
variable image_version {
default = "latest"
description = "OS Image version"
}
variable admin_username {
default = "terraform"
description = "Admin account"
}
variable admin_password {
description = "Admin account password (required)"
}
variable os_disk_name {
default = "osdisk"
description = "name of the OS disk"
}
# All VMs require a network interface
resource "azurerm_network_interface" "ni" {
name = "${var.vm_name}-ni"
location = "${var.location}"
resource_group_name = "${var.resource_group_name}"
network_security_group_id = "${var.network_security_group_id}"
ip_configuration {
name = "${var.vm_name}-ni"
subnet_id = "${var.subnet_id}"
private_ip_address_allocation = "${var.private_ip_address_allocation}"
private_ip_address = "${var.private_ip_address}"
public_ip_address_id = "${var.public_ip_address_id}"
}
}
resource "azurerm_storage_container" "osdisk" {
name = "${var.vm_name}${var.os_disk_name}"
storage_account_name = "${var.storage_account_name}"
resource_group_name = "${var.resource_group_name}"
container_access_type = "private"
}
resource "azurerm_virtual_machine" "vm" {
name = "${var.vm_name}"
location = "${var.location}"
resource_group_name = "${var.resource_group_name}"
network_interface_ids = ["${azurerm_network_interface.ni.id}"]
vm_size = "${var.vm_size}"
storage_image_reference {
publisher = "${var.image_publisher}"
offer = "${var.image_offer}"
sku = "${var.image_sku}"
version = "${var.image_version}"
}
storage_os_disk {
name = "${var.os_disk_name}"
vhd_uri = "${var.storage_primary_blob_endpoint}${azurerm_storage_container.osdisk.name}/${var.os_disk_name}.vhd"
caching = "ReadWrite"
create_option = "FromImage"
}
os_profile {
computer_name = "${var.vm_name}"
admin_username = "${var.admin_username}"
admin_password = "${var.admin_password}"
}
}
output "vm_id" {
value = "${azurerm_virtual_machine.vm.id}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment