Skip to content

Commit d8d5d14

Browse files
authored
Output SGID and EC2 SG RDS add (#63)
* Adding sg_outputs and ec2 sg * Adding ports output * db_port
1 parent 53033bb commit d8d5d14

File tree

12 files changed

+236
-66
lines changed

12 files changed

+236
-66
lines changed

action.yaml

+40-13
Original file line numberDiff line numberDiff line change
@@ -946,46 +946,70 @@ outputs:
946946
instance_endpoint:
947947
description: "The URL of the generated ec2 instance"
948948
value: ${{ steps.deploy.outputs.instance_endpoint }}
949+
ec2_sg_id:
950+
description: "SG ID for the EC2 instance"
951+
value: ${{ steps.deploy.outputs.ec2_sg_id }}
949952
# RDS
950953
db_endpoint:
951-
description: "ECS ALB DNS Record"
954+
description: "RDS Endpoint"
952955
value: ${{ steps.deploy.outputs.db_endpoint }}
953956
db_secret_details_name:
954-
description: "ECS DNS URL"
957+
description: "AWS Secret name containing db credentials"
955958
value: ${{ steps.deploy.outputs.db_secret_details_name }}
959+
db_sg_id:
960+
description: "SG ID for the RDS instance"
961+
value: ${{ steps.deploy.outputs.db_sg_id }}
956962
db_proxy_rds_endpoint:
957963
description: "Database proxy endpoint"
958-
value: ${{ steps.deploy.outputs.db_proxy_rds }}
964+
value: ${{ steps.deploy.outputs.db_proxy_rds_endpoint }}
959965
db_proxy_secret_name_rds:
960-
description: "Database proxy secret_name"
966+
description: "AWS Secret name containing proxy credentials"
961967
value: ${{ steps.deploy.outputs.db_proxy_secret_name_rds }}
968+
db_proxy_sg_id_rds:
969+
description: "SG ID for the RDS Proxy instance"
970+
value: ${{ steps.deploy.outputs.db_proxy_sg_id_rds }}
962971
# Aurora
963972
aurora_db_endpoint:
964-
description: "ECS ALB DNS Record"
965-
value: ${{ steps.deploy.outputs.aurora_endpoint }}
973+
description: "Aurora Endpoint"
974+
value: ${{ steps.deploy.outputs.aurora_db_endpoint }}
966975
aurora_db_secret_details_name:
967-
description: "ECS DNS URL"
968-
value: ${{ steps.deploy.outputs.aurora_secret_details_name }}
976+
description: "AWS Secret name containing db credentials"
977+
value: ${{ steps.deploy.outputs.aurora_db_secret_details_name }}
978+
aurora_db_sg_id:
979+
description: "SG ID for the Aurora instance"
980+
value: ${{ steps.deploy.outputs.aurora_db_sg_id }}
969981
aurora_proxy_endpoint:
970982
description: "Database proxy endpoint"
971983
value: ${{ steps.deploy.outputs.db_proxy_aurora }}
972-
aurora_proxy_secret_name_rds:
973-
description: "Database proxy secret_name"
984+
aurora_proxy_secret_name:
985+
description: "AWS Secret name containing proxy credentials"
974986
value: ${{ steps.deploy.outputs.db_proxy_secret_name_aurora }}
987+
aurora_proxy_sg_id:
988+
description: "SG ID for the RDS Proxy instance"
989+
value: ${{ steps.deploy.outputs.db_proxy_sg_id_aurora }}
975990
# DB Proxy
976991
db_proxy_endpoint:
977992
description: "Database proxy endpoint"
978993
value: ${{ steps.deploy.outputs.db_proxy_endpoint }}
979994
db_proxy_secret_name:
980995
description: "Database proxy secret_name"
981996
value: ${{ steps.deploy.outputs.db_proxy_secret_name }}
997+
db_proxy_sg_id:
998+
description: "SG ID for the RDS Proxy instance"
999+
value: ${{ steps.deploy.outputs.db_proxy_sg_id }}
9821000
# ECS
9831001
ecs_load_balancer_dns:
9841002
description: "ECS ALB DNS Record"
9851003
value: ${{ steps.deploy.outputs.ecs_load_balancer_dns }}
9861004
ecs_dns_record:
9871005
description: "ECS DNS URL"
9881006
value: ${{ steps.deploy.outputs.ecs_dns_record }}
1007+
ecs_sg_id:
1008+
description: "ECS SG ID"
1009+
value: ${{ steps.deploy.outputs.ecs_sg_id }}
1010+
ecs_lb_sg_id:
1011+
description: "ECS LB SG ID"
1012+
value: ${{ steps.deploy.outputs.ecs_lb_sg_id }}
9891013
# ECR
9901014
ecr_repository_arn:
9911015
description: "ECR Repo ARN"
@@ -1003,6 +1027,9 @@ outputs:
10031027
redis_connection_string_secret:
10041028
description: "Redis secret containing complete URL to connect directly. (e.g. rediss://user:pass@host:port)"
10051029
value: ${{ steps.deploy.outputs.redis_connection_string_secret }}
1030+
redis_sg_id:
1031+
description: "Redis SG ID"
1032+
value: ${{ steps.deploy.outputs.redis_sg_id }}
10061033
runs:
10071034
using: 'composite'
10081035
steps:
@@ -1373,10 +1400,10 @@ runs:
13731400
AWS_ELB_LISTEN_PORT: ${{ inputs.aws_elb_listen_port }}
13741401
RDS_ENDPOINT: ${{ steps.deploy.outputs.db_endpoint }}
13751402
RDS_SECRETS_NAME: ${{ steps.deploy.outputs.db_secret_details_name }}
1376-
RDS_PROXY: ${{ steps.deploy.outputs.db_proxy_rds }}
1403+
RDS_PROXY: ${{ steps.deploy.outputs.db_proxy_rds_endpoint }}
13771404
RDS_PROXY_SECRET: ${{ steps.deploy.outputs.db_proxy_secret_name_rds }}
1378-
AURORA_ENDPOINT: ${{ steps.deploy.outputs.aurora_endpoint }}
1379-
AURORA_SECRETS_NAME: ${{ steps.deploy.outputs.aurora_secret_details_name }}
1405+
AURORA_ENDPOINT: ${{ steps.deploy.outputs.aurora_db_endpoint }}
1406+
AURORA_SECRETS_NAME: ${{ steps.deploy.outputs.aurora_db_secret_details_name }}
13801407
AURORA_PROXY: ${{ steps.deploy.outputs.db_proxy_aurora }}
13811408
AURORA_PROXY_SECRET: ${{ steps.deploy.outputs.db_proxy_secret_name_aurora }}
13821409
DB_PROXY: ${{ steps.deploy.outputs.db_proxy_endpoint }}

operations/deployment/terraform/aws/bitovi_main.tf

+53-9
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,21 @@ module "ec2" {
3131
}
3232
}
3333

34+
module "ec2_sg_to_rds" {
35+
source = "../modules/aws/sg/add_rule"
36+
count = var.aws_ec2_instance_create && var.aws_rds_db_enable ? 1 : 0
37+
# Inputs
38+
sg_type = "ingress"
39+
sg_rule_description = "${var.aws_resource_identifier} - EC2 Incoming"
40+
sg_rule_from_port = try(module.db_proxy_rds[0].db_proxy_port,module.rds[0].db_port)
41+
sg_rule_to_port = try(module.db_proxy_rds[0].db_proxy_port,module.rds[0].db_port)
42+
sg_rule_protocol = "tcp"
43+
source_security_group_id = module.ec2[0].aws_security_group_ec2_sg_id
44+
target_security_group_id = try(module.db_proxy_rds[0].db_proxy_sg_id,module.rds[0].rds_sg_id)
45+
46+
depends_on = [ module.ec2,module.rds ]
47+
}
48+
3449
module "aws_certificates" {
3550
source = "../modules/aws/certificates"
3651
count = ( var.aws_ec2_instance_create || var.aws_ecs_enable ) && var.aws_r53_enable && var.aws_r53_domain_name != "" ? 1 : 0
@@ -646,6 +661,11 @@ output "instance_endpoint" {
646661
value = local.ec2_endpoint
647662
}
648663

664+
output "ec2_sg_id" {
665+
description = "SG ID for the EC2 instance"
666+
value = try(module.ec2[0].aws_security_group_ec2_sg_id,null)
667+
}
668+
649669
output "aws_elb_dns_name" {
650670
description = "Public DNS address of the LB"
651671
value = try(module.aws_elb[0].aws_elb_dns_name,null)
@@ -661,47 +681,59 @@ output "vm_url" {
661681
}
662682

663683
# Aurora
664-
output "aurora_endpoint" {
684+
output "aurora_db_endpoint" {
665685
value = try(module.aurora_rds[0].aurora_db_endpoint,null)
666686
}
667-
668-
output "aurora_secret_details_name" {
687+
output "aurora_db_secret_details_name" {
669688
value = try(module.aurora_rds[0].aurora_secret_name,null)
670689
}
690+
output "aurora_db_sg_id" {
691+
value = try(module.aurora_rds[0].aurora_sg_id,null)
692+
}
671693

694+
# Aurora Proxy
672695
output "db_proxy_aurora" {
673696
value = try(module.db_proxy_aurora[0].db_proxy_endpoint,null)
674697
}
675-
676698
output "db_proxy_secret_name_aurora" {
677699
value = try(module.db_proxy_aurora[0].db_proxy_secret_name,null)
678700
}
701+
output "db_proxy_sg_id_aurora" {
702+
value = try(module.db_proxy_aurora[0].db_proxy_sg_id,null)
703+
}
679704

680705
# RDS
681706
output "db_endpoint" {
682707
value = try(module.rds[0].db_endpoint,null)
683708
}
684-
685709
output "db_secret_details_name" {
686710
value = try(module.rds[0].db_secret_name,null)
687711
}
712+
output "db_sg_id" {
713+
value = try(module.rds[0].db_sg_id,null)
714+
}
688715

689-
output "db_proxy_rds" {
716+
# RDS Proxy
717+
output "db_proxy_rds_endpoint" {
690718
value = try(module.db_proxy_rds[0].db_proxy_endpoint,null)
691719
}
692-
693-
# Proxy
694720
output "db_proxy_secret_name_rds" {
695721
value = try(module.db_proxy_rds[0].db_proxy_secret_name,null)
696722
}
723+
output "db_proxy_sg_id_rds" {
724+
value = try(module.db_proxy_rds[0].db_proxy_sg_id,null)
725+
}
697726

727+
# Proxy
698728
output "db_proxy_endpoint" {
699729
value = try(module.db_proxy[0].db_proxy_endpoint,null)
700730
}
701-
702731
output "db_proxy_secret_name" {
703732
value = try(module.db_proxy[0].db_proxy_secret_name,null)
704733
}
734+
output "db_proxy_sg_id" {
735+
value = try(module.db_proxy[0].db_proxy_sg_id,null)
736+
}
705737

706738
# ECS
707739
output "ecs_dns_record" {
@@ -712,6 +744,14 @@ output "ecs_load_balancer_dns" {
712744
value = try(module.aws_ecs[0].load_balancer_dns,null)
713745
}
714746

747+
output "ecs_sg_id" {
748+
value = try(module.aws_ecs[0].ecs_sg.id,null)
749+
}
750+
751+
output "ecs_lb_sg_id" {
752+
value = try(module.aws_ecs[0].ecs_lb_sg.id,null)
753+
}
754+
715755
# Redis
716756
output "redis_secret_name" {
717757
value = try(module.redis[0].redis_secret_name,null)
@@ -723,4 +763,8 @@ output "redis_endpoint" {
723763

724764
output "redis_connection_string_secret" {
725765
value = try(module.redis[0].redis_connection_string_secret,null)
766+
}
767+
768+
output "redis_sg_id" {
769+
value = try(module.redis[0].redis_sg_id,null)
726770
}

operations/deployment/terraform/modules/aws/aurora/aws_aurora.tf

+8
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,14 @@ output "aurora_db_endpoint" {
250250
value = aws_rds_cluster.aurora.endpoint
251251
}
252252

253+
output "db_port" {
254+
value = aws_rds_cluster.aurora.port
255+
}
256+
253257
output "random_string" {
254258
value = random_string.random_sm.result
259+
}
260+
261+
output "aurora_sg_id" {
262+
value = aws_security_group.aurora_security_group.id
255263
}

operations/deployment/terraform/modules/aws/db_proxy/aws_db_proxy.tf

+8
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,10 @@ output "db_proxy_endpoint" {
269269
value = aws_db_proxy.rds_proxy[0].endpoint
270270
}
271271

272+
output "db_proxy_port" {
273+
value = local.db_port
274+
}
275+
272276
output "db_proxy_secret_name" {
273277
value = aws_secretsmanager_secret.proxy_credentials.name
274278
}
@@ -283,3 +287,7 @@ resource "random_string" "random_sm" {
283287
locals {
284288
random_string = var.incoming_random_string != null ? var.incoming_random_string : random_string.random_sm.result
285289
}
290+
291+
output "db_proxy_sg_id" {
292+
value = aws_security_group.sg_rds_proxy.id
293+
}

operations/deployment/terraform/modules/aws/ec2/aws_ec2.tf

+8
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,12 @@ output "aws_instance_server_id" {
153153

154154
output "private_key_filename" {
155155
value = local_sensitive_file.private_key.filename
156+
}
157+
158+
output "aws_security_group_ec2_sg_name" {
159+
value = data.aws_security_group.ec2_security_group.name
160+
}
161+
162+
output "aws_security_group_ec2_sg_id" {
163+
value = data.aws_security_group.ec2_security_group.id
156164
}

operations/deployment/terraform/modules/aws/ec2/aws_ec2_security.tf

-7
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,6 @@ locals {
4242
aws_ec2_port_list = var.aws_ec2_port_list != "" ? [for n in split(",", var.aws_ec2_port_list) : tonumber(n)] : []
4343
}
4444

45-
output "aws_security_group_ec2_sg_name" {
46-
value = data.aws_security_group.ec2_security_group.name
47-
}
48-
output "aws_security_group_ec2_sg_id" {
49-
value = data.aws_security_group.ec2_security_group.id
50-
}
51-
5245
resource "aws_iam_role" "ec2_role" {
5346
count = var.aws_ec2_iam_instance_profile != "" ? 0 : 1
5447
name = var.aws_resource_identifier

operations/deployment/terraform/modules/aws/ecs/aws_ecs_networking.tf

+8
Original file line numberDiff line numberDiff line change
@@ -223,4 +223,12 @@ output "load_balancer_protocol" {
223223

224224
output "load_balancer_zone_id" {
225225
value = aws_alb.ecs_lb.zone_id
226+
}
227+
228+
output "ecs_sg_id" {
229+
value = aws_security_group.ecs_sg.id
230+
}
231+
232+
output "ecs_lb_sg_id" {
233+
value = aws_security_group.ecs_lb_sg.id
226234
}

operations/deployment/terraform/modules/aws/elb/aws_elb.tf

+8-9
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,6 @@ resource "aws_elb" "vm_lb" {
111111
Name = "${var.aws_resource_identifier_supershort}"
112112
}
113113
}
114-
115-
output "aws_elb_dns_name" {
116-
value = aws_elb.vm_lb.dns_name
117-
}
118-
output "aws_elb_zone_id" {
119-
value = aws_elb.vm_lb.zone_id
120-
}
121-
122114

123115
# TODO: Fix when a user only passes app_ports, the target length should be the same.
124116
# The main idea of the next block is to get what should be opened, mapped, and with which protocol.
@@ -145,4 +137,11 @@ locals {
145137
# Same but for listen protocols, and if a cert is available, make them SSL
146138
elb_listen_protocol = length(local.aws_elb_listen_protocol) < local.aws_ports_ammount ? ( local.elb_ssl_available ?
147139
[ for _ in range(local.aws_ports_ammount) : "ssl" ] : [ for _ in range(local.aws_ports_ammount) : "tcp" ] ) : local.aws_elb_listen_protocol
148-
}
140+
}
141+
142+
output "aws_elb_dns_name" {
143+
value = aws_elb.vm_lb.dns_name
144+
}
145+
output "aws_elb_zone_id" {
146+
value = aws_elb.vm_lb.zone_id
147+
}

operations/deployment/terraform/modules/aws/rds/aws_rds.tf

+20-12
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,6 @@ resource "aws_db_instance" "default" {
8282
}
8383
}
8484

85-
output "db_endpoint" {
86-
value = aws_db_instance.default.endpoint
87-
}
88-
89-
output "db_secret_name" {
90-
value = aws_secretsmanager_secret.rds_database_credentials.name
91-
}
92-
93-
output "db_id" {
94-
value = aws_db_instance.default.id
95-
}
96-
9785
// Creates a secret manager secret for the databse credentials
9886
resource "aws_secretsmanager_secret" "rds_database_credentials" {
9987
name = "${var.aws_resource_identifier_supershort}-rdsdb-pub-${random_string.random_sm.result}"
@@ -141,6 +129,26 @@ data "aws_vpc" "selected" {
141129
id = var.aws_selected_vpc_id
142130
}
143131

132+
output "db_endpoint" {
133+
value = aws_db_instance.default.endpoint
134+
}
135+
136+
output "db_secret_name" {
137+
value = aws_secretsmanager_secret.rds_database_credentials.name
138+
}
139+
140+
output "db_id" {
141+
value = aws_db_instance.default.id
142+
}
143+
144144
output "random_string" {
145145
value = random_string.random_sm.result
146+
}
147+
148+
output "rds_sg_id" {
149+
value = aws_security_group.rds_db_security_group.id
150+
}
151+
152+
output "db_port" {
153+
value = aws_db_instance.default.port
146154
}

0 commit comments

Comments
 (0)