Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # create a resource group if it doesn't exist
- resource "azurerm_resource_group" "rg" {
- name = "a132rg"
- location = "ukwest"
- }
- # create virtual network
- resource "azurerm_virtual_network" "vnet" {
- name = "tfvnet"
- address_space = ["10.0.0.0/16"]
- location = "ukwest"
- resource_group_name = "${azurerm_resource_group.rg.name}"
- subnet {
- name = "subnet1"
- address_prefix = "10.0.3.0/24"
- }
- }
- # create subnet
- resource "azurerm_subnet" "subnet" {
- name = "tfsub"
- resource_group_name = "${azurerm_resource_group.rg.name}"
- virtual_network_name = "${azurerm_virtual_network.vnet.name}"
- address_prefix = "10.0.2.0/24"
- #network_security_group_id = "${azurerm_network_security_group.nsg.id}"
- }
- # create public IPs
- resource "azurerm_public_ip" "ip" {
- name = "tfip"
- location = "ukwest"
- resource_group_name = "${azurerm_resource_group.rg.name}"
- public_ip_address_allocation = "dynamic"
- domain_name_label = "a132"
- tags {
- environment = "staging"
- }
- }
- # create network interface
- resource "azurerm_network_interface" "ni" {
- name = "tfni"
- location = "ukwest"
- resource_group_name = "${azurerm_resource_group.rg.name}"
- ip_configuration {
- name = "ipconfiguration"
- subnet_id = "${azurerm_subnet.subnet.id}"
- private_ip_address_allocation = "static"
- private_ip_address = "10.0.2.5"
- public_ip_address_id = "${azurerm_public_ip.ip.id}"
- }
- }
- # create storage account
- resource "azurerm_storage_account" "storage" {
- name = "0fda935368315bd1a5f5560e"
- resource_group_name = "${azurerm_resource_group.rg.name}"
- location = "ukwest"
- account_replication_type = "LRS"
- account_tier = "Standard"
- tags {
- environment = "staging"
- }
- }
- # create storage container
- resource "azurerm_storage_container" "storagecont" {
- name = "vhd"
- resource_group_name = "${azurerm_resource_group.rg.name}"
- storage_account_name = "${azurerm_storage_account.storage.name}"
- container_access_type = "private"
- depends_on = ["azurerm_storage_account.storage"]
- }
- # create virtual machine
- resource "azurerm_virtual_machine" "vm" {
- name = "a132vm"
- location = "ukwest"
- resource_group_name = "${azurerm_resource_group.rg.name}"
- network_interface_ids = ["${azurerm_network_interface.ni.id}"]
- vm_size = "Standard_A6"
- storage_image_reference {
- publisher = "Canonical"
- offer = "UbuntuServer"
- sku = "16.04-LTS"
- version = "latest"
- }
- storage_os_disk {
- name = "myosdisk"
- vhd_uri = "${azurerm_storage_account.storage.primary_blob_endpoint}${azurerm_storage_container.storagecont.name}/myosdisk.vhd"
- caching = "ReadWrite"
- create_option = "FromImage"
- }
- os_profile {
- computer_name = "a132"
- admin_username = "****"
- admin_password = "*************"
- }
- os_profile_linux_config {
- disable_password_authentication = false
- }
- }
Add Comment
Please, Sign In to add comment