Single Required Block - ivaramme/terraform-azurerm-caf GitHub Wiki
This patten covers the following phrase in the Terraform Registry:
(Required) A <name of block> block as defined below.
Example:
(Required) A time_period block as defined below.
Simple use case
In the configuration.tfvars
file:
time_period = {
start_date = "2022-06-01T00:00:00Z"
}
In the resource file:
time_period {
start_date = try(var.settings.time_period.start_date, join("", [formatdate("YYYY-MM", timestamp()), "-01T00:00:00Z"]))
end_date = try(var.settings.time_period.end_date, null)
}
- No
for_each
required since there is only one block - In this example, a
try
statement is added to thestart_date
to ensure that the CI passes with a valid date. If thestart_date
is not defined in theconfiguration.tfvars
, it is generated dynamically usingjoin("", [formatdate("YYYY-MM", timestamp()), "-01T00:00:00Z"]
which gets the date of the first day of the month.