Writing Terraform configurations

Use locals to specify explicit dependencies between resources

Helpful way to give a hint to Terraform that some resources should be deleted before even when there is no direct dependency in Terraform configurations.

Terraform 0.12 - Required vs Optional arguments

  1. 1.
    Required argument index_document must be set, if var.website is not an empty map.
  2. 2.
    Optional argument error_document can be omitted.
main.tf:
1
variable "website" {
2
type = map(string)
3
default = {}
4
}
5
6
resource "aws_s3_bucket" "this" {
7
# omitted...
8
9
dynamic "website" {
10
for_each = length(keys(var.website)) == 0 ? [] : [var.website]
11
12
content {
13
index_document = website.value.index_document
14
error_document = lookup(website.value, "error_document", null)
15
}
16
}
17
}
Copied!
terraform.tfvars:
1
website = {
2
index_document = "index.html"
3
}
Copied!
Last modified 2yr ago