working Terraform configuration for a VM w/ data disk

This commit is contained in:
Troy McConaghy 2017-02-10 18:01:19 +01:00
parent 218c1ca4b4
commit efe7669b58
10 changed files with 119 additions and 5 deletions

View File

@ -0,0 +1,12 @@
resource "azurerm_network_interface" "bdb_node_NIC_1" {
name = "bdb_node_NIC_1"
location = "${var.location}"
resource_group_name = "${azurerm_resource_group.bdb_node_RG.name}"
ip_configuration {
name = "bdb_node_IP_config_1"
subnet_id = "${azurerm_subnet.bdb_node_subnet_1.id}"
private_ip_address_allocation = "dynamic"
public_ip_address_id = "${azurerm_public_ip.bdb_node_IP_1.id}"
}
}

View File

@ -0,0 +1,20 @@
# Azure Network Security Group docs:
# https://www.terraform.io/docs/providers/azurerm/r/network_security_group.html
# https://docs.microsoft.com/en-us/azure/virtual-network/virtual-networks-nsg
resource "azurerm_network_security_group" "bdb_node_NSG_1" {
name = "bdb_node_NSG_1"
location = "${var.location}"
resource_group_name = "${azurerm_resource_group.bdb_node_RG.name}"
security_rule {
name = "ssh"
priority = 100
direction = "Inbound"
access = "Allow"
protocol = "Tcp" # Tcp, Udp, or * for both
source_port_range = "*"
destination_port_range = "22"
source_address_prefix = "*"
destination_address_prefix = "*"
}
}

View File

@ -0,0 +1,10 @@
resource "azurerm_public_ip" "bdb_node_IP_1" {
name = "bdb_node_IP_1"
location = "${var.location}"
resource_group_name = "${azurerm_resource_group.bdb_node_RG.name}"
public_ip_address_allocation = "static"
}
output "bdb_node_IP_1" {
value = "${azurerm_public_ip.bdb_node_IP_1.ip_address}"
}

View File

@ -1,5 +1,4 @@
# Create a resource group
resource "azurerm_resource_group" "bdbNodeRG" {
name = "bdbNodeRG"
resource "azurerm_resource_group" "bdb_node_RG" {
name = "bdb_node_RG"
location = "${var.location}"
}

View File

@ -0,0 +1,6 @@
resource "azurerm_storage_account" "bdb_node_SA" {
name = "bdbnodestorageaccount"
location = "${var.location}"
resource_group_name = "${azurerm_resource_group.bdb_node_RG.name}"
account_type = "Standard_LRS"
}

View File

@ -0,0 +1,6 @@
resource "azurerm_storage_container" "bdb_node_SC_1" {
name = "bdbnodestoragecontainer1"
resource_group_name = "${azurerm_resource_group.bdb_node_RG.name}"
storage_account_name = "${azurerm_storage_account.bdb_node_SA.name}"
container_access_type = "private"
}

View File

@ -0,0 +1,7 @@
resource "azurerm_subnet" "bdb_node_subnet_1" {
name = "bdb_node_subnet_1"
resource_group_name = "${azurerm_resource_group.bdb_node_RG.name}"
virtual_network_name = "${azurerm_virtual_network.bdb_node_VN_1.name}"
address_prefix = "10.0.2.0/24"
network_security_group_id = "${azurerm_network_security_group.bdb_node_NSG_1.id}"
}

View File

@ -1,7 +1,14 @@
# Use this file for Terraform variables that:
# 1) you don't mind sharing with the world on GitHub (if default provided) or
# 2) you want Terraform to ask the user for at runtime (if no default provided)
# Secret variables should be put in secret.tfvars or similar.
# Secret variables should be put in secret.tfvars with the following contents:
# subscription_id = "..."
# client_id = "..."
# client_secret = "..."
# tenant_id = "..."
# The secret.tfvars file will be read if you use:
# $ terraform <subcommand> -var-file="secret.tfvars"
variable "location" {
default = "westeurope"

View File

@ -0,0 +1,41 @@
variable "vm1_admin_password" {}
resource "azurerm_virtual_machine" "bdb_node_VM_1" {
name = "bdb_node_VM_1"
location = "${var.location}"
resource_group_name = "${azurerm_resource_group.bdb_node_RG.name}"
network_interface_ids = ["${azurerm_network_interface.bdb_node_NIC_1.id}"]
vm_size = "Standard_A2_v2"
storage_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "16.04-LTS"
version = "latest"
}
storage_os_disk {
name = "vm1osdisk1"
vhd_uri = "${azurerm_storage_account.bdb_node_SA.primary_blob_endpoint}${azurerm_storage_container.bdb_node_SC_1.name}/vm1osdisk1.vhd"
caching = "ReadWrite"
create_option = "FromImage"
}
storage_data_disk {
name = "vm1datadisk1"
vhd_uri = "${azurerm_storage_account.bdb_node_SA.primary_blob_endpoint}${azurerm_storage_container.bdb_node_SC_1.name}/vm1datadisk1.vhd"
disk_size_gb = "30"
create_option = "empty"
lun = 0
}
os_profile {
computer_name = "vm1"
admin_username = "vm1admin"
admin_password = "${var.vm1_admin_password}"
}
os_profile_linux_config {
disable_password_authentication = false
}
}

View File

@ -0,0 +1,6 @@
resource "azurerm_virtual_network" "bdb_node_VN_1" {
name = "bdb_node_VN_1"
location = "${var.location}"
resource_group_name = "${azurerm_resource_group.bdb_node_RG.name}"
address_space = ["10.0.0.0/16"]
}