Pisanie konfiguracji Terraform
Użyj zmiennych lokalnych (locals), aby określić jawne zależności między zasobami
locals), aby określić jawne zależności między zasobamiPrzydatny sposób na wskazanie Terraform, że niektóre zasoby powinny zostać usunięte wcześniej, nawet jeśli nie ma bezpośredniej zależności w konfiguracjach.
https://raw.githubusercontent.com/antonbabenko/terraform-best-practices/master/snippets/locals.tf
Terraform 0.12 - argumenty wymagane vs opcjonalne
Wymagany argument
index_documentmusi być ustawiony, jeślivar.websitenie jest pustą mapą.Opcjonalny argument
error_documentmożna pominąć.
variable "website" {
type = map(string)
default = {}
}
resource "aws_s3_bucket" "this" {
# pomijamy...
dynamic "website" {
for_each = length(keys(var.website)) == 0 ? [] : [var.website]
content {
index_document = website.value.index_document
error_document = lookup(website.value, "error_document", null)
}
}
}website = {
index_document = "index.html"
}Last updated