Skip to content

Commit

Permalink
Checks on checklist for resman
Browse files Browse the repository at this point in the history
  • Loading branch information
wiktorn committed Jan 12, 2024
1 parent fd8c45d commit 8947b20
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions fast/stages/1-resman/checklist.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,12 @@

locals {
# parse raw data from JSON files if they exist
_cl_data_raw = (
_cl_data = (
var.factories_config.checklist_data == null
? null
: yamldecode(file(pathexpand(var.factories_config.checklist_data)))
)
# check that version and organization id are fine
_cl_data = local._cl_data_raw == null ? null : (
local._cl_data_raw.version != "0.1.0"
||
local._cl_data_raw.organization.id != tostring(var.organization.id)
? null
: local._cl_data_raw
: jsondecode(file(pathexpand(var.factories_config.checklist_data)))
)

# normalized IAM bindings one element per binding
_cl_iam = local._cl_data == null ? [] : flatten([
for v in try(local._cl_data.access_control, []) : [
Expand All @@ -54,6 +47,32 @@ locals {
}
}

check "checklist" {
assert {
condition = (
var.factories_config.checklist_data == null
) || (
try(local._cl_data.version, "") == "0.1.0"
)
error_message = join("", [
"Checklist file version must be 0.1.0. ",
"File ${coalesce(var.factories_config.checklist_data, "NULL")} has version ${try(local._cl_data.version, "NULL")}.",
])
}

assert {
condition = (
var.factories_config.checklist_data == null
) || (
try(local._cl_data.organization.id, null) == tostring(var.organization.id)
)
error_message = join("", [
"Organization Id doesn't match. var.organization.id is ${var.organization.id}. ",
"File ${coalesce(var.factories_config.checklist_data, "NULL")} has organization ${try(local._cl_data.organization.id, "NULL")}.",
])
}
}

module "checklist-folder-1" {
source = "../../../modules/folder"
for_each = {
Expand Down

0 comments on commit 8947b20

Please sign in to comment.