Taula de continguts

Terraform, conditionals, state and VM

azure public ip

resource "azurerm_network_interface" "web_server_nic" {
  name                = "${var.web_server_name}-nic"
  location            = "${var.web_server_location}"
  resource_group_name = "${azurerm_resource_group.web_server_rg.name}"

  ip_configuration {
    name                          = "${var.web_server_name}-ip"
    subnet_id                     = "${azurerm_subnet.web_server_subnet.id}"
    private_ip_address_allocation = "dynamic"
    public_ip_address_id         = "${azurerm_public_ip.web_server_public_ip.id}"
  }
}

resource "azurerm_public_ip" "web_server_public_ip" {
  name                         = "${var.web_server_name}-public-ip"
  location                     = "${var.web_server_location}"
  resource_group_name          = "${azurerm_resource_group.web_server_rg.name}"
  public_ip_address_allocation = "dynamic"
}

conditionals

"web_server_location"       = "westus2"
"web_server_rg"             = "web-rg"
"resource_prefix"           = "web-server"
"web_server_address_space"  = "1.0.0.0/22"
"web_server_address_prefix" = "1.0.1.0/24"
"web_server_name"           = "web-01"
"environment"               = "production"
variable "environment" {}

resource "azurerm_public_ip" "web_server_public_ip" {
  name                         = "${var.web_server_name}-public-ip"
  location                     = "${var.web_server_location}"
  resource_group_name          = "${azurerm_resource_group.web_server_rg.name}"
  public_ip_address_allocation = "${var.environment == "production" ? "static" : "dynamic" }"
}

azure Network Security Group

resource "azurerm_network_interface" "web_server_nic" {
  name                      = "${var.web_server_name}-nic"
  location                  = "${var.web_server_location}"
  resource_group_name       = "${azurerm_resource_group.web_server_rg.name}"
  network_security_group_id = "${azurerm_network_security_group.web_server_nsg.id}"

  ip_configuration {
    name                          = "${var.web_server_name}-ip"
    subnet_id                     = "${azurerm_subnet.web_server_subnet.id}"
    private_ip_address_allocation = "dynamic"
    public_ip_address_id         = "${azurerm_public_ip.web_server_public_ip.id}"
  }
}

resource "azurerm_network_security_rule" "web_server_nsg_rule_rdp" {
  name                        = "RDP Inbound"
  priority                    = 100
  direction                   = "Inbound"
  access                      = "Allow"
  protocol                    = "TCP"
  source_port_range           = "*"
  destination_port_range      = "3389"
  source_address_prefix       = "*"
  destination_address_prefix  = "*"
  resource_group_name         = "${azurerm_resource_group.web_server_rg.name}"
  network_security_group_name = "${azurerm_network_security_group.web_server_nsg.name}"
}

azure Terraform state

azure Market Place Images

azure Hardware Models

Azure Virtual Machine