Skip to content

Commit 70ce3f2

Browse files
authored
feat: improve how to use resource_group in modules (#35)
1 parent d8ade96 commit 70ce3f2

File tree

9 files changed

+108
-66
lines changed

9 files changed

+108
-66
lines changed

modules/cloudwatch-log-group/outputs.tf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,19 @@ output "metric_filters" {
5454
}
5555
}
5656
}
57+
58+
output "resource_group" {
59+
description = "The resource group created to manage resources in this module."
60+
value = merge(
61+
{
62+
enabled = var.resource_group.enabled && var.module_tags_enabled
63+
},
64+
(var.resource_group.enabled && var.module_tags_enabled
65+
? {
66+
arn = module.resource_group[0].arn
67+
name = module.resource_group[0].name
68+
}
69+
: {}
70+
)
71+
)
72+
}

modules/cloudwatch-log-group/resource-group.tf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
locals {
2-
resource_group_name = (var.resource_group_name != ""
3-
? var.resource_group_name
2+
resource_group_name = (var.resource_group.name != ""
3+
? var.resource_group.name
44
: join(".", [
55
local.metadata.package,
66
local.metadata.module,
@@ -12,12 +12,12 @@ locals {
1212

1313
module "resource_group" {
1414
source = "tedilabs/misc/aws//modules/resource-group"
15-
version = "~> 0.10.0"
15+
version = "~> 0.12.0"
1616

17-
count = (var.resource_group_enabled && var.module_tags_enabled) ? 1 : 0
17+
count = (var.resource_group.enabled && var.module_tags_enabled) ? 1 : 0
1818

1919
name = local.resource_group_name
20-
description = var.resource_group_description
20+
description = var.resource_group.description
2121

2222
query = {
2323
resource_tags = local.module_tags

modules/cloudwatch-log-group/variables.tf

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -79,23 +79,21 @@ variable "module_tags_enabled" {
7979
# Resource Group
8080
###################################################
8181

82-
variable "resource_group_enabled" {
83-
description = "(Optional) Whether to create Resource Group to find and group AWS resources which are created by this module."
84-
type = bool
85-
default = true
86-
nullable = false
87-
}
8882

89-
variable "resource_group_name" {
90-
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`."
91-
type = string
92-
default = ""
93-
nullable = false
94-
}
9583

96-
variable "resource_group_description" {
97-
description = "(Optional) The description of Resource Group."
98-
type = string
99-
default = "Managed by Terraform."
100-
nullable = false
84+
85+
variable "resource_group" {
86+
description = <<EOF
87+
(Optional) A configurations of Resource Group for this module. `resource_group` as defined below.
88+
(Optional) `enabled` - Whether to create Resource Group to find and group AWS resources which are created by this module. Defaults to `true`.
89+
(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.
90+
(Optional) `description` - The description of Resource Group. Defaults to `Managed by Terraform.`.
91+
EOF
92+
type = object({
93+
enabled = optional(bool, true)
94+
name = optional(string, "")
95+
description = optional(string, "Managed by Terraform.")
96+
})
97+
default = {}
98+
nullable = false
10199
}

modules/cloudwatch-oam-link/outputs.tf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,19 @@ output "metric_configuration" {
4040
description = "A configuration for filtering which metric namespaces are to be shared from the source account to the monitoring account."
4141
value = var.metric_configuration
4242
}
43+
44+
output "resource_group" {
45+
description = "The resource group created to manage resources in this module."
46+
value = merge(
47+
{
48+
enabled = var.resource_group.enabled && var.module_tags_enabled
49+
},
50+
(var.resource_group.enabled && var.module_tags_enabled
51+
? {
52+
arn = module.resource_group[0].arn
53+
name = module.resource_group[0].name
54+
}
55+
: {}
56+
)
57+
)
58+
}

modules/cloudwatch-oam-link/resource-group.tf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
locals {
2-
resource_group_name = (var.resource_group_name != ""
3-
? var.resource_group_name
2+
resource_group_name = (var.resource_group.name != ""
3+
? var.resource_group.name
44
: join(".", [
55
local.metadata.package,
66
local.metadata.module,
@@ -12,12 +12,12 @@ locals {
1212

1313
module "resource_group" {
1414
source = "tedilabs/misc/aws//modules/resource-group"
15-
version = "~> 0.10.0"
15+
version = "~> 0.12.0"
1616

17-
count = (var.resource_group_enabled && var.module_tags_enabled) ? 1 : 0
17+
count = (var.resource_group.enabled && var.module_tags_enabled) ? 1 : 0
1818

1919
name = local.resource_group_name
20-
description = var.resource_group_description
20+
description = var.resource_group.description
2121

2222
query = {
2323
resource_tags = local.module_tags

modules/cloudwatch-oam-link/variables.tf

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -80,23 +80,21 @@ variable "module_tags_enabled" {
8080
# Resource Group
8181
###################################################
8282

83-
variable "resource_group_enabled" {
84-
description = "(Optional) Whether to create Resource Group to find and group AWS resources which are created by this module."
85-
type = bool
86-
default = true
87-
nullable = false
88-
}
8983

90-
variable "resource_group_name" {
91-
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`."
92-
type = string
93-
default = ""
94-
nullable = false
95-
}
9684

97-
variable "resource_group_description" {
98-
description = "(Optional) The description of Resource Group."
99-
type = string
100-
default = "Managed by Terraform."
101-
nullable = false
85+
86+
variable "resource_group" {
87+
description = <<EOF
88+
(Optional) A configurations of Resource Group for this module. `resource_group` as defined below.
89+
(Optional) `enabled` - Whether to create Resource Group to find and group AWS resources which are created by this module. Defaults to `true`.
90+
(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.
91+
(Optional) `description` - The description of Resource Group. Defaults to `Managed by Terraform.`.
92+
EOF
93+
type = object({
94+
enabled = optional(bool, true)
95+
name = optional(string, "")
96+
description = optional(string, "Managed by Terraform.")
97+
})
98+
default = {}
99+
nullable = false
102100
}

modules/cloudwatch-oam-sink/outputs.tf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,19 @@ output "allowed_source_organization_paths" {
3232
description = "A list of the organization paths of AWS accounts allowed to share data with this monitoring account."
3333
value = var.allowed_source_organization_paths
3434
}
35+
36+
output "resource_group" {
37+
description = "The resource group created to manage resources in this module."
38+
value = merge(
39+
{
40+
enabled = var.resource_group.enabled && var.module_tags_enabled
41+
},
42+
(var.resource_group.enabled && var.module_tags_enabled
43+
? {
44+
arn = module.resource_group[0].arn
45+
name = module.resource_group[0].name
46+
}
47+
: {}
48+
)
49+
)
50+
}

modules/cloudwatch-oam-sink/resource-group.tf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
locals {
2-
resource_group_name = (var.resource_group_name != ""
3-
? var.resource_group_name
2+
resource_group_name = (var.resource_group.name != ""
3+
? var.resource_group.name
44
: join(".", [
55
local.metadata.package,
66
local.metadata.module,
@@ -12,12 +12,12 @@ locals {
1212

1313
module "resource_group" {
1414
source = "tedilabs/misc/aws//modules/resource-group"
15-
version = "~> 0.10.0"
15+
version = "~> 0.12.0"
1616

17-
count = (var.resource_group_enabled && var.module_tags_enabled) ? 1 : 0
17+
count = (var.resource_group.enabled && var.module_tags_enabled) ? 1 : 0
1818

1919
name = local.resource_group_name
20-
description = var.resource_group_description
20+
description = var.resource_group.description
2121

2222
query = {
2323
resource_tags = local.module_tags

modules/cloudwatch-oam-sink/variables.tf

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,23 +59,21 @@ variable "module_tags_enabled" {
5959
# Resource Group
6060
###################################################
6161

62-
variable "resource_group_enabled" {
63-
description = "(Optional) Whether to create Resource Group to find and group AWS resources which are created by this module."
64-
type = bool
65-
default = true
66-
nullable = false
67-
}
6862

69-
variable "resource_group_name" {
70-
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`."
71-
type = string
72-
default = ""
73-
nullable = false
74-
}
7563

76-
variable "resource_group_description" {
77-
description = "(Optional) The description of Resource Group."
78-
type = string
79-
default = "Managed by Terraform."
80-
nullable = false
64+
65+
variable "resource_group" {
66+
description = <<EOF
67+
(Optional) A configurations of Resource Group for this module. `resource_group` as defined below.
68+
(Optional) `enabled` - Whether to create Resource Group to find and group AWS resources which are created by this module. Defaults to `true`.
69+
(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.
70+
(Optional) `description` - The description of Resource Group. Defaults to `Managed by Terraform.`.
71+
EOF
72+
type = object({
73+
enabled = optional(bool, true)
74+
name = optional(string, "")
75+
description = optional(string, "Managed by Terraform.")
76+
})
77+
default = {}
78+
nullable = false
8179
}

0 commit comments

Comments
 (0)