github.com/darmach/terratest@v0.34.8-0.20210517103231-80931f95e3ff/examples/azure/terraform-azure-network-example/main.tf (about)

     1  # ---------------------------------------------------------------------------------------------------------------------
     2  # DEPLOY AN AZURE NETWORK
     3  # This is an example of how to deploy frequent Azure Networking Resources. Note this network doesn't actually do
     4  # anything and is only created for the example to test their commonly needed and integrated properties.
     5  # ---------------------------------------------------------------------------------------------------------------------
     6  # See test/azure/terraform_azure_network_example_test.go for how to write automated tests for this code.
     7  # ---------------------------------------------------------------------------------------------------------------------
     8  
     9  provider "azurerm" {
    10    version = "~>2.20"
    11    features {}
    12  }
    13  
    14  # ---------------------------------------------------------------------------------------------------------------------
    15  # PIN TERRAFORM VERSION TO >= 0.12
    16  # The examples have been upgraded to 0.12 syntax
    17  # ---------------------------------------------------------------------------------------------------------------------
    18  
    19  terraform {
    20    # This module is now only being tested with Terraform 0.13.x. However, to make upgrading easier, we are setting
    21    # 0.12.26 as the minimum version, as that version added support for required_providers with source URLs, making it
    22    # forwards compatible with 0.13.x code.
    23    required_version = ">= 0.12.26"
    24  }
    25  
    26  # ---------------------------------------------------------------------------------------------------------------------
    27  # DEPLOY A RESOURCE GROUP
    28  # ---------------------------------------------------------------------------------------------------------------------
    29  
    30  resource "azurerm_resource_group" "net" {
    31    name     = "terratest-network-rg-${var.postfix}"
    32    location = var.location
    33  }
    34  
    35  # ---------------------------------------------------------------------------------------------------------------------
    36  # DEPLOY VIRTUAL NETWORK
    37  # ---------------------------------------------------------------------------------------------------------------------
    38  
    39  resource "azurerm_virtual_network" "net" {
    40    name                = "vnet-${var.postfix}"
    41    location            = azurerm_resource_group.net.location
    42    resource_group_name = azurerm_resource_group.net.name
    43    address_space       = ["10.0.0.0/16"]
    44    dns_servers         = [var.dns_ip_01, var.dns_ip_02]
    45  }
    46  
    47  resource "azurerm_subnet" "net" {
    48    name                 = "subnet-${var.postfix}"
    49    resource_group_name  = azurerm_resource_group.net.name
    50    virtual_network_name = azurerm_virtual_network.net.name
    51    address_prefixes     = [var.subnet_prefix]
    52  }
    53  
    54  # ---------------------------------------------------------------------------------------------------------------------
    55  # DEPLOY PRIVATE NETWORK INTERFACE
    56  # ---------------------------------------------------------------------------------------------------------------------
    57  
    58  resource "azurerm_network_interface" "net01" {
    59    name                = "nic-private-${var.postfix}"
    60    location            = azurerm_resource_group.net.location
    61    resource_group_name = azurerm_resource_group.net.name
    62  
    63    ip_configuration {
    64      name                          = "terratestconfiguration1"
    65      subnet_id                     = azurerm_subnet.net.id
    66      private_ip_address_allocation = "Static"
    67      private_ip_address            = var.private_ip
    68    }
    69  }
    70  
    71  # ---------------------------------------------------------------------------------------------------------------------
    72  # DEPLOY PUBLIC ADDRESS AND NETWORK INTERFACE
    73  # ---------------------------------------------------------------------------------------------------------------------
    74  
    75  resource "azurerm_public_ip" "net" {
    76    name                    = "pip-${var.postfix}"
    77    resource_group_name     = azurerm_resource_group.net.name
    78    location                = azurerm_resource_group.net.location
    79    allocation_method       = "Static"
    80    ip_version              = "IPv4"
    81    sku                     = "Basic"
    82    idle_timeout_in_minutes = "4"
    83    domain_name_label       = var.domain_name_label
    84  }
    85  
    86  resource "azurerm_network_interface" "net02" {
    87    name                = "nic-public-${var.postfix}"
    88    location            = azurerm_resource_group.net.location
    89    resource_group_name = azurerm_resource_group.net.name
    90  
    91    ip_configuration {
    92      name                          = "terratestconfiguration1"
    93      subnet_id                     = azurerm_subnet.net.id
    94      private_ip_address_allocation = "Dynamic"
    95      public_ip_address_id          = azurerm_public_ip.net.id
    96    }
    97  }
    98