Skip to content

Commit 09c16b1

Browse files
author
Kamlesh
committed
terraform 0.11.
0 parents  commit 09c16b1

File tree

7 files changed

+415
-0
lines changed

7 files changed

+415
-0
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Compiled files
2+
*.tfstate
3+
*.tfstate.backup
4+
5+
# Module directory
6+
.terraform
7+
.idea
8+
*.iml

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
AWS ALB
2+
==============
3+
4+
This module is for create alb with related resources.
5+
6+
###### main.tf
7+
contain resource code for alb.
8+
9+
###### variables.tf
10+
contain variables declaration. all variables are empty by default. we will define or put value to variables in equls.tf (main file for infrastructure). these are input vars.
11+
12+
###### outputs.tf
13+
is alse contain variables but we will these variables for output like ec2 instance id.
14+
15+
## Infrastructure creats by this module
16+
17+
1. Alb
18+
2. Alb listener
19+
3. Alb target group
20+
4. Alb target group attachment.
21+
22+
23+
24+

examples/example.tf

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
provider "aws" {
2+
profile = "default"
3+
region = "${var.region}"
4+
}
5+
6+
locals {
7+
public_cidr_block = "${cidrsubnet("10.0.0.0/16", 1, 0)}"
8+
}
9+
10+
module "vpc" {
11+
source = "git::https://github.com/clouddrove/terraform-aws-vpc.git?ref=tags/0.11.0"
12+
cidr_block = "10.0.0.0/16"
13+
name = "vpc"
14+
application = "clouddrove"
15+
environment = "test"
16+
}
17+
18+
19+
module "public_subnets" {
20+
source = "git::https://github.com/clouddrove/terraform-aws-public-subnet.git?ref=tags/0.11.0"
21+
name = "name"
22+
application = "cloudDrove"
23+
environment = "test"
24+
availability_zones = ["us-east-1a", "us-east-1b", "us-east-1c"]
25+
vpc_id = "${module.vpc.vpc_id}"
26+
cidr_block = "${local.public_cidr_block}"
27+
type = "public"
28+
igw_id = "${module.vpc.igw_id}"
29+
nat_gateway_enabled = "false"
30+
}
31+
module "bastion" {
32+
source = "../../terraform-aws-ec2"
33+
name = "${var.name}"
34+
instance_count = 2
35+
36+
application = "${var.application}"
37+
environment = "${var.environment}"
38+
ami = "${var.ami_id}"
39+
instance_type = "${var.instance_type}"
40+
key_name = "${var.key_name}"
41+
monitoring = false
42+
vpc_security_group_ids_list = ["${module.sg.security_group_ids}"]
43+
subnet = "${var.subnet}"
44+
ebs_volume_count = "0"
45+
disk_size = 10
46+
user_data_base64 = "${base64encode("${file("../_bin/user_data.sh")}")}"
47+
}
48+
49+
module "sg" {
50+
source = "git::https://github.com/clouddrove/terraform-aws-security-group.git?ref=tags/0.11.0"
51+
name = "${var.name}"
52+
application = "${var.application}"
53+
environment = "${var.environment}"
54+
vpc_id = "${var.vpc_id}"
55+
cidr_blocks = "${var.source_ip}"
56+
allowed_ports = [
57+
22]
58+
59+
}
60+
module "alb" {
61+
source = "./../"
62+
application = "dev"
63+
environment = "${var.environment}"
64+
65+
name = "backend"
66+
internal = false
67+
load_balancer_type = "application"
68+
security_groups = ["${module.sg.security_group_ids}"]
69+
subnets = ["subnet-0399c34a","subnet-18d8ad35"]
70+
enable_deletion_protection = false
71+
listener_port = 443
72+
listener_protocol = "HTTPS"
73+
vpc_id = "vpc-7478c912"
74+
instance_count = 1
75+
target_id = ["i-08da6f78390d2a8c6",]
76+
target_group_protocol = "HTTP"
77+
target_group_port = 80
78+
target_group_attachment_port = 80
79+
listener_certificate_arn = "arn:aws:acm:us-east-1:946010253026:certificate/17247909-1d93-4dbb-80a6-32a31a9a4b9f"
80+
log_bucket_name = "cloudrove-logs"
81+
}

examples/varible.tf

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
variable "region" {
2+
default = "us-east-1"
3+
}
4+
variable "name" {
5+
type = "string"
6+
description = "Name (e.g. `app` or `cluster`)"
7+
}
8+
9+
variable "application" {
10+
type = "string"
11+
description = "Application (e.g. `cd` or `clouddrove`)"
12+
}
13+
14+
variable "environment" {
15+
type = "string"
16+
description = "Environment (e.g. `prod`, `dev`, `staging`)"
17+
}
18+
19+
variable "vpc_id" {
20+
type = "string"
21+
description = ""
22+
}
23+
24+
variable "source_ip" {
25+
type = "list"
26+
description = ""
27+
}
28+
29+
variable "instance_type" {
30+
type = "string"
31+
description = ""
32+
default = "t2.micro"
33+
}
34+
35+
variable "key_name" {
36+
type = "string"
37+
description = ""
38+
}
39+
40+
variable "ami_id" {
41+
type = "string"
42+
description = ""
43+
}
44+
45+
variable "subnet" {
46+
type = "string"
47+
description = ""
48+
}
49+
50+
variable "disk_size" {
51+
description = "Size of the root volume in gigabytes"
52+
default = "8"
53+
}
54+
55+
variable "user_data_base64" {
56+
type = "string"
57+
description = "The Base64-encoded user data to provide when launching the instances"
58+
default = ""
59+
}

main.tf

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
module "label" {
2+
source = "git::https://github.com/clouddrove/terraform-lables.git?ref=tags/0.11.0"
3+
name = "${var.name}"
4+
application = "${var.application}"
5+
environment = "${var.environment}"
6+
}
7+
## ALB
8+
resource "aws_lb" "main" {
9+
name = "${module.label.id}"
10+
internal = "${var.internal}"
11+
load_balancer_type = "${var.load_balancer_type}"
12+
security_groups = ["${var.security_groups}"]
13+
subnets = ["${var.subnets}"]
14+
enable_deletion_protection = "${var.enable_deletion_protection}"
15+
idle_timeout = "${var.idle_timeout}"
16+
enable_cross_zone_load_balancing = "${var.enable_cross_zone_load_balancing}"
17+
enable_http2 = "${var.enable_http2}"
18+
ip_address_type = "${var.ip_address_type}"
19+
tags = "${module.label.tags}"
20+
21+
timeouts {
22+
create = "${var.load_balancer_create_timeout}"
23+
delete = "${var.load_balancer_delete_timeout}"
24+
update = "${var.load_balancer_update_timeout}"
25+
}
26+
access_logs {
27+
enabled = "${var.access_logs}"
28+
bucket = "${var.log_bucket_name}"
29+
prefix = "${module.label.id}"
30+
}
31+
}
32+
33+
34+
##### ALB LISTENER
35+
36+
resource "aws_lb_listener" "front_end" {
37+
load_balancer_arn = "${aws_lb.main.arn}"
38+
port = "${var.listener_port}"
39+
protocol = "${var.listener_protocol}"
40+
ssl_policy = "${var.listener_ssl_policy}"
41+
certificate_arn = "${var.listener_certificate_arn}"
42+
default_action {
43+
target_group_arn = "${aws_lb_target_group.main.arn}"
44+
type = "forward"
45+
}
46+
}
47+
48+
##### ALB TARGET GROUP
49+
50+
resource "aws_lb_target_group" "main" {
51+
name = "${module.label.id}"
52+
port = "${var.target_group_port}"
53+
protocol = "${var.target_group_protocol}"
54+
vpc_id = "${var.vpc_id}"
55+
}
56+
57+
58+
##### ALB TARGET GROUP ATTACHMENT 1
59+
60+
resource "aws_lb_target_group_attachment" "attachment1" {
61+
count = "${var.instance_count}"
62+
target_group_arn = "${aws_lb_target_group.main.arn}"
63+
target_id = "${element(var.target_id, count.index)}"
64+
port = "${var.target_group_attachment_port}"
65+
}
66+

outputs.tf

Whitespace-only changes.

0 commit comments

Comments
 (0)