Skip to content

Instantly share code, notes, and snippets.

@rohrerb
Created August 27, 2018 11:40
Show Gist options
  • Save rohrerb/fae778135b6938a4131540b544907683 to your computer and use it in GitHub Desktop.
Save rohrerb/fae778135b6938a4131540b544907683 to your computer and use it in GitHub Desktop.
variable "environment_code" { default = "US"}
variable "deployment_code" { default = "T"}
variable "location_code" { default = "V"}
variable "instance_count" { default = 1}
//variable "enable_msi" { default = false}
variable "msi_block_identity" {
type = "map"
default = {
"type" = "SystemAssigned"
}
}
locals {
base_hostname = "${format("%s%s%s%s%s", var.environment_code, var.deployment_code, var.location_code, "l", "xyz")}"
}
provider "azurerm" {
subscription_id = "72f988bf-86f1-41af-91ab-2d7cd011db47"
}
resource "azurerm_resource_group" "rg" {
name = "${format("%s%s%s-Web", upper(var.environment_code), upper(var.deployment_code), upper(var.location_code))}"
location = "eastus"
}
resource "azurerm_virtual_network" "network" {
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" {
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.instance_count}"
name = "${format("%s%03dNetworkInterface", local.base_hostname, count.index + 1)}"
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" {
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.instance_count}"
name = "${format("%s%03d", local.base_hostname, count.index + 1)}"
location = "${azurerm_resource_group.rg.location}"
resource_group_name = "${azurerm_resource_group.rg.name}"
network_interface_ids = ["${element(azurerm_network_interface.nic.*.id, count.index)}"]
availability_set_id = "${azurerm_availability_set.av_set.id}"
vm_size = "Standard_A1"
storage_os_disk {
name = "${format("%s%03d", local.base_hostname, count.index + 1)}-osdisk"
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"
}
identity = "${var.msi_block_identity}"
os_profile_linux_config {
disable_password_authentication = true
ssh_keys {
path = "/home/azureuser/.ssh/authorized_keys"
key_data = "ssh-rsa AAAEvL5aUMfWFBRXtl8FnKcZTGV"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment