4
4
provider "aws" {
5
5
region = " eu-west-1"
6
6
}
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
+ }
7
14
# ###----------------------------------------------------------------------------------
8
15
# # A VPC is a virtual network that closely resembles a traditional network that you'd operate in your own data center.
9
16
# ###----------------------------------------------------------------------------------
10
17
module "vpc" {
11
18
source = " clouddrove/vpc/aws"
12
19
version = " 2.0.0"
13
20
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"
19
24
}
20
25
21
26
# ###----------------------------------------------------------------------------------
@@ -24,12 +29,10 @@ module "vpc" {
24
29
# tfsec:ignore:aws-ec2-no-public-ip-subnet
25
30
module "public_subnets" {
26
31
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"
32
33
34
+ name = local. name
35
+ environment = local. environment
33
36
availability_zones = [" eu-west-1b" , " eu-west-1c" ]
34
37
vpc_id = module. vpc . vpc_id
35
38
cidr_block = module. vpc . vpc_cidr_block
@@ -41,30 +44,103 @@ module "public_subnets" {
41
44
# #----------------------------------------------------------------------------------
42
45
# # Below module will create SECURITY-GROUP and its components.
43
46
# #----------------------------------------------------------------------------------
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" {
46
81
source = " clouddrove/security-group/aws"
47
82
version = " 2.0.0"
48
83
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
+ ]
55
133
}
56
134
57
135
# ###----------------------------------------------------------------------------------
58
136
# # This terraform module is designed to generate consistent label names and tags for resources.
59
137
# ###----------------------------------------------------------------------------------
60
138
module "acm" {
61
139
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"
67
141
142
+ name = local. name
143
+ environment = local. environment
68
144
enable_aws_certificate = true
69
145
domain_name = " clouddrove.ca"
70
146
subject_alternative_names = [" *.clouddrove.ca" ]
@@ -79,15 +155,13 @@ module "lambda" {
79
155
source = " clouddrove/lambda/aws"
80
156
version = " 1.3.0"
81
157
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"
91
165
iam_actions = [
92
166
" logs:CreateLogStream" ,
93
167
" logs:CreateLogGroup" ,
@@ -121,17 +195,15 @@ module "lambda" {
121
195
module "api_gateway" {
122
196
source = " ./../../"
123
197
124
- name = " api"
125
- environment = " test"
126
- label_order = [" environment" , " name" ]
127
-
198
+ name = local. name
199
+ environment = local. environment
128
200
domain_name = " clouddrove.ca"
129
201
create_vpc_link_enabled = true
130
202
zone_id = " 1`23456059QJZ25345678"
131
203
integration_uri = module. lambda . arn
132
204
domain_name_certificate_arn = module. acm . arn
133
205
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 ]
135
207
cors_configuration = {
136
208
allow_credentials = true
137
209
allow_methods = [" GET" , " OPTIONS" , " POST" ]
0 commit comments