Skip to content

Commit 2f18564

Browse files
authored
Merge pull request #3 from Aswin-Vijayan/TEC-56
[TEC-56][Add] - New branch
2 parents eb807f2 + 13da55e commit 2f18564

File tree

25 files changed

+1883
-92
lines changed

25 files changed

+1883
-92
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*.tfstate
66
*.tfstate.*
77
.terraform.lock.hcl
8-
8+
.terraform
99
# Crash log files
1010
crash.log
1111

@@ -28,3 +28,4 @@ override.tf.json
2828

2929
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
3030
# example: *tfplan*
31+
.DS_Store

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ Terraform AWS Cloud examples for beginners
66
terraform init \
77
-backend-config="key=dev/vpc.tfstate" \
88
-backend-config="bucket=dcube-terraform-state" \
9-
-backend-config="region=us-west-2"
9+
-backend-config="region=us-west-2" \
10+
-backend-config="dynamodb_table=terraform-state-lock"
1011

11-
terraform destory \
12+
terraform destroy \
1213
-backend-config="key=dev/vpc.tfstate" \
1314
-backend-config="bucket=dcube-terraform-state" \
14-
-backend-config="region=us-west-2"
15+
-backend-config="region=us-west-2" \
16+
-backend-config="dynamodb_table=terraform-state-lock"
1517

1618

1719
## Requirements

environments/dev/lb-asg/main.tf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
provider "aws" {
2+
region = var.region
3+
}
4+
5+
module "lb-asg" {
6+
source = "../../../modules/lb-asg"
7+
region = var.region
8+
owner = var.owner
9+
cost_center = var.cost_center
10+
subnets = var.subnets
11+
ami_id = var.ami_id
12+
instance_type = var.instance_type
13+
key_name = var.key_name
14+
environment = var.environment
15+
vpc_id = var.vpc_id
16+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
variable "tags" {
2+
default = {}
3+
type = map(string)
4+
description = "Extra tags to attach to the lb-asg resources"
5+
}
6+
7+
variable "region" {
8+
type = string
9+
description = "Region of the lb-asg"
10+
}
11+
12+
variable "ami_id" {
13+
description = "The ID of the Amazon Machine Image (AMI) to use for the EC2 instances."
14+
}
15+
16+
variable "instance_type" {
17+
description = "The type of EC2 instance to use for the ASG."
18+
}
19+
20+
variable "key_name" {
21+
description = "The name of the EC2 key pair to use for the instances."
22+
}
23+
24+
variable "environment" {
25+
description = "The environment name for the resources."
26+
}
27+
28+
variable "vpc_id" {
29+
description = "The ID of the VPC to use for the resources."
30+
}
31+
32+
variable "subnets" {
33+
description = "A list of subnet IDs to use for the resources."
34+
type = list(string)
35+
}
36+
37+
variable "iam_role_arn" {
38+
description = "ARN of the existing IAM role"
39+
type = string
40+
default = null
41+
}
42+
43+
variable "owner" {
44+
type = string
45+
description = "Name of owner this lb-asg is meant to house"
46+
}
47+
48+
variable "cost_center" {
49+
type = string
50+
description = "Name of cost-center for this lb-asg"
51+
}

environments/dev/rds/main.tf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
provider "aws" {
2+
region = var.region
3+
}
4+
5+
module "rds" {
6+
source = "../../../modules/rds"
7+
region = var.region
8+
owner = var.owner
9+
cost_center = var.cost_center
10+
environment = var.environment
11+
db_username = var.db_username
12+
manage_master_user_password = var.manage_master_user_password
13+
db_password = var.db_password
14+
db_name = var.db_name
15+
db_instance_class = var.db_instance_class
16+
parameter_name = var.parameter_name
17+
}

environments/dev/rds/variables.tf

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
variable "tags" {
2+
default = {}
3+
type = map(string)
4+
description = "Extra tags to attach to the RDS resources"
5+
}
6+
7+
variable "update_rds_endpoint" {
8+
type = bool
9+
default = true
10+
}
11+
12+
variable "region" {
13+
type = string
14+
description = "Region of the rds"
15+
}
16+
17+
variable "environment" {
18+
description = "The environment name for the resources."
19+
}
20+
21+
variable "owner" {
22+
type = string
23+
description = "Name of the owner for this RDS"
24+
}
25+
26+
variable "cost_center" {
27+
type = string
28+
description = "Name of cost-center for this RDS"
29+
}
30+
31+
variable "db_username" {
32+
description = "The username for the RDS database"
33+
type = string
34+
}
35+
36+
variable "manage_master_user_password" {
37+
description = "To enable master user password or not"
38+
type = bool
39+
default = false
40+
}
41+
42+
variable "db_password" {
43+
description = "Password for RDS"
44+
type = string
45+
}
46+
47+
variable "db_name" {
48+
description = "The identifier for the RDS instance"
49+
type = string
50+
}
51+
52+
variable "db_instance_class" {
53+
description = "The RDS instance class"
54+
type = string
55+
}
56+
57+
variable "parameter_name" {
58+
description = "The RDS instance class"
59+
type = string
60+
}

environments/dev/vpc/main.tf

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ provider "aws" {
66
}
77

88
module "vpc" {
9-
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-
availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"]
9+
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"]
1920
}

environments/test/vpc/main.tf

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ resource "aws_iam_role" "eks_cluster" {
1616

1717
assume_role_policy = jsonencode(
1818
{
19-
Version = "2012-10-17"
20-
Statement = [
21-
{
22-
Action = "sts:AssumeRole"
23-
Effect = "Allow"
24-
Principal = {
25-
Service = "eks.amazonaws.com"
19+
Version = "2012-10-17"
20+
Statement = [
21+
{
22+
Action = "sts:AssumeRole"
23+
Effect = "Allow"
24+
Principal = {
25+
Service = "eks.amazonaws.com"
26+
}
2627
}
27-
}
28-
]
29-
}
28+
]
29+
}
3030
)
3131
}
3232

@@ -36,8 +36,8 @@ resource "aws_iam_role_policy_attachment" "AmazonEKSClusterPolicy" {
3636
}
3737

3838
resource "aws_iam_role_policy_attachment" "AmazonEC2ContainerRegistryReadOnly-EKS" {
39-
policy_arn = "arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly"
40-
role = aws_iam_role.eks_cluster.name
39+
policy_arn = "arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly"
40+
role = aws_iam_role.eks_cluster.name
4141
}
4242

4343

@@ -46,17 +46,17 @@ resource "aws_iam_role" "eks_node_group" {
4646

4747
assume_role_policy = jsonencode(
4848
{
49-
Version = "2012-10-17"
50-
Statement = [
51-
{
52-
Action = "sts:AssumeRole"
53-
Effect = "Allow"
54-
Principal = {
55-
Service = "ec2.amazonaws.com"
49+
Version = "2012-10-17"
50+
Statement = [
51+
{
52+
Action = "sts:AssumeRole"
53+
Effect = "Allow"
54+
Principal = {
55+
Service = "ec2.amazonaws.com"
56+
}
5657
}
57-
}
58-
]
59-
}
58+
]
59+
}
6060
)
6161
}
6262

@@ -65,20 +65,20 @@ resource "aws_iam_role_policy_attachment" "AmazonEKSWorkerNodePolicy" {
6565
role = aws_iam_role.eks_node_group.name
6666
}
6767

68-
resource "aws_iam_role_policy_attachment" "AmazonEKS_CNI_Policy" {
68+
resource "aws_iam_role_policy_attachment" "AmazonEKS_CNI_Policy" {
6969
policy_arn = "arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy"
70-
role = aws_iam_role.eks_node_group.name
71-
}
72-
73-
resource "aws_iam_role_policy_attachment" "EC2InstanceProfileForImageBuilderECRContainerBuilds" {
70+
role = aws_iam_role.eks_node_group.name
71+
}
72+
73+
resource "aws_iam_role_policy_attachment" "EC2InstanceProfileForImageBuilderECRContainerBuilds" {
7474
policy_arn = "arn:aws:iam::aws:policy/EC2InstanceProfileForImageBuilderECRContainerBuilds"
75-
role = aws_iam_role.eks_node_group.name
76-
}
77-
78-
resource "aws_iam_role_policy_attachment" "AmazonEC2ContainerRegistryReadOnly" {
75+
role = aws_iam_role.eks_node_group.name
76+
}
77+
78+
resource "aws_iam_role_policy_attachment" "AmazonEC2ContainerRegistryReadOnly" {
7979
policy_arn = "arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly"
80-
role = aws_iam_role.eks_node_group.name
81-
}
80+
role = aws_iam_role.eks_node_group.name
81+
}
8282

8383
resource "aws_security_group" "eks_control_plane_sg" {
8484
name_prefix = "eks-control-plane-sg"
@@ -119,31 +119,31 @@ resource "aws_security_group" "worker_nodes_sg" {
119119
}
120120

121121
resource "aws_eks_node_group" "ondemand_group" {
122-
cluster_name = aws_eks_cluster.eks_cluster.name
122+
cluster_name = aws_eks_cluster.eks_cluster.name
123123
node_group_name = "ondemand-group"
124124
node_role_arn = aws_iam_role.eks_node_group.arn
125125
subnet_ids = [var.subnet_id_1, var.subnet_id_2]
126126
scaling_config {
127127
desired_size = 2
128-
max_size = 2
129-
min_size = 2
128+
max_size = 2
129+
min_size = 2
130130
}
131131
instance_types = ["t2.medium"]
132-
capacity_type = "ON_DEMAND"
132+
capacity_type = "ON_DEMAND"
133133
}
134134

135135
resource "aws_eks_node_group" "spot_group" {
136-
cluster_name = aws_eks_cluster.eks_cluster.name
136+
cluster_name = aws_eks_cluster.eks_cluster.name
137137
node_role_arn = aws_iam_role.eks_node_group.arn
138138
subnet_ids = [var.subnet_id_1, var.subnet_id_2]
139139
node_group_name = "spot-group"
140140
scaling_config {
141141
desired_size = 2
142-
max_size = 2
143-
min_size = 2
142+
max_size = 2
143+
min_size = 2
144144
}
145145
instance_types = ["t2.medium"]
146-
capacity_type = "SPOT"
146+
capacity_type = "SPOT"
147147

148148
depends_on = [
149149
aws_iam_role_policy_attachment.AmazonEKSWorkerNodePolicy,
@@ -152,7 +152,7 @@ resource "aws_eks_node_group" "spot_group" {
152152
]
153153

154154
remote_access {
155-
ec2_ssh_key = var.key-name
155+
ec2_ssh_key = var.key-name
156156
source_security_group_ids = [aws_security_group.worker_nodes_sg.id]
157157
}
158158
}

environments/test/vpc/variables.tf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,22 @@ variable "cluster_name" {
88
}
99

1010
variable "subnet_id_1" {
11-
type = string
12-
default = "subnet-058a7514ba8adbb07"
11+
type = string
12+
default = "subnet-058a7514ba8adbb07"
1313
}
1414

1515
variable "ami_id" {
1616
type = string
1717
default = "ami-0735c191cf914754d"
1818
}
19-
19+
2020
variable "subnet_id_2" {
21-
type = string
22-
default = "subnet-0dbcd1ac168414927"
21+
type = string
22+
default = "subnet-0dbcd1ac168414927"
2323
}
2424

2525
variable "vpc_id" {
26-
type = string
26+
type = string
2727
default = "vpc-0a5ca4a92c2e10163"
2828
}
2929

0 commit comments

Comments
 (0)