Skip to content

Commit 79c6d53

Browse files
authored
feat: add EIP and modify AMI configuration (#21)
1 parent 5a91a52 commit 79c6d53

File tree

4 files changed

+44
-40
lines changed

4 files changed

+44
-40
lines changed

aws.tf

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module "automq_byoc_data_bucket_name" {
1212
force_destroy = true
1313

1414
tags = {
15-
automqVendor = "automq"
15+
automqVendor = "automq"
1616
automqEnvironmentID = var.automq_byoc_env_id
1717
}
1818
}
@@ -27,7 +27,7 @@ module "automq_byoc_ops_bucket_name" {
2727
force_destroy = true
2828

2929
tags = {
30-
automqVendor = "automq"
30+
automqVendor = "automq"
3131
automqEnvironmentID = var.automq_byoc_env_id
3232
}
3333
}
@@ -39,8 +39,8 @@ module "automq_byoc_vpc" {
3939
version = "5.0.0"
4040

4141
count = var.create_new_vpc ? 1 : 0
42-
cidr = "10.0.0.0/16"
43-
name = "automq-byoc-vpc-${var.automq_byoc_env_id}"
42+
cidr = "10.0.0.0/16"
43+
name = "automq-byoc-vpc-${var.automq_byoc_env_id}"
4444

4545
azs = slice(data.aws_availability_zones.available_azs.names, 0, 3)
4646
public_subnets = ["10.0.0.0/20"]
@@ -50,7 +50,7 @@ module "automq_byoc_vpc" {
5050
enable_dns_hostnames = true
5151

5252
tags = {
53-
automqVendor = "automq"
53+
automqVendor = "automq"
5454
automqEnvironmentID = var.automq_byoc_env_id
5555
}
5656
}
@@ -76,26 +76,26 @@ resource "aws_security_group" "vpc_endpoint_sg" {
7676
}
7777

7878
tags = {
79-
Name = "automq-byoc-endpoint-sg-${var.automq_byoc_env_id}"
80-
automqVendor = "automq"
79+
Name = "automq-byoc-endpoint-sg-${var.automq_byoc_env_id}"
80+
automqVendor = "automq"
8181
automqEnvironmentID = var.automq_byoc_env_id
8282
}
8383
}
8484

8585
resource "aws_vpc_endpoint" "ec2_endpoint" {
8686
count = var.create_new_vpc ? 1 : 0
8787

88-
vpc_id = module.automq_byoc_vpc[0].vpc_id
89-
service_name = "com.amazonaws.${var.cloud_provider_region}.ec2"
90-
vpc_endpoint_type = "Interface"
88+
vpc_id = module.automq_byoc_vpc[0].vpc_id
89+
service_name = "com.amazonaws.${var.cloud_provider_region}.ec2"
90+
vpc_endpoint_type = "Interface"
9191
security_group_ids = [aws_security_group.vpc_endpoint_sg[0].id]
92-
subnet_ids = module.automq_byoc_vpc[0].private_subnets
92+
subnet_ids = module.automq_byoc_vpc[0].private_subnets
9393

9494
private_dns_enabled = true
9595

9696
tags = {
97-
Name = "automq-byoc-ec2-endpoint-${var.automq_byoc_env_id}"
98-
automqVendor = "automq"
97+
Name = "automq-byoc-ec2-endpoint-${var.automq_byoc_env_id}"
98+
automqVendor = "automq"
9999
automqEnvironmentID = var.automq_byoc_env_id
100100
}
101101
}
@@ -113,8 +113,8 @@ resource "aws_vpc_endpoint" "s3_endpoint" {
113113
)
114114

115115
tags = {
116-
Name = "automq-byoc-s3-endpoint-${var.automq_byoc_env_id}"
117-
automqVendor = "automq"
116+
Name = "automq-byoc-s3-endpoint-${var.automq_byoc_env_id}"
117+
automqVendor = "automq"
118118
automqEnvironmentID = var.automq_byoc_env_id
119119
}
120120
}
@@ -131,19 +131,15 @@ data "aws_vpc" "vpc_id" {
131131
}
132132

133133
locals {
134-
ssm_parameter_path = "/aws/service/marketplace/prod-nl2cyzygb46fw/${var.automq_byoc_env_version}"
135-
}
136-
137-
data "aws_ssm_parameter" "marketplace_ami" {
138-
name = local.ssm_parameter_path
134+
image_name = var.use_custom_ami ? var.automq_byoc_env_console_ami : format("AutoMQ-control-center-Prod-%s-x86_64", var.automq_byoc_env_version)
139135
}
140136

141-
data "aws_ami" "marketplace_ami_details" {
137+
data "aws_ami" "console_ami" {
142138
most_recent = true
143139

144140
filter {
145-
name = "image-id"
146-
values = [data.aws_ssm_parameter.marketplace_ami.value]
141+
name = "name"
142+
values = [local.image_name]
147143
}
148144
}
149145

@@ -166,7 +162,7 @@ resource "aws_security_group" "automq_byoc_console_sg" {
166162
}
167163

168164
tags = {
169-
automqVendor = "automq"
165+
automqVendor = "automq"
170166
automqEnvironmentID = var.automq_byoc_env_id
171167
}
172168
}
@@ -178,9 +174,9 @@ resource "aws_iam_role" "automq_byoc_role" {
178174
Version = "2012-10-17"
179175
Statement = [
180176
{
181-
Action = "sts:AssumeRole"
182-
Effect = "Allow"
183-
Sid = ""
177+
Action = "sts:AssumeRole"
178+
Effect = "Allow"
179+
Sid = ""
184180
Principal = {
185181
Service = "ec2.amazonaws.com"
186182
}
@@ -189,7 +185,7 @@ resource "aws_iam_role" "automq_byoc_role" {
189185
})
190186

191187
tags = {
192-
automqVendor = "automq"
188+
automqVendor = "automq"
193189
automqEnvironmentID = var.automq_byoc_env_id
194190
}
195191
}
@@ -204,7 +200,7 @@ resource "aws_iam_policy" "automq_byoc_policy" {
204200
})
205201

206202
tags = {
207-
automqVendor = "automq"
203+
automqVendor = "automq"
208204
automqEnvironmentID = var.automq_byoc_env_id
209205
}
210206
}
@@ -219,7 +215,7 @@ resource "aws_iam_instance_profile" "automq_byoc_instance_profile" {
219215
role = aws_iam_role.automq_byoc_role.name
220216

221217
tags = {
222-
automqVendor = "automq"
218+
automqVendor = "automq"
223219
automqEnvironmentID = var.automq_byoc_env_id
224220
}
225221
}
@@ -236,7 +232,15 @@ resource "aws_route53_zone" "private_r53" {
236232
}
237233

238234
tags = {
239-
automqVendor = "automq"
235+
automqVendor = "automq"
236+
automqEnvironmentID = var.automq_byoc_env_id
237+
}
238+
}
239+
240+
resource "aws_eip" "web_ip" {
241+
instance = aws_instance.automq_byoc_console.id
242+
tags = {
243+
automqVendor = "automq"
240244
automqEnvironmentID = var.automq_byoc_env_id
241245
}
242246
}
@@ -251,4 +255,4 @@ locals {
251255

252256
data "aws_subnet" "public_subnet_info" {
253257
id = local.public_subnet_id
254-
}
258+
}

main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
resource "aws_instance" "automq_byoc_console" {
2-
ami = var.specified_ami_by_marketplace ? data.aws_ami.marketplace_ami_details.id : var.automq_byoc_env_console_ami
2+
ami = data.aws_ami.console_ami.id
33
instance_type = var.automq_byoc_ec2_instance_type
44
subnet_id = local.automq_byoc_env_console_public_subnet_id
55
vpc_security_group_ids = [aws_security_group.automq_byoc_console_sg.id]

outputs.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ output "automq_byoc_env_id" {
55

66
output "automq_byoc_endpoint" {
77
description = "The endpoint for the AutoMQ environment console. Users can set this endpoint to the AutoMQ Terraform Provider to manage resources through Terraform. Additionally, users can access this endpoint via web browser, log in, and manage resources within the environment using the WebUI."
8-
value = "http://${aws_instance.automq_byoc_console.public_ip}:8080"
8+
value = "http://${aws_eip.web_ip.public_ip}:8080"
99
}
1010

1111
output "automq_byoc_initial_username" {
@@ -41,7 +41,7 @@ output "automq_byoc_ops_bucket_name" {
4141
4242
output "automq_byoc_env_console_ec2_instance_ip" {
4343
description = "The instance IP of the deployed AutoMQ BYOC control panel. You can access the service through this IP."
44-
value = aws_instance.automq_byoc_console.public_ip
44+
value = aws_eip.web_ip.public_ip
4545
}
4646
4747
output "automq_byoc_env_console_public_subnet_id" {

variables.tf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,17 @@ variable "automq_byoc_ec2_instance_type" {
5757
variable "automq_byoc_env_version" {
5858
description = "Set the version for the AutoMQ BYOC environment console. It is recommended to keep the default value, which is the latest version. Historical release note reference [document](https://docs.automq.com/automq-cloud/release-notes)."
5959
type = string
60-
default = "latest"
60+
default = "1.2.10"
6161
}
6262

63-
variable "specified_ami_by_marketplace" {
64-
description = "The parameter defaults to true, which means the AMI will be obtained from AWS Marketplace. If you wish to use a custom AMI, set this parameter to false and specify the `automq_byoc_env_console_ami` parameter with your custom AMI ID."
63+
variable "use_custom_ami" {
64+
description = "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."
6565
type = bool
66-
default = true
66+
default = false
6767
}
6868

6969
variable "automq_byoc_env_console_ami" {
70-
description = "When parameter `specified_ami_by_marketplace` set to false, this parameter must set a custom AMI to deploy automq console."
70+
description = "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."
7171
type = string
7272
default = ""
7373
}

0 commit comments

Comments
 (0)