Skip to content

Commit

Permalink
Update resource-group module to support optional attributes (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
posquit0 authored Sep 2, 2023
1 parent d160603 commit 99a4896
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
6 changes: 3 additions & 3 deletions modules/resource-group/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ This module creates following resources.

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.1 |
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.5 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.14 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | 4.16.0 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.15.0 |

## Modules

Expand All @@ -35,7 +35,7 @@ No modules.
| <a name="input_name"></a> [name](#input\_name) | (Required) A name to identify the resource group. A resource group name can have a maximum of 127 characters, including letters, numbers, hyphens, dots, and underscores. The name cannot start with `AWS` or `aws`. | `string` | n/a | yes |
| <a name="input_description"></a> [description](#input\_description) | (Optional) The description of the resource group. | `string` | `"Managed by Terraform."` | no |
| <a name="input_module_tags_enabled"></a> [module\_tags\_enabled](#input\_module\_tags\_enabled) | (Optional) Whether to create AWS Resource Tags for the module informations. | `bool` | `true` | no |
| <a name="input_query"></a> [query](#input\_query) | (Optional) A configuration for the actual query used to match against resources. It supports `resource_types` and `resource_tags`. `query` block as defined below.<br> (Required) `resource_tags` - A map of key/value pairs that are compared to the tags attached to resources.<br> (Optional) `resource_types` - A list of resource-type specification strings with `AWS::service-id::resource-type` format. Limit the results to only those resource types that match the filter. Specify `AWS::AllSupported` to include resources of any resources that are currently supported by Resource Group. | `any` | `{}` | no |
| <a name="input_query"></a> [query](#input\_query) | (Optional) A configuration for the actual query used to match against resources. It supports `resource_types` and `resource_tags`. `query` block as defined below.<br> (Optional) `resource_tags` - A map of key/value pairs that are compared to the tags attached to resources.<br> (Optional) `resource_types` - A list of resource-type specification strings with `AWS::service-id::resource-type` format. Limit the results to only those resource types that match the filter. Specify `AWS::AllSupported` to include resources of any resources that are currently supported by Resource Group. | <pre>object({<br> resource_tags = optional(map(string), {})<br> resource_types = optional(list(string), ["AWS::AllSupported"])<br> })</pre> | `{}` | no |
| <a name="input_tags"></a> [tags](#input\_tags) | (Optional) A map of tags to add to all resources. | `map(string)` | `{}` | no |

## Outputs
Expand Down
4 changes: 2 additions & 2 deletions modules/resource-group/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ locals {

locals {
filters = [
for key, value in try(var.query.resource_tags, {}) : {
for key, value in var.query.resource_tags : {
"Key" = key
"Values" = flatten([value])
}
]
query = <<-JSON
{
"ResourceTypeFilters": ${jsonencode(try(var.query.resource_types, ["AWS::AllSupported"]))},
"ResourceTypeFilters": ${jsonencode(var.query.resource_types)},
"TagFilters": ${jsonencode(local.filters)}
}
JSON
Expand Down
4 changes: 2 additions & 2 deletions modules/resource-group/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ output "description" {

output "resource_types" {
description = "The resource types used by the resource group to query resources."
value = try(var.query.resource_types, ["AWS::AllSupported"])
value = var.query.resource_types
}

output "resource_tags" {
description = "The resource tags used by the resource group to query resources."
value = try(var.query.resource_tags, {})
value = var.query.resource_tags
}
14 changes: 11 additions & 3 deletions modules/resource-group/variables.tf
Original file line number Diff line number Diff line change
@@ -1,32 +1,40 @@
variable "name" {
description = "(Required) A name to identify the resource group. A resource group name can have a maximum of 127 characters, including letters, numbers, hyphens, dots, and underscores. The name cannot start with `AWS` or `aws`."
type = string
nullable = false
}

variable "description" {
description = "(Optional) The description of the resource group."
type = string
default = "Managed by Terraform."
nullable = false
}

variable "query" {
description = <<EOF
(Optional) A configuration for the actual query used to match against resources. It supports `resource_types` and `resource_tags`. `query` block as defined below.
(Required) `resource_tags` - A map of key/value pairs that are compared to the tags attached to resources.
(Optional) `resource_tags` - A map of key/value pairs that are compared to the tags attached to resources.
(Optional) `resource_types` - A list of resource-type specification strings with `AWS::service-id::resource-type` format. Limit the results to only those resource types that match the filter. Specify `AWS::AllSupported` to include resources of any resources that are currently supported by Resource Group.
EOF
type = any
default = {}
type = object({
resource_tags = optional(map(string), {})
resource_types = optional(list(string), ["AWS::AllSupported"])
})
default = {}
nullable = false
}

variable "tags" {
description = "(Optional) A map of tags to add to all resources."
type = map(string)
default = {}
nullable = false
}

variable "module_tags_enabled" {
description = "(Optional) Whether to create AWS Resource Tags for the module informations."
type = bool
default = true
nullable = false
}
2 changes: 1 addition & 1 deletion modules/resource-group/versions.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
terraform {
required_version = ">= 1.1"
required_version = ">= 1.5"

required_providers {
aws = {
Expand Down

0 comments on commit 99a4896

Please sign in to comment.