Skip to content

Commit fc55087

Browse files
committed
feat: add support for additional tags
1 parent 9b430fe commit fc55087

File tree

4 files changed

+71
-74
lines changed

4 files changed

+71
-74
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ module "automq-byoc" {
4545
4646
# Set the target regionId of aws
4747
cloud_provider_region = "ap-southeast-1"
48+
49+
# Optional: Add additional tags to all resources
50+
additional_tags = {
51+
Environment = "Production"
52+
Project = "MyProject"
53+
Owner = "TeamA"
54+
CostCenter = "Engineering"
55+
}
4856
}
4957
5058
# Necessary outputs
@@ -246,6 +254,7 @@ output "automq_byoc_instance_id" {
246254
| <a name="input_automq_byoc_env_console_key_name"></a> [automq_byoc_env_console_key_name](#input_automq_byoc_env_console_key_name) | Specify the key pair name for accessing the AutoMQ BYOC environment console. If not specified, the console will be deployed without a key pair. | `string` | `""` | no |
247255
| <a name="input_use_custom_ami"></a> [use_custom_ami](#input_use_custom_ami) | The parameter defaults to false, which means a specific AMI is not specified. If you wish to use a custom AMI, set this parameter to true and specify the `automq_byoc_env_console_ami` parameter with your custom AMI ID. | `bool` | `false` | no |
248256
| <a name="input_automq_byoc_env_console_ami"></a> [automq_byoc_env_console_ami](#input_automq_byoc_env_console_ami) | When the `use_custom_ami` parameter is set to true, this parameter must be set with a custom AMI Name to deploy the AutoMQ console. | `string` | `""` | no |
257+
| <a name="input_additional_tags"></a> [additional_tags](#input_additional_tags) | Additional tags to apply to all resources created by this module. | `map(string)` | `{}` | no |
249258

250259
## Outputs
251260

aws.tf

Lines changed: 49 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ module "automq_byoc_data_bucket_name" {
1111
bucket = "automq-data-${var.automq_byoc_env_id}"
1212
force_destroy = true
1313

14-
tags = {
15-
automqVendor = "automq"
16-
automqEnvironmentID = var.automq_byoc_env_id
17-
}
14+
tags = local.common_tags
1815
}
1916

2017
# Conditional creation of ops bucket
@@ -26,10 +23,7 @@ module "automq_byoc_ops_bucket_name" {
2623
bucket = "automq-ops-${var.automq_byoc_env_id}"
2724
force_destroy = true
2825

29-
tags = {
30-
automqVendor = "automq"
31-
automqEnvironmentID = var.automq_byoc_env_id
32-
}
26+
tags = local.common_tags
3327
}
3428

3529
data "aws_availability_zones" "available_azs" {}
@@ -54,10 +48,7 @@ module "automq_byoc_vpc" {
5448
enable_nat_gateway = true
5549
single_nat_gateway = true
5650

57-
tags = {
58-
automqVendor = "automq"
59-
automqEnvironmentID = var.automq_byoc_env_id
60-
}
51+
tags = local.common_tags
6152
}
6253

6354
resource "aws_security_group" "vpc_endpoint_sg" {
@@ -80,11 +71,12 @@ resource "aws_security_group" "vpc_endpoint_sg" {
8071
cidr_blocks = ["0.0.0.0/0"]
8172
}
8273

83-
tags = {
84-
Name = "automq-byoc-endpoint-sg-${var.automq_byoc_env_id}"
85-
automqVendor = "automq"
86-
automqEnvironmentID = var.automq_byoc_env_id
87-
}
74+
tags = merge(
75+
local.common_tags,
76+
{
77+
Name = "automq-byoc-endpoint-sg-${var.automq_byoc_env_id}"
78+
}
79+
)
8880
}
8981

9082
resource "aws_vpc_endpoint" "ec2_endpoint" {
@@ -98,11 +90,12 @@ resource "aws_vpc_endpoint" "ec2_endpoint" {
9890

9991
private_dns_enabled = true
10092

101-
tags = {
102-
Name = "automq-byoc-ec2-endpoint-${var.automq_byoc_env_id}"
103-
automqVendor = "automq"
104-
automqEnvironmentID = var.automq_byoc_env_id
105-
}
93+
tags = merge(
94+
local.common_tags,
95+
{
96+
Name = "automq-byoc-ec2-endpoint-${var.automq_byoc_env_id}"
97+
}
98+
)
10699
}
107100

108101
resource "aws_vpc_endpoint" "s3_endpoint" {
@@ -117,11 +110,12 @@ resource "aws_vpc_endpoint" "s3_endpoint" {
117110
module.automq_byoc_vpc[0].private_route_table_ids
118111
)
119112

120-
tags = {
121-
Name = "automq-byoc-s3-endpoint-${var.automq_byoc_env_id}"
122-
automqVendor = "automq"
123-
automqEnvironmentID = var.automq_byoc_env_id
124-
}
113+
tags = merge(
114+
local.common_tags,
115+
{
116+
Name = "automq-byoc-s3-endpoint-${var.automq_byoc_env_id}"
117+
}
118+
)
125119
}
126120

127121
resource "aws_vpc_endpoint" "s3table_endpoint" {
@@ -135,11 +129,12 @@ resource "aws_vpc_endpoint" "s3table_endpoint" {
135129

136130
private_dns_enabled = true
137131

138-
tags = {
139-
Name = "automq-byoc-ec2-endpoint-${var.automq_byoc_env_id}"
140-
automqVendor = "automq"
141-
automqEnvironmentID = var.automq_byoc_env_id
142-
}
132+
tags = merge(
133+
local.common_tags,
134+
{
135+
Name = "automq-byoc-s3table-endpoint-${var.automq_byoc_env_id}"
136+
}
137+
)
143138
}
144139

145140
resource "aws_vpc_endpoint" "glue_endpoint" {
@@ -153,11 +148,12 @@ resource "aws_vpc_endpoint" "glue_endpoint" {
153148

154149
private_dns_enabled = true
155150

156-
tags = {
157-
Name = "automq-byoc-ec2-endpoint-${var.automq_byoc_env_id}"
158-
automqVendor = "automq"
159-
automqEnvironmentID = var.automq_byoc_env_id
160-
}
151+
tags = merge(
152+
local.common_tags,
153+
{
154+
Name = "automq-byoc-glue-endpoint-${var.automq_byoc_env_id}"
155+
}
156+
)
161157
}
162158

163159
locals {
@@ -166,6 +162,15 @@ locals {
166162
automq_data_bucket = var.automq_byoc_data_bucket_name == "" ? module.automq_byoc_data_bucket_name.s3_bucket_id : "${var.automq_byoc_data_bucket_name}"
167163
automq_ops_bucket = var.automq_byoc_ops_bucket_name == "" ? module.automq_byoc_ops_bucket_name.s3_bucket_id : "${var.automq_byoc_ops_bucket_name}"
168164
zone_id = aws_route53_zone.private_r53.zone_id
165+
166+
# Common tags that will be applied to all resources
167+
common_tags = merge(
168+
{
169+
automqVendor = "automq"
170+
automqEnvironmentID = var.automq_byoc_env_id
171+
},
172+
var.additional_tags
173+
)
169174
}
170175

171176
data "aws_vpc" "vpc_id" {
@@ -211,10 +216,7 @@ resource "aws_security_group" "automq_byoc_console_sg" {
211216
cidr_blocks = ["0.0.0.0/0"]
212217
}
213218

214-
tags = {
215-
automqVendor = "automq"
216-
automqEnvironmentID = var.automq_byoc_env_id
217-
}
219+
tags = local.common_tags
218220
}
219221

220222
resource "aws_iam_role" "automq_byoc_role" {
@@ -234,10 +236,7 @@ resource "aws_iam_role" "automq_byoc_role" {
234236
]
235237
})
236238

237-
tags = {
238-
automqVendor = "automq"
239-
automqEnvironmentID = var.automq_byoc_env_id
240-
}
239+
tags = local.common_tags
241240
}
242241

243242
resource "aws_iam_policy" "automq_byoc_policy" {
@@ -249,10 +248,7 @@ resource "aws_iam_policy" "automq_byoc_policy" {
249248
automq_ops_bucket = local.automq_ops_bucket
250249
})
251250

252-
tags = {
253-
automqVendor = "automq"
254-
automqEnvironmentID = var.automq_byoc_env_id
255-
}
251+
tags = local.common_tags
256252
}
257253

258254
resource "aws_iam_policy" "automq_byoc_k8s_policy" {
@@ -264,10 +260,7 @@ resource "aws_iam_policy" "automq_byoc_k8s_policy" {
264260
automq_ops_bucket = local.automq_ops_bucket
265261
})
266262

267-
tags = {
268-
automqVendor = "automq"
269-
automqEnvironmentID = var.automq_byoc_env_id
270-
}
263+
tags = local.common_tags
271264
}
272265

273266
resource "aws_iam_role_policy_attachment" "automq_byoc_role_attachment_k8s" {
@@ -284,10 +277,7 @@ resource "aws_iam_instance_profile" "automq_byoc_instance_profile" {
284277
name = "automq-byoc-instance-profile-${var.automq_byoc_env_id}"
285278
role = aws_iam_role.automq_byoc_role.name
286279

287-
tags = {
288-
automqVendor = "automq"
289-
automqEnvironmentID = var.automq_byoc_env_id
290-
}
280+
tags = local.common_tags
291281
}
292282

293283
resource "aws_route53_zone" "private_r53" {
@@ -301,18 +291,12 @@ resource "aws_route53_zone" "private_r53" {
301291
create_before_destroy = true
302292
}
303293

304-
tags = {
305-
automqVendor = "automq"
306-
automqEnvironmentID = var.automq_byoc_env_id
307-
}
294+
tags = local.common_tags
308295
}
309296

310297
resource "aws_eip" "web_ip" {
311298
instance = aws_instance.automq_byoc_console.id
312-
tags = {
313-
automqVendor = "automq"
314-
automqEnvironmentID = var.automq_byoc_env_id
315-
}
299+
tags = local.common_tags
316300
}
317301

318302
locals {

main.tf

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ resource "aws_instance" "automq_byoc_console" {
1313

1414
key_name = var.automq_byoc_env_console_key_name
1515

16-
tags = {
17-
Name = "automq-byoc-console-${var.automq_byoc_env_id}"
18-
automqVendor = "automq"
19-
automqEnvironmentID = var.automq_byoc_env_id
20-
}
16+
tags = merge(
17+
local.common_tags,
18+
{
19+
Name = "automq-byoc-console-${var.automq_byoc_env_id}"
20+
}
21+
)
2122

2223
associate_public_ip_address = true
2324

@@ -38,10 +39,7 @@ resource "aws_ebs_volume" "data_volume" {
3839
size = 20
3940
type = "gp3"
4041

41-
tags = {
42-
automqVendor = "automq"
43-
automqEnvironmentID = var.automq_byoc_env_id
44-
}
42+
tags = local.common_tags
4543
}
4644

4745
resource "aws_volume_attachment" "data_volume_attachment" {

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,9 @@ variable "automq_byoc_env_console_ami" {
7777
type = string
7878
default = ""
7979
}
80+
81+
variable "additional_tags" {
82+
description = "Additional tags to apply to all resources created by this module."
83+
type = map(string)
84+
default = {}
85+
}

0 commit comments

Comments
 (0)