File tree Expand file tree Collapse file tree 7 files changed +78
-0
lines changed
Expand file tree Collapse file tree 7 files changed +78
-0
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,37 @@ terraform {
55# Set up necessary IAM Roles for ECS Hosts
66
77data "aws_iam_policy_document" "ecs_cluster_asg_policy" {
8+ statement {
9+ actions = [
10+ " ssmmessages:CreateControlChannel" ,
11+ " ssmmessages:CreateDataChannel" ,
12+ " ssmmessages:OpenControlChannel" ,
13+ " ssmmessages:OpenDataChannel"
14+ ]
15+ effect = " Allow"
16+
17+ resources = [" *" ]
18+ }
19+
20+ statement {
21+ actions = [
22+ " s3:GetEncryptionConfiguration"
23+ ]
24+ effect = " Allow"
25+ resources = [" *" ]
26+ }
27+
28+ statement {
29+
30+ actions = [
31+ " kms:Decrypt"
32+ ]
33+
34+ effect = " Allow"
35+
36+ resources = [" *" ]
37+ }
38+
839 statement {
940 actions = [
1041 " ecs:DeregisterContainerInstance" ,
@@ -66,6 +97,11 @@ resource "aws_iam_role_policy" "ecs_cluster_asg_policy" {
6697 policy = data. aws_iam_policy_document . ecs_cluster_asg_policy . json
6798}
6899
100+ resource "aws_iam_role_policy_attachment" "ssm_policy_attachment" {
101+ policy_arn = " arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore"
102+ role = aws_iam_role. ecs_cluster . name
103+ }
104+
69105resource "aws_iam_instance_profile" "ecs_cluster_asg_profile" {
70106 name_prefix = " ecs_cluster_asg_profile-"
71107 role = aws_iam_role. ecs_cluster . name
Original file line number Diff line number Diff line change 1111
1212| Name | Description | Type | Default | Required |
1313| ------| -------------| ------| ---------| :-----:|
14+ | db\_ ingress\_ cidrs | n/a | ` list(string) ` | n/a | yes |
1415| mytags | Tags to include on the resources | ` map ` | ` {} ` | no |
1516| vpc\_ id | VPC ID | ` any ` | n/a | yes |
1617
2021| ------| -------------|
2122| alb-sg-id | ALB Security Group ID |
2223| ecs\_ sg\_ id | ECS Security Group ID |
24+ | sg\_ postgresql\_ id | n/a |
2325
2426<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
2527
Original file line number Diff line number Diff line change @@ -54,4 +54,31 @@ resource "aws_security_group" "sg-ecs" {
5454 }
5555}
5656
57+ resource "aws_security_group" "sg_postgresql" {
58+ name = " bmore-responsive-db-access"
59+ vpc_id = var. vpc_id
60+
61+ # Merge tags from environment tfvars and create name tag
62+ tags = merge (map (" Name" , " bmore-responsive-db-access" ), var. mytags )
63+
64+ ingress {
65+ # TLS (change to whatever ports you need)
66+ from_port = 5432
67+ to_port = 5432
68+ protocol = " tcp"
69+
70+ # We open to 0.0.0.0/0 here to support the testing activities.
71+ # In a production environment, these connections would be limited to
72+ # approved internal IPs. (10.x.x.x/x block(s))
73+ cidr_blocks = var. db_ingress_cidrs
74+ }
75+
76+ egress {
77+ from_port = 0
78+ to_port = 0
79+ protocol = " -1"
80+ cidr_blocks = [" 0.0.0.0/0" ]
81+ }
82+ }
83+
5784# TODO: Add SG Rules for ECS ASG and Load Balancer.
Original file line number Diff line number Diff line change @@ -7,3 +7,7 @@ output "alb-sg-id" {
77 description = " ALB Security Group ID"
88 value = aws_security_group. sg-alb . id
99}
10+
11+ output "sg_postgresql_id" {
12+ value = aws_security_group. sg_postgresql . id
13+ }
Original file line number Diff line number Diff line change @@ -7,3 +7,7 @@ variable "mytags" {
77 type = " map"
88 default = {}
99}
10+
11+ variable "db_ingress_cidrs" {
12+ type = list (string )
13+ }
Original file line number Diff line number Diff line change 2121
2222| Name | Description |
2323| ------| -------------|
24+ | private\_ subnet\_ cidrs | n/a |
2425| public-subnet-ids | Subnet IDs |
2526| subnet\_ ids | Subnet IDs |
2627| vpc-id | VPC ID |
Original file line number Diff line number Diff line change @@ -10,4 +10,8 @@ output "subnet_ids" {
1010output "public-subnet-ids" {
1111 description = " Subnet IDs"
1212 value = aws_subnet. public-subnet . * . id
13+ }
14+
15+ output "private_subnet_cidrs" {
16+ value = var. private_subnet_cidrs
1317}
You can’t perform that action at this time.
0 commit comments