Skip to content

Commit e9bb686

Browse files
committed
Added new folder with Terraform v13 compataible code
1 parent 17216a4 commit e9bb686

18 files changed

+1342
-0
lines changed
+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
2+
<h1>Setup Requirements</h1><br />
3+
4+
```
5+
1. Terraform binary => 0.12.x # wget -c https://releases.hashicorp.com/terraform/0.12.28/terraform_0.12.28_linux_amd64.zip
6+
2. Python3 & PIP needs to be installed on all nodes(on most , modern Linux systems it's available by default) # yum -y install python3-pip
7+
3. Ansible (install via pip) # pip3 install ansible --user
8+
4. AWS CLI (install via pip) # pip3 install awscli --user
9+
5. jq (install via package manager) - OPTIONAL # yum -y install jq
10+
```
11+
12+
`This project has been tested on MacOS(Mojave), CentOS7. Author provides no guarantees for working with other OS's,
13+
although the steps are generic enough that with little tweaking or even with no tweaking this might work
14+
on a range of OS's which support above 5 requirments.`
15+
16+
<h2>Notes and Instructions</h2><br />
17+
18+
*For Terraform Part*
19+
```
20+
The regional AWS providers are defined in providers.tf
21+
Terraform configuration and backend is defined in backend.tf.
22+
23+
24+
If you want to read and understand the deployment in sequence. Read through templates in the following order:
25+
1. network_setup.tf
26+
2. instances.tf --> local-exec provisioners in this templates kick-off Ansible playbooks in ansible_templates/
27+
3. alb_acm.tf
28+
4. dns.tf
29+
```
30+
*S3 Backend*
31+
```
32+
This project requires an S3 backend for storing Terraform state file, therefore in the terraform block in the backend.tf file you'll need to plug in the an actual bucket name before you can run "terraform init".
33+
Please also note that the "terraform" block does not allow usage of variables so values HAVE to be hardcoded.
34+
```
35+
Sample command for bucket creation via CLI:
36+
```
37+
aws s3api create-bucket --bucket <YOUR-UNIQUE-BUCKET-NAME-GOES-HERE>
38+
```
39+
40+
Example
41+
```
42+
aws s3api create-bucket --bucket myawesomebucketthatmayormaynotexistalready
43+
```
44+
45+
<h2>Supplementary files </h2> <br />
46+
47+
```
48+
1. ansible.cfg #A modified Ansible default config file with SSH host key checking and warnings disabled
49+
2. aws_get_cp_hostedzone #An AWS CLI command for fetching your hosted zone for DNS part of this project
50+
3. null_provisioners.tf #For setting up and deleting Ansible inventory files
51+
4. variables.tf #Defines variables and default values for them for the TF templates
52+
5. outputs.tf #Defines the outputs presented at successful completion of execution of TF apply.
53+
```
54+
55+
<h2>Ansible playbooks</h2><br />
56+
57+
```
58+
1. cred-privkey.j2 #Jinja template for creating Jenkins credentials via Jenkins API call(populates private key)
59+
2. install_jenkins.yaml #Playbook for Jenkins Master
60+
3. install_worker.yaml #Playbook for Jenkins Worker
61+
4. node.j2 #Jinja templates for registering worker node with Jenkins Master via Jenkins CLI(populates IP)
62+
5. jenkins_auth #Provides the file with preset credentials for our Jenkins Master
63+
```
+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#ACM CONFIGURATION
2+
#Creates ACM issues certificate and requests validation via DNS(Route53)
3+
resource "aws_acm_certificate" "jenkins-lb-https" {
4+
provider = aws.region-master
5+
domain_name = join(".", ["jenkins", data.aws_route53_zone.dns.name])
6+
validation_method = "DNS"
7+
tags = {
8+
Name = "Jenkins-ACM"
9+
}
10+
11+
}
12+
13+
#Validates ACM issued certificate via Route53
14+
resource "aws_acm_certificate_validation" "cert" {
15+
provider = aws.region-master
16+
certificate_arn = aws_acm_certificate.jenkins-lb-https.arn
17+
for_each = aws_route53_record.cert_validation
18+
validation_record_fqdns = [aws_route53_record.cert_validation[each.key].fqdn]
19+
}
20+
21+
####ACM CONFIG END
22+
23+
24+
resource "aws_lb" "application-lb" {
25+
provider = aws.region-master
26+
name = "jenkins-lb"
27+
internal = false
28+
load_balancer_type = "application"
29+
security_groups = [aws_security_group.lb-sg.id]
30+
subnets = [aws_subnet.subnet_1.id, aws_subnet.subnet_2.id]
31+
tags = {
32+
Name = "Jenkins-LB"
33+
}
34+
}
35+
36+
resource "aws_lb_target_group" "app-lb-tg" {
37+
provider = aws.region-master
38+
name = "app-lb-tg"
39+
port = 8080
40+
target_type = "instance"
41+
vpc_id = aws_vpc.vpc_master.id
42+
protocol = "HTTP"
43+
health_check {
44+
enabled = true
45+
interval = 10
46+
path = "/login"
47+
port = 8080
48+
protocol = "HTTP"
49+
matcher = "200-299"
50+
}
51+
tags = {
52+
Name = "jenkins-target-group"
53+
}
54+
}
55+
56+
resource "aws_lb_listener" "jenkins-listener" {
57+
provider = aws.region-master
58+
load_balancer_arn = aws_lb.application-lb.arn
59+
ssl_policy = "ELBSecurityPolicy-2016-08"
60+
port = "443"
61+
protocol = "HTTPS"
62+
certificate_arn = aws_acm_certificate.jenkins-lb-https.arn
63+
default_action {
64+
type = "forward"
65+
target_group_arn = aws_lb_target_group.app-lb-tg.arn
66+
}
67+
}
68+
69+
resource "aws_lb_listener" "jenkins-listener-http" {
70+
provider = aws.region-master
71+
load_balancer_arn = aws_lb.application-lb.arn
72+
port = "80"
73+
protocol = "HTTP"
74+
default_action {
75+
type = "redirect"
76+
redirect {
77+
port = "443"
78+
protocol = "HTTPS"
79+
status_code = "HTTP_301"
80+
}
81+
}
82+
}
83+
84+
resource "aws_lb_target_group_attachment" "jenkins-master-attach" {
85+
provider = aws.region-master
86+
target_group_arn = aws_lb_target_group.app-lb-tg.arn
87+
target_id = aws_instance.jenkins-master.id
88+
port = 8080
89+
}

0 commit comments

Comments
 (0)