Implement precondition check in project factory to ensure declared templates exist (#3493)
* pf template check * tfdoc * test inventories
This commit is contained in:
committed by
GitHub
parent
90b6e312d3
commit
f9f015a692
@@ -28,7 +28,8 @@ locals {
|
||||
_projects_input = {
|
||||
for k, v in merge(local._folder_projects_raw, local._projects_raw) :
|
||||
basename(k) => merge(
|
||||
try(local._templates_raw[v.project_template], {}), v
|
||||
try(local._templates_raw[v.project_template], {}),
|
||||
v
|
||||
)
|
||||
}
|
||||
_projects_path = try(
|
||||
@@ -57,6 +58,19 @@ locals {
|
||||
projects_input = merge(var.projects, local._projects_output)
|
||||
}
|
||||
|
||||
resource "terraform_data" "project-preconditions" {
|
||||
lifecycle {
|
||||
precondition {
|
||||
condition = alltrue([
|
||||
for k, v in local._projects_input :
|
||||
try(v.project_template, null) == null ||
|
||||
lookup(local._templates_raw, v.project_template, null) != null
|
||||
])
|
||||
error_message = "Missing project templates referenced in projects."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module "projects" {
|
||||
source = "../project"
|
||||
for_each = local.projects_input
|
||||
|
||||
Reference in New Issue
Block a user