44provider "aws" {
55 region = " eu-west-1"
66}
7+
8+ locals {
9+ vpc_cidr_block = module. vpc . vpc_cidr_block
10+ additional_cidr_block = " 172.16.0.0/16"
11+ name = " api"
12+ environment = " test"
13+ }
714# ###----------------------------------------------------------------------------------
815# # A VPC is a virtual network that closely resembles a traditional network that you'd operate in your own data center.
916# ###----------------------------------------------------------------------------------
1017module "vpc" {
1118 source = " clouddrove/vpc/aws"
1219 version = " 2.0.0"
1320
14- name = " vpc"
15- environment = " test"
16- label_order = [" name" , " environment" ]
17-
18- cidr_block = " 172.16.0.0/16"
21+ name = local. name
22+ environment = local. environment
23+ cidr_block = " 172.16.0.0/16"
1924}
2025
2126# ###----------------------------------------------------------------------------------
@@ -24,12 +29,10 @@ module "vpc" {
2429# tfsec:ignore:aws-ec2-no-public-ip-subnet
2530module "public_subnets" {
2631 source = " clouddrove/subnet/aws"
27- version = " 1.3.0"
28-
29- name = " public-subnet"
30- environment = " test"
31- label_order = [" name" , " environment" ]
32+ version = " 2.0.0"
3233
34+ name = local. name
35+ environment = local. environment
3336 availability_zones = [" eu-west-1b" , " eu-west-1c" ]
3437 vpc_id = module. vpc . vpc_id
3538 cidr_block = module. vpc . vpc_cidr_block
@@ -41,30 +44,103 @@ module "public_subnets" {
4144# #----------------------------------------------------------------------------------
4245# # Below module will create SECURITY-GROUP and its components.
4346# #----------------------------------------------------------------------------------
44- # tfsec:ignore:aws-ec2-no-public-ingress-sgr
45- module "security_group" {
47+
48+ # ################################################################################
49+ # Security Groups module call
50+ # ###############################################################################
51+
52+ module "ssh" {
53+ source = " clouddrove/security-group/aws"
54+ version = " 2.0.0"
55+
56+ name = local. name
57+ environment = local. environment
58+ vpc_id = module. vpc . vpc_id
59+ new_sg_ingress_rules_with_cidr_blocks = [{
60+ rule_count = 1
61+ from_port = 22
62+ protocol = " tcp"
63+ to_port = 22
64+ cidr_blocks = [local.vpc_cidr_block, local.additional_cidr_block]
65+ description = " Allow ssh traffic."
66+ }]
67+
68+ # # EGRESS Rules
69+ new_sg_egress_rules_with_cidr_blocks = [{
70+ rule_count = 1
71+ from_port = 22
72+ protocol = " tcp"
73+ to_port = 22
74+ cidr_blocks = [local.vpc_cidr_block, local.additional_cidr_block]
75+ description = " Allow ssh outbound traffic."
76+ }]
77+ }
78+
79+ # tfsec:ignore:aws-ec2-no-public-egress-sgr
80+ module "http_https" {
4681 source = " clouddrove/security-group/aws"
4782 version = " 2.0.0"
4883
49- name = " security-group"
50- environment = " test"
51- label_order = [" environment" , " name" ]
52- vpc_id = module. vpc . vpc_id
53- allowed_ip = [" 0.0.0.0/0" ]
54- allowed_ports = [3306 ]
84+ name = local. name
85+ environment = local. environment
86+ vpc_id = module. vpc . vpc_id
87+ # # INGRESS Rules
88+ new_sg_ingress_rules_with_cidr_blocks = [{
89+ rule_count = 1
90+ from_port = 22
91+ protocol = " tcp"
92+ to_port = 22
93+ cidr_blocks = [local.vpc_cidr_block]
94+ description = " Allow ssh traffic."
95+ },
96+ {
97+ rule_count = 2
98+ from_port = 80
99+ protocol = " tcp"
100+ to_port = 80
101+ cidr_blocks = [local.vpc_cidr_block]
102+ description = " Allow http traffic."
103+ },
104+ {
105+ rule_count = 3
106+ from_port = 443
107+ protocol = " tcp"
108+ to_port = 443
109+ cidr_blocks = [local.vpc_cidr_block]
110+ description = " Allow https traffic."
111+ },
112+ {
113+ rule_count = 3
114+ from_port = 3306
115+ protocol = " tcp"
116+ to_port = 3306
117+ cidr_blocks = [local.vpc_cidr_block]
118+ description = " Allow https traffic."
119+ }
120+ ]
121+
122+ # # EGRESS Rules
123+ new_sg_egress_rules_with_cidr_blocks = [{
124+ rule_count = 1
125+ from_port = 0
126+ protocol = " -1"
127+ to_port = 0
128+ cidr_blocks = [" 0.0.0.0/0" ]
129+ ipv6_cidr_blocks = [" ::/0" ]
130+ description = " Allow all traffic."
131+ }
132+ ]
55133}
56134
57135# ###----------------------------------------------------------------------------------
58136# # This terraform module is designed to generate consistent label names and tags for resources.
59137# ###----------------------------------------------------------------------------------
60138module "acm" {
61139 source = " clouddrove/acm/aws"
62- version = " 1.3.0"
63-
64- name = " certificate"
65- environment = " test"
66- label_order = [" name" , " environment" ]
140+ version = " 1.4.1"
67141
142+ name = local. name
143+ environment = local. environment
68144 enable_aws_certificate = true
69145 domain_name = " clouddrove.ca"
70146 subject_alternative_names = [" *.clouddrove.ca" ]
@@ -79,15 +155,13 @@ module "lambda" {
79155 source = " clouddrove/lambda/aws"
80156 version = " 1.3.0"
81157
82- name = " lambda"
83- environment = " test"
84- label_order = [" name" , " environment" ]
85-
86- enabled = true
87- timeout = 60
88- filename = " ./lambda_packages"
89- handler = " index.lambda_handler"
90- runtime = " python3.8"
158+ name = local. name
159+ environment = local. environment
160+ enabled = true
161+ timeout = 60
162+ filename = " ./lambda_packages"
163+ handler = " index.lambda_handler"
164+ runtime = " python3.8"
91165 iam_actions = [
92166 " logs:CreateLogStream" ,
93167 " logs:CreateLogGroup" ,
@@ -121,17 +195,15 @@ module "lambda" {
121195module "api_gateway" {
122196 source = " ./../../"
123197
124- name = " api"
125- environment = " test"
126- label_order = [" environment" , " name" ]
127-
198+ name = local. name
199+ environment = local. environment
128200 domain_name = " clouddrove.ca"
129201 create_vpc_link_enabled = true
130202 zone_id = " 1`23456059QJZ25345678"
131203 integration_uri = module. lambda . arn
132204 domain_name_certificate_arn = module. acm . arn
133205 subnet_ids = tolist (module. public_subnets . public_subnet_id )
134- security_group_ids = [module . security_group . security_group_ids ]
206+ security_group_ids = [module . ssh . security_group_id , module . http_https . security_group_id ]
135207 cors_configuration = {
136208 allow_credentials = true
137209 allow_methods = [" GET" , " OPTIONS" , " POST" ]
0 commit comments