-
Notifications
You must be signed in to change notification settings - Fork 709
Single Required Block
GlennChia edited this page Jul 7, 2021
·
1 revision
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.
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.