daily pastebin goal
64%
SHARE
TWEET

Untitled

a guest Feb 16th, 2019 101 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Configure the Microsoft Azure Provider
  2. provider "azurerm" {
  3.     subscription_id = ""
  4.     client_id       = ""
  5.     client_secret   = ""
  6.     tenant_id       = ""
  7. }
  8.  
  9. # Create a resource group if it doesn’t exist
  10. resource "azurerm_resource_group" "terraform_rg" {
  11.     name     = "myVmRg"
  12.     location = "eastus"
  13.  
  14.     tags {
  15.         environment = "Demo by avinash.seth@outlook.com"
  16.     }
  17. }
  18.  
  19. # Create virtual network
  20. resource "azurerm_virtual_network" "terraform_net" {
  21.     name                = "terravn"
  22.     address_space       = ["10.0.0.0/16"]
  23.     location            = "eastus"
  24.     resource_group_name = "${azurerm_resource_group.terraform_rg.name}"
  25. }
  26.  
  27. # Create subnet
  28. resource "azurerm_subnet" "terraform_subnet" {
  29.     name                 = "mySubnet"
  30.     resource_group_name  = "${azurerm_resource_group.terraform_rg.name}"
  31.     virtual_network_name = "${azurerm_virtual_network.terraform_net.name}"
  32.     address_prefix       = "10.0.1.0/24"
  33. }
  34.  
  35. # Create public IPs
  36. resource "azurerm_public_ip" "terraform_ip" {
  37.     name                         = "myPublicIP"
  38.     location                     = "eastus"
  39.     resource_group_name          = "${azurerm_resource_group.terraform_rg.name}"
  40.     public_ip_address_allocation = "dynamic"
  41. }
  42.  
  43. # Create Network Security Group and rule
  44. resource "azurerm_network_security_group" "terraform_nsg" {
  45.     name                = "myNetworkSecurityGroup"
  46.     location            = "eastus"
  47.     resource_group_name = "${azurerm_resource_group.terraform_rg.name}"
  48.  
  49.     security_rule {
  50.         name                       = "SSH"
  51.         priority                   = 1001
  52.         direction                  = "Inbound"
  53.         access                     = "Allow"
  54.         protocol                   = "Tcp"
  55.         source_port_range          = "*"
  56.         destination_port_range     = "22"
  57.         source_address_prefix      = "*"
  58.         destination_address_prefix = "*"
  59.     }
  60. }
  61.  
  62. # Create network interface
  63. resource "azurerm_network_interface" "terraform_nic" {
  64.     name                      = "myNIC"
  65.     location                  = "eastus"
  66.     resource_group_name       = "${azurerm_resource_group.terraform_rg.name}"
  67.     network_security_group_id = "${azurerm_network_security_group.terraform_nsg.id}"
  68.  
  69.     ip_configuration {
  70.         name                          = "myNicConfiguration"
  71.         subnet_id                     = "${azurerm_subnet.terraform_subnet.id}"
  72.         private_ip_address_allocation = "dynamic"
  73.         public_ip_address_id          = "${azurerm_public_ip.terraform_ip.id}"
  74.     }
  75. }
  76.  
  77. # Generate random text for a unique storage account name
  78. resource "random_id" "randomId" {
  79.     keepers = {
  80.         # Generate a new ID only when a new resource group is defined
  81.         resource_group = "${azurerm_resource_group.terraform_rg.name}"
  82.     }
  83.  
  84.     byte_length = 8
  85. }
  86.  
  87. # Create storage account for boot diagnostics
  88. resource "azurerm_storage_account" "mystorageaccount" {
  89.     name                        = "diag${random_id.randomId.hex}"
  90.     resource_group_name         = "${azurerm_resource_group.terraform_rg.name}"
  91.     location                    = "eastus"
  92.     account_tier                = "Standard"
  93.     account_replication_type    = "LRS"
  94. }
  95.  
  96. # Create virtual machine
  97. resource "azurerm_virtual_machine" "terraform_vm" {
  98.     name                  = "myVM"
  99.     location              = "eastus"
  100.     resource_group_name   = "${azurerm_resource_group.terraform_rg.name}"
  101.     network_interface_ids = ["${azurerm_network_interface.terraform_nic.id}"]
  102.     vm_size               = "Standard_DS1_v2"
  103.  
  104.     storage_os_disk {
  105.         name              = "myOsDisk"
  106.         caching           = "ReadWrite"
  107.         create_option     = "FromImage"
  108.         managed_disk_type = "Premium_LRS"
  109.     }
  110.  
  111.     storage_image_reference {
  112.         publisher = "Canonical"
  113.         offer     = "UbuntuServer"
  114.         sku       = "16.04.0-LTS"
  115.         version   = "latest"
  116.     }
  117.  
  118.     os_profile {
  119.         computer_name  = "avinashseth"
  120.         admin_username = "avinashseth"
  121.     }
  122.  
  123.     os_profile_linux_config {
  124.         disable_password_authentication = true
  125.         ssh_keys {
  126.             path     = "/home/avinashseth/.ssh/authorized_keys"
  127.             key_data = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCVMrEGzlfOnSC1Gc2yiaV8g/YwBBmix1CDTCU7XkPyIiTxEofa086Imy8jEuMGu4FFxaz8pzVuCWJ5MqDoMVfIsRVayJ0F+hF82TTttaaaOkIdYBd9MEKNn/bWm6rBzFjZg4G7CWBu+p3CzGQWu6spgq9rC3QZwo+ntgm4PZxJOO6hYvKTHalB6FE8sKW74SXHd2VnD1dtxRxqbeulInRBamjbhYDngAYeO+SfNjOel+ODiGyEh1rCc4RkoY02+nrCdwQtqBVSAmN8Nxkf93Hi2mml01Cwa3kswDSPx/F8WyhBpEizyIgesSgKXwdSa8ARaCWcsxxP4NCYLtcZ+cfp "
  128.         }
  129.     }
  130.  
  131.     boot_diagnostics {
  132.         enabled = "true"
  133.         storage_uri = "${azurerm_storage_account.mystorageaccount.primary_blob_endpoint}"
  134.     }
  135. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top