Aquesta és una revisió antiga del document


Terraform, variables, interpolation and networking

  • tipos nativos: strings, maps (key=value), list ([])
    • boolean no es nativo
  • localización:
    • en el cuerpo de script
    • por línea de comando o entono
    • en un fichero adicional de variables
    • más información: terraform variables
  • variable "nombre_variable" {
      default = "valor por defecto"
    }
     
    variable "localizaciones" {
      type = map
      default = {
        location1 = "xxxx"
        location2 = "yyyy"
      }
    }
  • testeando variables y su uso:
    variable "server_name" {
        default = "web-server"
    }
     
    variable "locations" {
        type = "map"
        default = {
            location1 = "xxx"
            location2 = "yyy"
        }
    }
     
    variable "subnets" {
        type = "list"
        default = ["10.0.1.10","10.0.1.11"]
    }
     
    variable "live" {
      type = "string"
      default = true
    }
    • terraform console
      • var.server_name
      • var.locations[«location1»]
      • var.locations.location1
      • var.subnets[0]
      • var.live
  • uso variables [de entorno] para almacenar credenciales
  • TF_VAR_<NOMBRE> definida como variable de entorno del sistema
  • variables
    • var.<nombre>
  • resources
    • <resource>.<nombre>.<atributo>
  • data: recoger un dato del estado
    • data.<resource>.<nombre>.<atributo>
  • variable "subscription_id" {
     
    }
     
    #suponiendo que está en el entorno
    provider "azurerm" {
        version         = ">=1.27"
        client_id       = "6c609608-a350-476f-85ff-eaff7e82f981"
        client_secret   = "qW0S]tToc]=]ub8HM7yciLSnwOWh1emD"
        tenant_id       = "c8537169-fe81-494a-a2dd-b4ea067073a1"
        subscription_id = var.subscription_id
        features {}
    }
  • agrupación lógica de recursos bajo tu criterio
  • cada resource* ha de ir en resource group
  • terraform.tfvars
    web_server_location = "westus2"
    web_server_rg = "web-rg"
main.tf
variable web_server_location {}
variable web_server_rg {}
 
resource "azurerm_resource_group" "web_server_rg" {
  name = var.web_server_rg
  location = var.web_server_location
}

  • info/cursos/udemy/terraform-azure/variables-interpolation-networking.1585585098.txt.gz
  • Darrera modificació: 30/03/2020 09:18
  • per mate