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/elasticache-redis-cluster/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,19 @@ output "endpoints" {
configuration = aws_elasticache_replication_group.this.configuration_endpoint_address
}
}

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 +187 to +198

Choose a reason for hiding this comment

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

medium

This output's value can be simplified. Using merge with a conditional map makes the logic a bit complex and results in an object with a non-static shape (the arn and name keys are conditional). It's generally better for module outputs to have a consistent structure.

Assuming you create the local.is_resource_group_created variable as suggested for resource-group.tf, you can simplify this output to be more readable and consistent.

  value = {
    enabled = local.is_resource_group_created
    arn     = local.is_resource_group_created ? module.resource_group[0].arn : null
    name    = local.is_resource_group_created ? module.resource_group[0].name : null
  }

}
10 changes: 5 additions & 5 deletions modules/elasticache-redis-cluster/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

Choose a reason for hiding this comment

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

medium

The condition var.resource_group.enabled && var.module_tags_enabled is also used in outputs.tf. To avoid repetition and improve maintainability, consider defining it as a local variable within the locals block at the top of this file.

For example:

locals {
  ...
  is_resource_group_created = var.resource_group.enabled && var.module_tags_enabled
}

Then you can simplify this line to use the new local.

  count = local.is_resource_group_created ? 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
32 changes: 15 additions & 17 deletions modules/elasticache-redis-cluster/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -377,23 +377,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
nullable = false
}

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 = ""
nullable = false
}

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

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/elasticache-redis-user-group/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,19 @@ output "users" {
description = "The list of user IDs that belong to the user group."
value = values(aws_elasticache_user_group_association.this)[*].user_id
}

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 +28 to +39

Choose a reason for hiding this comment

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

medium

This output's value can be simplified. Using merge with a conditional map makes the logic a bit complex and results in an object with a non-static shape (the arn and name keys are conditional). It's generally better for module outputs to have a consistent structure.

Assuming you create the local.is_resource_group_created variable as suggested for resource-group.tf, you can simplify this output to be more readable and consistent.

  value = {
    enabled = local.is_resource_group_created
    arn     = local.is_resource_group_created ? module.resource_group[0].arn : null
    name    = local.is_resource_group_created ? module.resource_group[0].name : null
  }

}
10 changes: 5 additions & 5 deletions modules/elasticache-redis-user-group/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

Choose a reason for hiding this comment

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

medium

The condition var.resource_group.enabled && var.module_tags_enabled is also used in outputs.tf. To avoid repetition and improve maintainability, consider defining it as a local variable within the locals block at the top of this file.

For example:

locals {
  ...
  is_resource_group_created = var.resource_group.enabled && var.module_tags_enabled
}

Then you can simplify this line to use the new local.

  count = local.is_resource_group_created ? 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
32 changes: 15 additions & 17 deletions modules/elasticache-redis-user-group/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,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
nullable = false
}

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 = ""
nullable = false
}

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

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/elasticache-redis-user/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,19 @@ output "password_required" {
description = "Whether a password is required for this user."
value = !aws_elasticache_user.this.no_password_required
}

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 +28 to +39

Choose a reason for hiding this comment

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

medium

This output's value can be simplified. Using merge with a conditional map makes the logic a bit complex and results in an object with a non-static shape (the arn and name keys are conditional). It's generally better for module outputs to have a consistent structure.

Assuming you create the local.is_resource_group_created variable as suggested for resource-group.tf, you can simplify this output to be more readable and consistent.

  value = {
    enabled = local.is_resource_group_created
    arn     = local.is_resource_group_created ? module.resource_group[0].arn : null
    name    = local.is_resource_group_created ? module.resource_group[0].name : null
  }

}
10 changes: 5 additions & 5 deletions modules/elasticache-redis-user/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

Choose a reason for hiding this comment

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

medium

The condition var.resource_group.enabled && var.module_tags_enabled is also used in outputs.tf. To avoid repetition and improve maintainability, consider defining it as a local variable within the locals block at the top of this file.

For example:

locals {
  ...
  is_resource_group_created = var.resource_group.enabled && var.module_tags_enabled
}

Then you can simplify this line to use the new local.

  count = local.is_resource_group_created ? 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
32 changes: 15 additions & 17 deletions modules/elasticache-redis-user/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,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
nullable = false
}

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 = ""
nullable = false
}

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

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
}