diff --git a/customResourceDefinitions.tf b/customResourceDefinitions.tf index ffc93d7..58caeb8 100644 --- a/customResourceDefinitions.tf +++ b/customResourceDefinitions.tf @@ -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] diff --git a/manifests.tf b/manifests.tf index f048b46..283095c 100644 --- a/manifests.tf +++ b/manifests.tf @@ -11,7 +11,7 @@ locals { } module "manifests" { - source = "./validations/manifest/" + source = "./modules/manifest/" count = length(local.yamls) path = local.yamls[count.index].path diff --git a/validations/CustomResourceDefinition/v1alpha1/outputs.tf b/modules/CustomResourceDefinition/v1alpha1/outputs.tf similarity index 100% rename from validations/CustomResourceDefinition/v1alpha1/outputs.tf rename to modules/CustomResourceDefinition/v1alpha1/outputs.tf diff --git a/validations/CustomResourceDefinition/v1alpha1/variables.tf b/modules/CustomResourceDefinition/v1alpha1/variables.tf similarity index 100% rename from validations/CustomResourceDefinition/v1alpha1/variables.tf rename to modules/CustomResourceDefinition/v1alpha1/variables.tf diff --git a/validations/CustomResourceDefinition/v1alpha1/version/outputs.tf b/modules/CustomResourceDefinition/v1alpha1/version/outputs.tf similarity index 100% rename from validations/CustomResourceDefinition/v1alpha1/version/outputs.tf rename to modules/CustomResourceDefinition/v1alpha1/version/outputs.tf diff --git a/validations/CustomResourceDefinition/v1alpha1/version/property/array/outputs.tf b/modules/CustomResourceDefinition/v1alpha1/version/property/array/outputs.tf similarity index 100% rename from validations/CustomResourceDefinition/v1alpha1/version/property/array/outputs.tf rename to modules/CustomResourceDefinition/v1alpha1/version/property/array/outputs.tf diff --git a/validations/CustomResourceDefinition/v1alpha1/version/property/array/variables.tf b/modules/CustomResourceDefinition/v1alpha1/version/property/array/variables.tf similarity index 100% rename from validations/CustomResourceDefinition/v1alpha1/version/property/array/variables.tf rename to modules/CustomResourceDefinition/v1alpha1/version/property/array/variables.tf diff --git a/validations/CustomResourceDefinition/v1alpha1/version/property/bool/outputs.tf b/modules/CustomResourceDefinition/v1alpha1/version/property/bool/outputs.tf similarity index 100% rename from validations/CustomResourceDefinition/v1alpha1/version/property/bool/outputs.tf rename to modules/CustomResourceDefinition/v1alpha1/version/property/bool/outputs.tf diff --git a/validations/CustomResourceDefinition/v1alpha1/version/property/bool/variables.tf b/modules/CustomResourceDefinition/v1alpha1/version/property/bool/variables.tf similarity index 100% rename from validations/CustomResourceDefinition/v1alpha1/version/property/bool/variables.tf rename to modules/CustomResourceDefinition/v1alpha1/version/property/bool/variables.tf diff --git a/validations/CustomResourceDefinition/v1alpha1/version/property/integer/outputs.tf b/modules/CustomResourceDefinition/v1alpha1/version/property/integer/outputs.tf similarity index 100% rename from validations/CustomResourceDefinition/v1alpha1/version/property/integer/outputs.tf rename to modules/CustomResourceDefinition/v1alpha1/version/property/integer/outputs.tf diff --git a/validations/CustomResourceDefinition/v1alpha1/version/property/integer/variables.tf b/modules/CustomResourceDefinition/v1alpha1/version/property/integer/variables.tf similarity index 100% rename from validations/CustomResourceDefinition/v1alpha1/version/property/integer/variables.tf rename to modules/CustomResourceDefinition/v1alpha1/version/property/integer/variables.tf diff --git a/validations/CustomResourceDefinition/v1alpha1/version/property/object/outputs.tf b/modules/CustomResourceDefinition/v1alpha1/version/property/object/outputs.tf similarity index 100% rename from validations/CustomResourceDefinition/v1alpha1/version/property/object/outputs.tf rename to modules/CustomResourceDefinition/v1alpha1/version/property/object/outputs.tf diff --git a/validations/CustomResourceDefinition/v1alpha1/version/property/object/property/outputs.tf b/modules/CustomResourceDefinition/v1alpha1/version/property/object/property/outputs.tf similarity index 100% rename from validations/CustomResourceDefinition/v1alpha1/version/property/object/property/outputs.tf rename to modules/CustomResourceDefinition/v1alpha1/version/property/object/property/outputs.tf diff --git a/validations/CustomResourceDefinition/v1alpha1/version/property/object/property/variables.tf b/modules/CustomResourceDefinition/v1alpha1/version/property/object/property/variables.tf similarity index 100% rename from validations/CustomResourceDefinition/v1alpha1/version/property/object/property/variables.tf rename to modules/CustomResourceDefinition/v1alpha1/version/property/object/property/variables.tf diff --git a/validations/CustomResourceDefinition/v1alpha1/version/property/object/variables.tf b/modules/CustomResourceDefinition/v1alpha1/version/property/object/variables.tf similarity index 100% rename from validations/CustomResourceDefinition/v1alpha1/version/property/object/variables.tf rename to modules/CustomResourceDefinition/v1alpha1/version/property/object/variables.tf diff --git a/validations/CustomResourceDefinition/v1alpha1/version/property/outputs.tf b/modules/CustomResourceDefinition/v1alpha1/version/property/outputs.tf similarity index 100% rename from validations/CustomResourceDefinition/v1alpha1/version/property/outputs.tf rename to modules/CustomResourceDefinition/v1alpha1/version/property/outputs.tf diff --git a/validations/CustomResourceDefinition/v1alpha1/version/property/string/outputs.tf b/modules/CustomResourceDefinition/v1alpha1/version/property/string/outputs.tf similarity index 100% rename from validations/CustomResourceDefinition/v1alpha1/version/property/string/outputs.tf rename to modules/CustomResourceDefinition/v1alpha1/version/property/string/outputs.tf diff --git a/validations/CustomResourceDefinition/v1alpha1/version/property/string/variables.tf b/modules/CustomResourceDefinition/v1alpha1/version/property/string/variables.tf similarity index 100% rename from validations/CustomResourceDefinition/v1alpha1/version/property/string/variables.tf rename to modules/CustomResourceDefinition/v1alpha1/version/property/string/variables.tf diff --git a/validations/CustomResourceDefinition/v1alpha1/version/property/variables.tf b/modules/CustomResourceDefinition/v1alpha1/version/property/variables.tf similarity index 100% rename from validations/CustomResourceDefinition/v1alpha1/version/property/variables.tf rename to modules/CustomResourceDefinition/v1alpha1/version/property/variables.tf diff --git a/validations/CustomResourceDefinition/v1alpha1/version/variables.tf b/modules/CustomResourceDefinition/v1alpha1/version/variables.tf similarity index 100% rename from validations/CustomResourceDefinition/v1alpha1/version/variables.tf rename to modules/CustomResourceDefinition/v1alpha1/version/variables.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/validations/manifest/outputs.tf b/modules/manifest/outputs.tf similarity index 100% rename from validations/manifest/outputs.tf rename to modules/manifest/outputs.tf diff --git a/validations/manifest/variables.tf b/modules/manifest/variables.tf similarity index 100% rename from validations/manifest/variables.tf rename to modules/manifest/variables.tf diff --git a/validations/resource/outputs.tf b/modules/resource/outputs.tf similarity index 100% rename from validations/resource/outputs.tf rename to modules/resource/outputs.tf diff --git a/validations/resource/property/array/outputs.tf b/modules/resource/property/array/outputs.tf similarity index 100% rename from validations/resource/property/array/outputs.tf rename to modules/resource/property/array/outputs.tf diff --git a/validations/resource/property/array/property/outputs.tf b/modules/resource/property/array/property/outputs.tf similarity index 100% rename from validations/resource/property/array/property/outputs.tf rename to modules/resource/property/array/property/outputs.tf diff --git a/validations/resource/property/array/property/variables.tf b/modules/resource/property/array/property/variables.tf similarity index 100% rename from validations/resource/property/array/property/variables.tf rename to modules/resource/property/array/property/variables.tf diff --git a/validations/resource/property/array/variables.tf b/modules/resource/property/array/variables.tf similarity index 100% rename from validations/resource/property/array/variables.tf rename to modules/resource/property/array/variables.tf diff --git a/validations/resource/property/bool/outputs.tf b/modules/resource/property/bool/outputs.tf similarity index 100% rename from validations/resource/property/bool/outputs.tf rename to modules/resource/property/bool/outputs.tf diff --git a/validations/resource/property/bool/variables.tf b/modules/resource/property/bool/variables.tf similarity index 100% rename from validations/resource/property/bool/variables.tf rename to modules/resource/property/bool/variables.tf diff --git a/validations/resource/property/integer/outputs.tf b/modules/resource/property/integer/outputs.tf similarity index 100% rename from validations/resource/property/integer/outputs.tf rename to modules/resource/property/integer/outputs.tf diff --git a/validations/resource/property/integer/variables.tf b/modules/resource/property/integer/variables.tf similarity index 100% rename from validations/resource/property/integer/variables.tf rename to modules/resource/property/integer/variables.tf diff --git a/validations/resource/property/object/outputs.tf b/modules/resource/property/object/outputs.tf similarity index 100% rename from validations/resource/property/object/outputs.tf rename to modules/resource/property/object/outputs.tf diff --git a/validations/resource/property/object/property/outputs.tf b/modules/resource/property/object/property/outputs.tf similarity index 100% rename from validations/resource/property/object/property/outputs.tf rename to modules/resource/property/object/property/outputs.tf diff --git a/validations/resource/property/object/property/variables.tf b/modules/resource/property/object/property/variables.tf similarity index 100% rename from validations/resource/property/object/property/variables.tf rename to modules/resource/property/object/property/variables.tf diff --git a/validations/resource/property/object/variables.tf b/modules/resource/property/object/variables.tf similarity index 100% rename from validations/resource/property/object/variables.tf rename to modules/resource/property/object/variables.tf diff --git a/validations/resource/property/outputs.tf b/modules/resource/property/outputs.tf similarity index 100% rename from validations/resource/property/outputs.tf rename to modules/resource/property/outputs.tf diff --git a/validations/resource/property/string/outputs.tf b/modules/resource/property/string/outputs.tf similarity index 100% rename from validations/resource/property/string/outputs.tf rename to modules/resource/property/string/outputs.tf diff --git a/validations/resource/property/string/variables.tf b/modules/resource/property/string/variables.tf similarity index 100% rename from validations/resource/property/string/variables.tf rename to modules/resource/property/string/variables.tf diff --git a/validations/resource/property/variables.tf b/modules/resource/property/variables.tf similarity index 100% rename from validations/resource/property/variables.tf rename to modules/resource/property/variables.tf diff --git a/validations/resource/variables.tf b/modules/resource/variables.tf similarity index 100% rename from validations/resource/variables.tf rename to modules/resource/variables.tf 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 +} diff --git a/resources.tf b/resources.tf index 545f39b..d4e30f7 100644 --- a/resources.tf +++ b/resources.tf @@ -6,7 +6,7 @@ locals { } module "resources" { - source = "./validations/resource/" + source = "./modules/resource/" count = length(local.resource_manifests) manifest = local.resource_manifests[count.index]