github.com/terraform-modules-krish/terratest@v0.29.0/examples/terraform-azure-example/main.tf (about)

     1  provider "azurerm" {
     2    version = "=1.31.0"
     3  }
     4  
     5  # ---------------------------------------------------------------------------------------------------------------------
     6  # PIN TERRAFORM VERSION TO >= 0.12
     7  # The examples have been upgraded to 0.12 syntax
     8  # ---------------------------------------------------------------------------------------------------------------------
     9  
    10  terraform {
    11    required_version = ">= 0.12"
    12  }
    13  
    14  # ---------------------------------------------------------------------------------------------------------------------
    15  # DEPLOY A RESOURCE GROUP
    16  # See test/terraform_azure_example_test.go for how to write automated tests for this code.
    17  # ---------------------------------------------------------------------------------------------------------------------
    18  
    19  resource "azurerm_resource_group" "main" {
    20    name     = "${var.prefix}-resources"
    21    location = "East US"
    22  }
    23  
    24  # ---------------------------------------------------------------------------------------------------------------------
    25  # DEPLOY VIRTUAL NETWORK RESOURCES
    26  # ---------------------------------------------------------------------------------------------------------------------
    27  
    28  resource "azurerm_virtual_network" "main" {
    29    name                = "${var.prefix}-network"
    30    address_space       = ["10.0.0.0/16"]
    31    location            = azurerm_resource_group.main.location
    32    resource_group_name = azurerm_resource_group.main.name
    33  }
    34  
    35  resource "azurerm_subnet" "internal" {
    36    name                 = "internal"
    37    resource_group_name  = azurerm_resource_group.main.name
    38    virtual_network_name = azurerm_virtual_network.main.name
    39    address_prefix       = "10.0.17.0/24"
    40  }
    41  
    42  resource "azurerm_network_interface" "main" {
    43    name                = "${var.prefix}-nic"
    44    location            = azurerm_resource_group.main.location
    45    resource_group_name = azurerm_resource_group.main.name
    46  
    47    ip_configuration {
    48      name                          = "terratestconfiguration1"
    49      subnet_id                     = azurerm_subnet.internal.id
    50      private_ip_address_allocation = "Dynamic"
    51    }
    52  }
    53  
    54  # ---------------------------------------------------------------------------------------------------------------------
    55  # DEPLOY A VIRTUAL MACHINE RUNNING UBUNTU
    56  # ---------------------------------------------------------------------------------------------------------------------
    57  
    58  resource "azurerm_virtual_machine" "main" {
    59    name                             = "${var.prefix}-vm"
    60    location                         = azurerm_resource_group.main.location
    61    resource_group_name              = azurerm_resource_group.main.name
    62    network_interface_ids            = [azurerm_network_interface.main.id]
    63    vm_size                          = "Standard_B1s"
    64    delete_os_disk_on_termination    = true
    65    delete_data_disks_on_termination = true
    66  
    67    storage_image_reference {
    68      publisher = "Canonical"
    69      offer     = "UbuntuServer"
    70      sku       = "16.04-LTS"
    71      version   = "latest"
    72    }
    73  
    74    storage_os_disk {
    75      name              = "terratestosdisk1"
    76      caching           = "ReadWrite"
    77      create_option     = "FromImage"
    78      managed_disk_type = "Standard_LRS"
    79    }
    80  
    81    os_profile {
    82      computer_name  = var.hostname
    83      admin_username = var.username
    84      admin_password = var.password
    85    }
    86  
    87    os_profile_linux_config {
    88      disable_password_authentication = false
    89    }
    90  }
    91