Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions modules/s3-archive-bucket/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,19 @@ output "logging" {
}
}
}

output "resource_group" {
description = "The resource group created to manage resources in this module."
value = merge(
{
enabled = var.resource_group.enabled && var.module_tags_enabled
},
(var.resource_group.enabled && var.module_tags_enabled
? {
arn = module.resource_group[0].arn
name = module.resource_group[0].name
}
: {}
)
)
Comment on lines +110 to +121

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current implementation of the resource_group output produces an object with a variable shape. When the resource group is disabled, the output object will be {"enabled": false}, but when enabled, it will include arn and name. This requires consumers of the module to check for the existence of these attributes, which can be error-prone.

To improve the module's usability, it's better to provide a consistent structure for the output, where arn and name are always present, but have null values when the resource group is not created. This makes the output predictable and easier to work with.

  value = (var.resource_group.enabled && var.module_tags_enabled) ? {
    enabled = true
    arn     = module.resource_group[0].arn
    name    = module.resource_group[0].name
  } : {
    enabled = false
    arn     = null
    name    = null
  }

}
10 changes: 5 additions & 5 deletions modules/s3-archive-bucket/resource-group.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
locals {
resource_group_name = (var.resource_group_name != ""
? var.resource_group_name
resource_group_name = (var.resource_group.name != ""
? var.resource_group.name
: join(".", [
local.metadata.package,
local.metadata.module,
Expand All @@ -12,12 +12,12 @@ locals {

module "resource_group" {
source = "tedilabs/misc/aws//modules/resource-group"
version = "~> 0.10.0"
version = "~> 0.12.0"

count = (var.resource_group_enabled && var.module_tags_enabled) ? 1 : 0
count = (var.resource_group.enabled && var.module_tags_enabled) ? 1 : 0

name = local.resource_group_name
description = var.resource_group_description
description = var.resource_group.description

query = {
resource_tags = local.module_tags
Expand Down
29 changes: 15 additions & 14 deletions modules/s3-archive-bucket/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -181,20 +181,21 @@ variable "module_tags_enabled" {
# Resource Group
###################################################

variable "resource_group_enabled" {
description = "(Optional) Whether to create Resource Group to find and group AWS resources which are created by this module."
type = bool
default = true
}

variable "resource_group_name" {
description = "(Optional) The name of 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
default = ""
}

variable "resource_group_description" {
description = "(Optional) The description of Resource Group."
type = string
default = "Managed by Terraform."

variable "resource_group" {
description = <<EOF
(Optional) A configurations of Resource Group for this module. `resource_group` as defined below.
(Optional) `enabled` - Whether to create Resource Group to find and group AWS resources which are created by this module. Defaults to `true`.
(Optional) `name` - The name of 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`. If not provided, a name will be generated using the module name and instance name.
(Optional) `description` - The description of Resource Group. Defaults to `Managed by Terraform.`.
EOF
type = object({
enabled = optional(bool, true)
name = optional(string, "")
description = optional(string, "Managed by Terraform.")
})
default = {}
nullable = false
}
16 changes: 16 additions & 0 deletions modules/sqs-aws-event-queue/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,19 @@ output "arn" {
description = "The ARN of the SQS queue."
value = aws_sqs_queue.this.arn
}

output "resource_group" {
description = "The resource group created to manage resources in this module."
value = merge(
{
enabled = var.resource_group.enabled && var.module_tags_enabled
},
(var.resource_group.enabled && var.module_tags_enabled
? {
arn = module.resource_group[0].arn
name = module.resource_group[0].name
}
: {}
)
)
Comment on lines +18 to +29

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current implementation of the resource_group output produces an object with a variable shape. When the resource group is disabled, the output object will be {"enabled": false}, but when enabled, it will include arn and name. This requires consumers of the module to check for the existence of these attributes, which can be error-prone.

To improve the module's usability, it's better to provide a consistent structure for the output, where arn and name are always present, but have null values when the resource group is not created. This makes the output predictable and easier to work with.

  value = (var.resource_group.enabled && var.module_tags_enabled) ? {
    enabled = true
    arn     = module.resource_group[0].arn
    name    = module.resource_group[0].name
  } : {
    enabled = false
    arn     = null
    name    = null
  }

}
10 changes: 5 additions & 5 deletions modules/sqs-aws-event-queue/resource-group.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
locals {
resource_group_name = (var.resource_group_name != ""
? var.resource_group_name
resource_group_name = (var.resource_group.name != ""
? var.resource_group.name
: join(".", [
local.metadata.package,
local.metadata.module,
Expand All @@ -12,12 +12,12 @@ locals {

module "resource_group" {
source = "tedilabs/misc/aws//modules/resource-group"
version = "~> 0.10.0"
version = "~> 0.12.0"

count = (var.resource_group_enabled && var.module_tags_enabled) ? 1 : 0
count = (var.resource_group.enabled && var.module_tags_enabled) ? 1 : 0

name = local.resource_group_name
description = var.resource_group_description
description = var.resource_group.description

query = {
resource_tags = local.module_tags
Expand Down
29 changes: 15 additions & 14 deletions modules/sqs-aws-event-queue/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,21 @@ variable "module_tags_enabled" {
# Resource Group
###################################################

variable "resource_group_enabled" {
description = "Whether to create Resource Group to find and group AWS resources which are created by this module."
type = bool
default = true
}

variable "resource_group_name" {
description = "The name of 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
default = ""
}

variable "resource_group_description" {
description = "The description of Resource Group."
type = string
default = "Managed by Terraform."

variable "resource_group" {
description = <<EOF
(Optional) A configurations of Resource Group for this module. `resource_group` as defined below.
(Optional) `enabled` - Whether to create Resource Group to find and group AWS resources which are created by this module. Defaults to `true`.
(Optional) `name` - The name of 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`. If not provided, a name will be generated using the module name and instance name.
(Optional) `description` - The description of Resource Group. Defaults to `Managed by Terraform.`.
EOF
type = object({
enabled = optional(bool, true)
name = optional(string, "")
description = optional(string, "Managed by Terraform.")
})
default = {}
nullable = false
}