Skip to content

Commit

Permalink
Merge pull request #8 from lukerops/refactor/output
Browse files Browse the repository at this point in the history
Modifica output do projeto
  • Loading branch information
lukerops authored Sep 29, 2023
2 parents a63ea70 + 271cf39 commit e702d97
Show file tree
Hide file tree
Showing 48 changed files with 79 additions and 3 deletions.
2 changes: 1 addition & 1 deletion customResourceDefinitions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ locals {
}

module "custom_resource_definitions_v1alpha1" {
source = "./validations/CustomResourceDefinition/v1alpha1/"
source = "./modules/CustomResourceDefinition/v1alpha1/"
count = length(local.v1alpha1_manifests)

manifest = local.v1alpha1_manifests[count.index]
Expand Down
2 changes: 1 addition & 1 deletion manifests.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ locals {
}

module "manifests" {
source = "./validations/manifest/"
source = "./modules/manifest/"
count = length(local.yamls)

path = local.yamls[count.index].path
Expand Down
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
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
}
2 changes: 1 addition & 1 deletion resources.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ locals {
}

module "resources" {
source = "./validations/resource/"
source = "./modules/resource/"
count = length(local.resource_manifests)

manifest = local.resource_manifests[count.index]
Expand Down

0 comments on commit e702d97

Please sign in to comment.