Skip to content

Commit

Permalink
agrupa os recursos e define o output do projeto
Browse files Browse the repository at this point in the history
  • Loading branch information
lukerops committed Sep 29, 2023
1 parent 24b21e1 commit 271cf39
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 0 deletions.
21 changes: 21 additions & 0 deletions modules/groupResources/groupByKind/outputs.tf
Original file line number Diff line number Diff line change
@@ -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
}
}
6 changes: 6 additions & 0 deletions modules/groupResources/groupByKind/resources/outputs.tf
Original file line number Diff line number Diff line change
@@ -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
}
}
11 changes: 11 additions & 0 deletions modules/groupResources/groupByKind/resources/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
variable "apiGroup" {
type = string
}

variable "kind" {
type = string
}

variable "resources" {
type = any
}
7 changes: 7 additions & 0 deletions modules/groupResources/groupByKind/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
variable "apiGroup" {
type = string
}

variable "resources" {
type = any
}
19 changes: 19 additions & 0 deletions modules/groupResources/outputs.tf
Original file line number Diff line number Diff line change
@@ -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
}
}
3 changes: 3 additions & 0 deletions modules/groupResources/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
variable "resources" {
type = any
}
9 changes: 9 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module "groupResources" {
source = "./modules/groupResources/"

resources = module.resources[*].instance
}

output "resources" {
value = module.groupResources.groupedResources
}

0 comments on commit 271cf39

Please sign in to comment.