From 271cf396a6d98fc52124bc9ddc23425740d436d4 Mon Sep 17 00:00:00 2001 From: Lucas Campos Vieira Date: Fri, 29 Sep 2023 12:11:38 -0300 Subject: [PATCH] agrupa os recursos e define o output do projeto --- modules/groupResources/groupByKind/outputs.tf | 21 +++++++++++++++++++ .../groupByKind/resources/outputs.tf | 6 ++++++ .../groupByKind/resources/variables.tf | 11 ++++++++++ .../groupResources/groupByKind/variables.tf | 7 +++++++ modules/groupResources/outputs.tf | 19 +++++++++++++++++ modules/groupResources/variables.tf | 3 +++ outputs.tf | 9 ++++++++ 7 files changed, 76 insertions(+) create mode 100644 modules/groupResources/groupByKind/outputs.tf create mode 100644 modules/groupResources/groupByKind/resources/outputs.tf create mode 100644 modules/groupResources/groupByKind/resources/variables.tf create mode 100644 modules/groupResources/groupByKind/variables.tf create mode 100644 modules/groupResources/outputs.tf create mode 100644 modules/groupResources/variables.tf create mode 100644 outputs.tf diff --git a/modules/groupResources/groupByKind/outputs.tf b/modules/groupResources/groupByKind/outputs.tf new file mode 100644 index 0000000..ad2e19b --- /dev/null +++ b/modules/groupResources/groupByKind/outputs.tf @@ -0,0 +1,21 @@ +locals { + kinds = distinct([ + for resource in var.resources : resource.kind + if resource.apiGroup == var.apiGroup + ]) +} + +module "resources" { + source = "./resources/" + for_each = toset(local.kinds) + + apiGroup = var.apiGroup + kind = each.key + resources = var.resources +} + +output "kinds" { + value = { + for kind, result in module.resources : kind => result.resources + } +} diff --git a/modules/groupResources/groupByKind/resources/outputs.tf b/modules/groupResources/groupByKind/resources/outputs.tf new file mode 100644 index 0000000..55b4821 --- /dev/null +++ b/modules/groupResources/groupByKind/resources/outputs.tf @@ -0,0 +1,6 @@ +output "resources" { + value = { + for resource in var.resources : resource.metadata.name => resource + if resource.apiGroup == var.apiGroup && resource.kind == var.kind + } +} diff --git a/modules/groupResources/groupByKind/resources/variables.tf b/modules/groupResources/groupByKind/resources/variables.tf new file mode 100644 index 0000000..63ba89f --- /dev/null +++ b/modules/groupResources/groupByKind/resources/variables.tf @@ -0,0 +1,11 @@ +variable "apiGroup" { + type = string +} + +variable "kind" { + type = string +} + +variable "resources" { + type = any +} diff --git a/modules/groupResources/groupByKind/variables.tf b/modules/groupResources/groupByKind/variables.tf new file mode 100644 index 0000000..0091d26 --- /dev/null +++ b/modules/groupResources/groupByKind/variables.tf @@ -0,0 +1,7 @@ +variable "apiGroup" { + type = string +} + +variable "resources" { + type = any +} diff --git a/modules/groupResources/outputs.tf b/modules/groupResources/outputs.tf new file mode 100644 index 0000000..f682e87 --- /dev/null +++ b/modules/groupResources/outputs.tf @@ -0,0 +1,19 @@ +locals { + apiGroups = distinct([ + for resource in var.resources : resource.apiGroup + ]) +} + +module "kinds" { + source = "./groupByKind/" + for_each = toset(local.apiGroups) + + apiGroup = each.key + resources = var.resources +} + +output "groupedResources" { + value = { + for apiGroup, result in module.kinds : apiGroup => result.kinds + } +} diff --git a/modules/groupResources/variables.tf b/modules/groupResources/variables.tf new file mode 100644 index 0000000..9148e18 --- /dev/null +++ b/modules/groupResources/variables.tf @@ -0,0 +1,3 @@ +variable "resources" { + type = any +} diff --git a/outputs.tf b/outputs.tf new file mode 100644 index 0000000..1e69fcb --- /dev/null +++ b/outputs.tf @@ -0,0 +1,9 @@ +module "groupResources" { + source = "./modules/groupResources/" + + resources = module.resources[*].instance +} + +output "resources" { + value = module.groupResources.groupedResources +}