Skip to content

Commit 5af9c59

Browse files
authored
feat: create private Route 53 hosted zone and update IAM policy actions (#95)
* feat: create private Route 53 hosted zone and update IAM policy actions * feat: enhance S3 permissions in IAM policy for lifecycle management
1 parent c5e7156 commit 5af9c59

File tree

3 files changed

+47
-43
lines changed

3 files changed

+47
-43
lines changed

cloudservice-setup/aws/ec2-custom/iam.tf

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ resource "aws_iam_policy" "automq_console_policy" {
3939
"autoscaling:ResumeProcesses",
4040
"autoscaling:SuspendProcesses",
4141
"autoscaling:UpdateAutoScalingGroup",
42+
# "ec2:DeleteKeyPair",
4243
"ec2:AttachVolume",
4344
"ec2:AuthorizeSecurityGroupEgress",
4445
"ec2:AuthorizeSecurityGroupIngress",
45-
"ec2:DeleteKeyPair",
4646
"ec2:DeleteSecurityGroup",
4747
"ec2:DeleteVolume",
4848
"ec2:DetachVolume",
@@ -65,6 +65,20 @@ resource "aws_iam_policy" "automq_console_policy" {
6565
{
6666
Effect = "Allow"
6767
Action = [
68+
"s3:ListBucket",
69+
"s3:ListBucketMultipartUploads",
70+
"s3:GetLifecycleConfiguration",
71+
"s3:PutLifecycleConfiguration"
72+
]
73+
Resource = [
74+
"arn:aws:s3:::${local.data_bucket_name}",
75+
"arn:aws:s3:::${local.ops_bucket_name}"
76+
]
77+
},
78+
{
79+
Effect = "Allow"
80+
Action = [
81+
"s3:AbortMultipartUpload",
6882
"s3:DeleteObject",
6983
"s3:GetObject",
7084
"s3:PutObject",
@@ -92,7 +106,8 @@ resource "aws_iam_policy" "automq_console_policy" {
92106
Action = [
93107
"autoscaling:CreateAutoScalingGroup",
94108
"autoscaling:DescribeAutoScalingGroups",
95-
"ec2:CreateKeyPair",
109+
# "ec2:CreateKeyPair",
110+
# "ec2:DescribeKeyPairs",
96111
"ec2:CreateLaunchTemplate",
97112
"ec2:CreateLaunchTemplateVersion",
98113
"ec2:CreateSecurityGroup",
@@ -104,7 +119,6 @@ resource "aws_iam_policy" "automq_console_policy" {
104119
"ec2:DescribeInstanceAttribute",
105120
"ec2:DescribeInstanceTypeOfferings",
106121
"ec2:DescribeInstances",
107-
"ec2:DescribeKeyPairs",
108122
"ec2:DescribeLaunchTemplateVersions",
109123
"ec2:DescribeLaunchTemplates",
110124
"ec2:DescribeRouteTables",
@@ -117,10 +131,6 @@ resource "aws_iam_policy" "automq_console_policy" {
117131
"ec2:DescribeVpcs",
118132
"ec2:ModifyLaunchTemplate",
119133
"ec2:RunInstances",
120-
"eks:DescribeCluster",
121-
"eks:DescribeNodegroup",
122-
"eks:ListClusters",
123-
"eks:ListNodegroups",
124134
"elasticloadbalancing:DescribeTargetGroups",
125135
"fsx:CreateFileSystem",
126136
"fsx:CreateStorageVirtualMachine",
@@ -132,32 +142,22 @@ resource "aws_iam_policy" "automq_console_policy" {
132142
"pricing:DescribeServices",
133143
"pricing:GetAttributeValues",
134144
"pricing:GetProducts",
135-
"route53:ChangeResourceRecordSets",
136-
"route53:GetHostedZone",
137-
"route53:ListHostedZones",
138-
"route53:ListHostedZonesByName",
139-
"route53:ListHostedZonesByVpc",
140-
"route53:ListResourceRecordSets",
141-
"s3:AbortMultipartUpload",
142-
"s3:CreateBucket",
143-
"s3:DeleteObject",
144-
"s3:ListAllMyBuckets",
145-
"s3:ListBucket",
146-
"s3:ListBucketMultipartUploads",
147-
"ssm:GetParameters"
145+
"ssm:GetParameters",
146+
# "eks:DescribeCluster",
147+
# "eks:DescribeNodegroup",
148+
# "eks:ListClusters",
149+
# "eks:ListNodegroups"
148150
]
149151
Resource = "*"
150152
},
151153
{
152154
Effect = "Allow"
153155
Action = [
154-
"s3:GetLifecycleConfiguration",
155-
"s3:ListBucket",
156-
"s3:PutLifecycleConfiguration"
157-
]
158-
Resource = [
159-
"arn:aws:s3:::${local.ops_bucket_name}"
156+
"route53:ChangeResourceRecordSets",
157+
"route53:GetHostedZone",
158+
"route53:ListResourceRecordSets"
160159
]
160+
Resource = "arn:aws:route53:::hostedzone/${local.route53_hosted_zone_id}"
161161
}
162162
]
163163
})

cloudservice-setup/aws/ec2-custom/main.tf

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ resource "aws_instance" "automq_byoc_console" {
144144
automq_data_bucket = local.data_bucket_name,
145145
automq_ops_bucket = local.ops_bucket_name,
146146
instance_security_group_id = aws_security_group.automq_byoc_console_sg.id,
147-
instance_dns = aws_route53_zone.private_r53.zone_id,
147+
instance_dns = local.route53_hosted_zone_id,
148148
instance_profile_arn = aws_iam_instance_profile.automq_byoc_instance_profile.arn,
149149
environment_id = local.env_id
150150
})
@@ -169,19 +169,3 @@ resource "aws_volume_attachment" "data_volume_attachment" {
169169
volume_id = aws_ebs_volume.data_volume.id
170170
instance_id = aws_instance.automq_byoc_console.id
171171
}
172-
173-
resource "aws_route53_zone" "private_r53" {
174-
name = "${local.name_suffix}.automq.private"
175-
176-
vpc {
177-
vpc_id = var.vpc_id
178-
}
179-
180-
lifecycle {
181-
create_before_destroy = true
182-
}
183-
184-
tags = merge(local.common_tags, {
185-
Name = "automq-private-zone-${local.env_id}"
186-
})
187-
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Create a private Route 53 hosted zone or you can use an existing one
2+
resource "aws_route53_zone" "private_r53" {
3+
name = "${local.name_suffix}.automq.private"
4+
5+
vpc {
6+
vpc_id = var.vpc_id
7+
}
8+
9+
lifecycle {
10+
create_before_destroy = true
11+
}
12+
13+
tags = merge(local.common_tags, {
14+
Name = "automq-private-zone-${local.env_id}"
15+
})
16+
}
17+
18+
locals {
19+
route53_hosted_zone_id = aws_route53_zone.private_r53.zone_id
20+
}

0 commit comments

Comments
 (0)