Skip to content

Commit 0c4684f

Browse files
Merge branch 'techiescamp:master' into TEC-56
2 parents 1b542cb + 4f55c0c commit 0c4684f

File tree

16 files changed

+638
-239
lines changed

16 files changed

+638
-239
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,31 @@ terraform destroy \
2222
-backend-config="dynamodb_table=terraform-state-lock"
2323
```
2424

25+
#### VPC Provisioning
26+
27+
cd into the `environments/dev/vpc` directory and run the following commands:
28+
29+
1. Init Terraform in the directory `environments/dev/vpc`
30+
31+
```
32+
terraform init
33+
```
34+
2. To preview the changes in code
35+
36+
```
37+
terraform plan -var-file=../../../vars/dev/vpc.tfvars
38+
```
39+
3. To apply the changes
40+
41+
```
42+
terraform apply -var-file=../../../vars/dev/vpc.tfvars
43+
```
44+
4. To destroy the resources created using the code
45+
46+
```
47+
terraform destroy -var-file=../../../vars/dev/vpc.tfvars
48+
49+
2550
#### RDS Provisioning
2651
2752
cd into the `environments/dev/rds` directory and run the following commands:

environments/dev/ec2/main.tf

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,36 @@ module "ec2" {
2020
}
2121

2222
module "security-group" {
23-
source = "../../../modules/security-group"
24-
region = var.region
25-
tags = var.tags
26-
name = var.name
27-
environment = var.environment
28-
owner = var.owner
29-
cost_center = var.cost_center
30-
application = var.application
31-
sg_name = var.sg_name
32-
vpc_id = var.vpc_id
33-
ingress_from_port = var.ingress_from_port
34-
ingress_to_port = var.ingress_to_port
35-
ingress_protocol = var.ingress_protocol
36-
ingress_cidr_block = var.ingress_cidr_block
37-
egress_from_port = var.egress_from_port
38-
egress_to_port = var.egress_to_port
39-
egress_protocol = var.egress_protocol
40-
egress_cidr_block = var.egress_cidr_block
23+
source = "../../../modules/security-group"
24+
region = var.region
25+
tags = var.tags
26+
name = var.name
27+
environment = var.environment
28+
owner = var.owner
29+
cost_center = var.cost_center
30+
application = var.application
31+
sg_name = var.sg_name
32+
vpc_id = var.vpc_id
33+
34+
ingress_cidr_from_port = var.ingress_cidr_from_port
35+
ingress_cidr_to_port = var.ingress_cidr_to_port
36+
ingress_cidr_protocol = var.ingress_cidr_protocol
37+
ingress_cidr_block = var.ingress_cidr_block
38+
create_ingress_cidr = var.create_ingress_cidr
39+
ingress_sg_from_port = var.ingress_sg_from_port
40+
ingress_sg_to_port = var.ingress_sg_to_port
41+
ingress_sg_protocol = var.ingress_sg_protocol
42+
ingress_security_group_ids = var.ingress_security_group_ids
43+
create_ingress_sg = var.create_ingress_sg
44+
egress_cidr_from_port = var.egress_cidr_from_port
45+
egress_cidr_to_port = var.egress_cidr_to_port
46+
egress_cidr_protocol = var.egress_cidr_protocol
47+
egress_cidr_block = var.egress_cidr_block
48+
create_egress_cidr = var.create_egress_cidr
49+
egress_sg_from_port = var.egress_sg_from_port
50+
egress_sg_to_port = var.egress_sg_to_port
51+
egress_sg_protocol = var.egress_sg_protocol
52+
egress_security_group_ids = var.egress_security_group_ids
53+
create_egress_sg = var.create_egress_sg
4154
}
55+

environments/dev/ec2/variables.tf

Lines changed: 95 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -43,73 +43,133 @@ variable "vpc_id" {
4343
description = "VPC ID for the security group"
4444
}
4545

46+
variable "tags" {
47+
default = {}
48+
type = map(string)
49+
description = "Extra tags to attach to the security group resources"
50+
}
51+
52+
variable "name" {
53+
type = string
54+
description = "The name of the resources"
55+
}
56+
57+
variable "environment" {
58+
type = string
59+
description = "The environment name for the resources"
60+
}
61+
62+
variable "owner" {
63+
type = string
64+
description = "Owner's name for the resource"
65+
}
66+
67+
variable "cost_center" {
68+
type = string
69+
description = "Cost center identifier for the resource"
70+
}
71+
72+
variable "application" {
73+
type = string
74+
description = "Name of the application related to the resource"
75+
}
76+
77+
variable "ingress_cidr_from_port" {
78+
type = list(number)
79+
description = "List of starting ports for cidr ingress rules of the EC2 security group."
80+
}
81+
82+
variable "ingress_cidr_to_port" {
83+
type = list(number)
84+
description = "List of ending ports for cidr ingress rules of the EC2 security group."
85+
}
86+
87+
variable "ingress_cidr_protocol" {
88+
type = list(string)
89+
description = "List of protocols for cidr ingress rules of the EC2 security group."
90+
}
91+
4692
variable "ingress_cidr_block" {
4793
type = list(string)
48-
description = "CIDR blocks for EC2 security group ingress rules"
94+
description = "List of CIDR blocks for cidr ingress rules of the EC2 security group."
4995
}
5096

51-
variable "ingress_from_port" {
52-
description = "The starting port for ingress rules"
97+
variable "ingress_sg_from_port" {
5398
type = list(number)
99+
description = "List of starting ports for sg ingress rules of the EC2 security group."
54100
}
55101

56-
variable "ingress_to_port" {
57-
description = "The ending port for ingress rules"
102+
variable "ingress_sg_to_port" {
58103
type = list(number)
104+
description = "List of ending ports for sg ingress rules of the EC2 security group."
59105
}
60106

61-
variable "ingress_protocol" {
62-
description = "The protocol for ingress rules"
63-
type = list(any)
107+
variable "ingress_sg_protocol" {
108+
type = list(string)
109+
description = "List of protocols for sg ingress rules of the EC2 security group."
64110
}
65111

66-
variable "egress_cidr_block" {
112+
variable "ingress_security_group_ids" {
67113
type = list(string)
68-
description = "CIDR blocks for EC2 security group egress rules"
114+
description = "List of Security Group ids for sg ingress rules of the EC2 security group."
69115
}
70116

71-
variable "egress_from_port" {
72-
description = "The starting port for egress rules"
117+
variable "egress_cidr_from_port" {
73118
type = list(number)
119+
description = "List of starting ports for cidr egress rules of the EC2 security group."
74120
}
75121

76-
variable "egress_to_port" {
77-
description = "The ending port for egress rules"
122+
variable "egress_cidr_to_port" {
78123
type = list(number)
124+
description = "List of ending ports for cidr egress rules of the EC2 security group."
79125
}
80126

81-
variable "egress_protocol" {
82-
description = "The protocol for egress rules"
83-
type = list(any)
127+
variable "egress_cidr_protocol" {
128+
type = list(string)
129+
description = "List of protocols for cidr egress rules of the EC2 security group."
84130
}
85131

86-
variable "tags" {
87-
default = {}
88-
type = map(string)
89-
description = "Extra tags to attach to the security group resources"
132+
variable "egress_cidr_block" {
133+
type = list(string)
134+
description = "List of CIDR blocks for cidr egress rules of the EC2 security group."
90135
}
91136

92-
variable "name" {
93-
type = string
94-
description = "The name of the resources"
137+
variable "egress_sg_from_port" {
138+
type = list(number)
139+
description = "List of starting ports for sg egress rules of the EC2 security group."
95140
}
96141

97-
variable "environment" {
142+
variable "egress_sg_to_port" {
143+
type = list(number)
144+
description = "List of ending ports for sg egress rules of the EC2 security group."
145+
}
146+
147+
variable "egress_sg_protocol" {
98148
type = list(string)
99-
description = "The environment name for the resources"
149+
description = "List of protocols for sg egress rules of the EC2 security group."
100150
}
101151

102-
variable "owner" {
103-
type = string
104-
description = "Owner's name for the resource"
152+
variable "egress_security_group_ids" {
153+
type = list(string)
154+
description = "List of Security Group ids for sg egress rules of the EC2 security group."
105155
}
106156

107-
variable "cost_center" {
108-
type = string
109-
description = "Cost center identifier for the resource"
157+
variable "create_ingress_cidr" {
158+
type = bool
159+
description = "Enable or disable CIDR block ingress rules."
110160
}
111161

112-
variable "application" {
113-
type = string
114-
description = "Name of the application related to the resource"
162+
variable "create_ingress_sg" {
163+
type = bool
164+
description = "Enable or disable Security Groups ingress rules."
165+
}
166+
167+
variable "create_egress_cidr" {
168+
type = bool
169+
description = "Enable or disable CIDR block egress rules."
170+
}
171+
172+
variable "create_egress_sg" {
173+
type = bool
174+
description = "Enable or disable Security Groups egress rules."
115175
}

environments/dev/vpc/main.tf

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,22 @@ provider "aws" {
77

88
module "vpc" {
99
source = "../../../modules/vpc"
10-
name = "eks-vpc"
11-
region = "us-west-2"
12-
project = "EKS Demo"
13-
environment = "dev"
14-
vpc_cidr_block = "10.0.0.0/16"
15-
public_subnet_cidr_blocks = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
16-
app_subnet_cidr_blocks = ["10.0.4.0/24", "10.0.5.0/24", "10.0.6.0/24"]
17-
db_subnet_cidr_blocks = ["10.0.7.0/24", "10.0.8.0/24", "10.0.9.0/24"]
18-
management_subnet_cidr_blocks = ["10.0.10.0/24", "10.0.11.0/24", "10.0.12.0/24"]
19-
availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"]
10+
region = var.region
11+
vpc_cidr_block = var.vpc_cidr_block
12+
instance_tenancy = var.instance_tenancy
13+
enable_dns_support = var.enable_dns_support
14+
enable_dns_hostnames = var.enable_dns_hostnames
15+
domain = var.domain
16+
create_nat_gateway = var.create_nat_gateway
17+
destination_cidr_block = var.destination_cidr_block
18+
map_public_ip_on_launch = var.map_public_ip_on_launch
19+
public_subnet_cidr_blocks = var.public_subnet_cidr_blocks
20+
app_subnet_cidr_blocks = var.app_subnet_cidr_blocks
21+
db_subnet_cidr_blocks = var.db_subnet_cidr_blocks
22+
management_subnet_cidr_blocks = var.management_subnet_cidr_blocks
23+
availability_zones = var.availability_zones
24+
owner = var.owner
25+
environment = var.environment
26+
cost_center = var.cost_center
27+
application = var.application
2028
}

environments/dev/vpc/variables.tf

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Common Variables
2+
3+
variable "tags" {
4+
default = {}
5+
type = map(string)
6+
description = "Extra tags to attach to the VPC resources"
7+
}
8+
9+
variable "region" {
10+
type = string
11+
description = "Region of the VPC"
12+
}
13+
14+
# VPC Variables
15+
16+
variable "vpc_cidr_block" {
17+
type = string
18+
description = "CIDR block for the VPC"
19+
}
20+
21+
# Subnet Varaibles
22+
23+
variable "public_subnet_cidr_blocks" {
24+
type = list(any)
25+
description = "List of public subnet CIDR blocks"
26+
}
27+
28+
variable "app_subnet_cidr_blocks" {
29+
type = list(any)
30+
description = "List of application subnet CIDR blocks"
31+
}
32+
33+
variable "db_subnet_cidr_blocks" {
34+
type = list(any)
35+
description = "List of Database subnet CIDR blocks"
36+
}
37+
38+
variable "management_subnet_cidr_blocks" {
39+
type = list(any)
40+
description = "List of management subnet CIDR blocks"
41+
}
42+
43+
variable "availability_zones" {
44+
type = list(any)
45+
description = "List of availability zones"
46+
}
47+
48+
variable "create_nat_gateway" {
49+
type = bool
50+
description = "whether to create a NAT gateway or not"
51+
}
52+
53+
variable "owner" {
54+
type = string
55+
description = "Name of owner"
56+
}
57+
58+
variable "environment" {
59+
type = string
60+
description = "The environment name for the resources."
61+
}
62+
63+
variable "cost_center" {
64+
type = string
65+
description = "Name of cost-center for this alb-asg"
66+
}
67+
68+
variable "application" {
69+
type = string
70+
description = "Name of the application"
71+
}
72+
73+
variable "instance_tenancy" {
74+
type = string
75+
description = "Set instance-tenancy"
76+
}
77+
78+
variable "enable_dns_support" {
79+
type = bool
80+
description = "whether to enable DNS support or not"
81+
}
82+
83+
variable "enable_dns_hostnames" {
84+
type = bool
85+
description = "whether to enable DNS hostnames or not"
86+
}
87+
88+
variable "domain" {
89+
type = string
90+
description = "Set the domain of eip"
91+
}
92+
93+
variable "destination_cidr_block" {
94+
type = string
95+
description = "Set the destination cidr block"
96+
}
97+
98+
variable "map_public_ip_on_launch" {
99+
type = bool
100+
description = "whether to map public ip on launch or not"
101+
}
102+
103+

0 commit comments

Comments
 (0)