%title: Terraform %author: Hubert
Terraform : Stockage des variables
- type de variables :
- string
- number
- bool (boolean)
- liste
- map
variable "mybool" {
type = "bool"
default = true
}
- deux manières d'utiliser
output "mavariable" {
value = var.str
}
output "mavariable" {
value = "${var.str}"
}
Terraform : Stockage des variables
- définition à plusieurs niveaux : environnement > fichier spécifique
- ordre des variables
- 1 - environnement
- 2 - fichier : terraform.tfvars
- 3 - fichier json : terraform.tfvars.json
- 4 - fichier *.auto.tfvars ou *.auto.tfvars.json
- 5 - CLI : -var ou - var-file
- environnement:
export TF_VAR_str="env"
terraform apply
- fichier terraform.tfvars
echo 'str="terraform"'> terraform.tfvars
- fichier auto
echo 'str="auto"'> production.auto.tfvars
- le fichier ou la cli
terraform apply -var "str=cli"
terraform apply -var-file vafile.tfvars -var "str=cli"