terraform/examples/azure-vm-simple-linux/main.tf

113 lines
3.8 KiB
Terraform
Raw Normal View History

2017-04-17 22:46:01 +02:00
resource "azurerm_resource_group" "rg" {
name = "${var.resource_group}"
location = "${var.location}"
}
resource "azurerm_virtual_network" "vnet" {
name = "${var.virtual_network_name}"
location = "${var.location}"
address_space = ["${var.address_space}"]
resource_group_name = "${azurerm_resource_group.rg.name}"
}
resource "azurerm_subnet" "subnet" {
name = "${var.rg_prefix}subnet"
virtual_network_name = "${azurerm_virtual_network.vnet.name}"
resource_group_name = "${azurerm_resource_group.rg.name}"
address_prefix = "${var.subnet_prefix}"
}
resource "azurerm_network_interface" "nic" {
2017-04-24 18:45:24 +02:00
name = "${var.rg_prefix}nic"
location = "${var.location}"
resource_group_name = "${azurerm_resource_group.rg.name}"
2017-04-17 22:46:01 +02:00
ip_configuration {
name = "${var.rg_prefix}ipconfig"
subnet_id = "${azurerm_subnet.subnet.id}"
private_ip_address_allocation = "Dynamic"
public_ip_address_id = "${azurerm_public_ip.pip.id}"
}
}
resource "azurerm_public_ip" "pip" {
name = "${var.rg_prefix}-ip"
location = "${var.location}"
resource_group_name = "${azurerm_resource_group.rg.name}"
public_ip_address_allocation = "dynamic"
domain_name_label = "${var.dns_name}"
}
resource "azurerm_storage_account" "stor" {
name = "${var.dns_name}stor"
2017-04-17 22:46:01 +02:00
location = "${var.location}"
resource_group_name = "${azurerm_resource_group.rg.name}"
account_type = "${var.storage_account_type}"
}
resource "azurerm_storage_container" "storc" {
name = "${var.hostname}-vhds"
resource_group_name = "${azurerm_resource_group.rg.name}"
storage_account_name = "${azurerm_storage_account.stor.name}"
container_access_type = "private"
}
resource "azurerm_managed_disk" "disk1" {
name = "${var.hostname}-osdisk1"
location = "${var.location}"
resource_group_name = "${azurerm_resource_group.rg.name}"
storage_account_type = "Standard_LRS"
create_option = "Empty"
disk_size_gb = "30"
}
resource "azurerm_managed_disk" "disk2" {
name = "${var.hostname}-disk2"
location = "${var.location}"
resource_group_name = "${azurerm_resource_group.rg.name}"
storage_account_type = "Standard_LRS"
create_option = "Empty"
disk_size_gb = "1023"
}
resource "azurerm_virtual_machine" "vm" {
name = "${var.rg_prefix}vm"
location = "${var.location}"
resource_group_name = "${azurerm_resource_group.rg.name}"
vm_size = "${var.vm_size}"
network_interface_ids = ["${azurerm_network_interface.nic.id}"]
storage_image_reference {
publisher = "${var.image_publisher}"
offer = "${var.image_offer}"
sku = "${var.image_sku}"
version = "${var.image_version}"
}
storage_os_disk {
name = "${var.hostname}-osdisk1"
vhd_uri = "${azurerm_storage_account.stor.primary_blob_endpoint}${azurerm_storage_container.storc.name}/${var.hostname}-osdisk1.vhd"
caching = "ReadWrite"
create_option = "FromImage"
}
storage_data_disk {
name = "${var.hostname}-disk2"
vhd_uri = "${azurerm_storage_account.stor.primary_blob_endpoint}${azurerm_storage_container.storc.name}/${var.hostname}-disk2.vhd"
disk_size_gb = "1023"
create_option = "Empty"
lun = 0
}
os_profile {
computer_name = "${var.hostname}"
admin_username = "${var.admin_username}"
admin_password = "${var.admin_password}"
}
boot_diagnostics {
enabled = "true"
storage_uri = "${azurerm_storage_account.stor.primary_blob_endpoint}"
}
}