forked from squad12-devops/case-study
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.tf
More file actions
120 lines (105 loc) · 3.11 KB
/
main.tf
File metadata and controls
120 lines (105 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
locals {
vpc_id = "vpc-b31390d8"
subnet_id = "subnet-1ee94375"
ssh_user = "ubuntu"
pvt_key = "~/dhaba/key/squad12.pem"
key_name = "squad12key"
ubuntu184 = "ami-01e7ca2ef94a0ae86"
medium = "t2.medium"
micro = "t2.micro"
large = "t2.2xlarge"
}
#### Cloud Provider ####
provider "aws" {
region = "us-east-2"
}
# Build Server
resource "aws_instance" "squad12Build" {
ami = local.ubuntu184
subnet_id = local.subnet_id
instance_type = local.large
associate_public_ip_address = true
security_groups=[aws_security_group.squad12sg.id]
key_name = local.key_name
tags = {
Name = "squad12-Build"
}
provisioner "remote-exec" {
inline = ["echo wait for SSH","wget https://raw.githubusercontent.com/squad12-devops/case-study/main/build.sh","sudo bash build.sh","sudo wget http://www-us.apache.org/dist/maven/maven-3/3.5.4/binaries/apache-maven-3.5.4-bin.tar.gz","sudo tar -xvf apache-maven-3.5.4-bin.tar.gz -C /root","docker pull squad12devops/squad12-jenkins-docker-image:latest","echo Done!"]
connection {
type = "ssh"
user = local.ssh_user
private_key = file(local.pvt_key)
host = aws_instance.squad12Build.public_ip
}
}
}
# Test Server
resource "aws_instance" "squad12Test" {
ami = local.ubuntu184
subnet_id = local.subnet_id
instance_type = local.large
associate_public_ip_address = true
security_groups=[aws_security_group.squad12sg.id]
key_name = local.key_name
tags = {
Name = "squad12-Test"
}
provisioner "remote-exec" {
inline = ["echo wait for SSH","wget https://raw.githubusercontent.com/squad12-devops/case-study/main/nodes.sh","sudo bash nodes.sh","echo Done!"]
connection {
type = "ssh"
user = local.ssh_user
private_key = file(local.pvt_key)
host = aws_instance.squad12Test.public_ip
}
}
}
# Prod Server
resource "aws_instance" "squad12Prod" {
ami = local.ubuntu184
subnet_id = local.subnet_id
instance_type = local.large
associate_public_ip_address = true
security_groups=[aws_security_group.squad12sg.id]
key_name = local.key_name
tags = {
Name = "squad12-Prod"
}
provisioner "remote-exec" {
inline = ["echo wait for SSH","wget https://raw.githubusercontent.com/squad12-devops/case-study/main/nodes.sh","sudo bash nodes.sh","echo Done!"]
connection {
type = "ssh"
user = local.ssh_user
private_key = file(local.pvt_key)
host = aws_instance.squad12Prod.public_ip
}
}
}
output "JIRA" {
value = "https://12squaddevops.atlassian.net/"
}
output "GitHub" {
value = "https://github.com/squad12-devops/case-study"
}
output "Jenkins" {
value = aws_instance.squad12Build.public_ip
}
output "SonarQube" {
value = "SonarQube URL"
}
output "Slack" {
value = "https://https://app.slack.com/client/T01PFJ01H51/C01PFJ2AZ0B"
}
output "Artifactory" {
value = "https://squad12devops.jfrog.io/ui/login/"
}
output "Blazemeter" {
value = "blazemeter URL"
}
output "QAWebapp" {
value = aws_instance.squad12Test.public_ip
}
output "ProdWebapp" {
value = aws_instance.squad12Prod.public_ip
}