You don't have access to this class

Keep learning! Join and start boosting your career

Aprovecha el precio especial y haz tu profesión a prueba de IA

Antes: $249

Currency
$209
Suscríbete

Termina en:

0 Días
7 Hrs
33 Min
34 Seg

Archivos de definición y variables

15/27
Resources

Our configuration file at the moment is not very reusable since all the values are already defined, Terraform allows us that instead of adding static values we can define our file with variables.

Variables within Terraform must be defined and instantiated, a good practice is to have variables defined in one file and instantiated in another.

Terraform allows us to use String, List and Map variables. To each variable we can add a default value, a description and the type of the variable, currently Terraform identifies the type of variable automatically.

The file where we assign the values of the variables must end in .tfvars.

Contributions 14

Questions 2

Sort by:

Want to see more contributions, questions and answers from the community?

Es comun que cuando se destruye la infraestructura no se quiera destruir algun recurso en espesifico (por ejemplo la base de datos o algo asi) asi que podemos espesificarlo en la definicion de dicho recurso de la siguiente panera

resource "aws_db_instance" "example" {
  # ...
  lifecycle {
    prevent_destroy = true # no destruir cuando se aplique terraform destroy
  }
  timeouts {
    create = "60m"
    delete = "2h"
  }
}

En VS Code la extesión de Anton Kulikov de Terraform ya soporta la versión 0.12 de Terraform, para que no les marque error cuando declaren variables.

🤯🤯🤯 Brutal lo que se puede hacer, parece magia negra.

Que se identifique el tipo de variable usado se puede hacer desde terraform 0.12, más información acá https://www.terraform.io/docs/configuration/variables.html

excelente explicacion, me sorprendio mucho poder encontrar un curso de terraform aqui en platzi, definitivamente de las mejores inversiones que he hecho en mi vida profesional, muchas gracias Yolanda, pude aplicar rapidamente los conocimientos en mi trabajo.

Pienso que dentro de las buenas practicas, las variables se deben llevar en otro archivo tf

me parecio chevere que si no le especifico el archivo de las variables terraform solicita los valores de entrada para poder ejecutar

Muy potente - funcional

provider "aws" {
  region = "us-east-2"
}

resource "aws_instance" "platzi-instance" {
  ami           = var.ami_id
  instance_type = var.instance_type
  tags          = var.tags
}

last version: v1.3.x

  • El tipo de variables que usa terraform:
    • string:
    • mapa: object: {name = "Mabel", age = 52}
    • listas: tupla: ["us-west-1a", "us-west-1c"]
    • number:
    • bool:
    • null: special type

Doc Oficial - Variables en Terraform
Link

Una bosta la clase

last version: v1.3.x

  • Las variables tienen los siguientes argumentos al momento de ser creadas:
    • default
    • type
    • description
    • validation
    • sensitive
    • nullable

Types
The Terraform language uses the following types for its values:

string: a sequence of Unicode characters representing some text, like “hello”.
number: a numeric value. The number type can represent both whole numbers like 15 and fractional values like 6.283185.
bool: a boolean value, either true or false. bool values can be used in conditional logic.
list (or tuple): a sequence of values, like [“us-west-1a”, “us-west-1c”]. Elements in a list or tuple are identified by consecutive whole numbers, starting with zero.
map (or object): a group of values identified by named labels, like {name = “Mabel”, age = 52}.
Strings, numbers, and bools are sometimes called primitive types. Lists/tuples and maps/objects are sometimes called complex types, structural types, or collection types.

Finally, there is one special value that has no type:

null: a value that represents absence or omission. If you set an argument of a resource to null, Terraform behaves as though you had completely omitted it — it will use the argument’s default value if it has one, or raise an error if the argument is mandatory. null is most useful in conditional expressions, so you can dynamically omit an argument if a condition isn’t met.