-
Notifications
You must be signed in to change notification settings - Fork 1
/
pipeline.tf
154 lines (136 loc) · 3.54 KB
/
pipeline.tf
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
resource "aws_instance" "pipeline" {
ami = "${data.aws_ami.latest-ubuntu.id}"
instance_type = "t2.micro"
key_name= "aws_key"
vpc_security_group_ids = [aws_security_group.pipeline-public-SSH.id,aws_security_group.pipeline-public-sphinxdoc.id,aws_security_group.pipeline-public-sphinxdoc-prod.id]
root_block_device {
delete_on_termination = true
volume_size = 20
}
provisioner "local-exec" {
//Added sleep to give VM time to setup SSH
command = "sleep 30s && ssh-keyscan -v -H ${self.public_ip} >> ~/.ssh/known_hosts"
}
provisioner "remote-exec" {
connection {
type = "ssh"
host = self.public_ip
user = "ubuntu"
private_key = file("project")
timeout = "4m"
}
inline = [
"touch hello.txt",
"echo helloworld remote provisioner >> hello.txt",
]
}
tags = {
Name = "pipeline"
}
}
//You need a security group to open up SSH
resource "aws_security_group" "pipeline-public-SSH" {
egress = [
{
cidr_blocks = [ "0.0.0.0/0", ]
description = ""
from_port = 0
ipv6_cidr_blocks = []
prefix_list_ids = []
protocol = "-1"
security_groups = []
self = false
to_port = 0
}
]
ingress = [
{
cidr_blocks = [ "0.0.0.0/0", ]
description = ""
from_port = 22
ipv6_cidr_blocks = []
prefix_list_ids = []
protocol = "tcp"
security_groups = []
self = false
to_port = 22
}
]
tags = {
Name = "SSH-pipeline-Public"
}
}
resource "aws_security_group" "pipeline-public-sphinxdoc" {
egress = [
{
cidr_blocks = [ "0.0.0.0/0", ]
description = ""
from_port = 0
ipv6_cidr_blocks = []
prefix_list_ids = []
protocol = "-1"
security_groups = []
self = false
to_port = 0
}
]
ingress = [
{
cidr_blocks = [ "0.0.0.0/0", ]
description = ""
from_port = 8080
ipv6_cidr_blocks = []
prefix_list_ids = []
protocol = "tcp"
security_groups = []
self = false
to_port = 8080
}
]
tags = {
Name = "pipeline-Public-Jenkins"
}
}
resource "aws_security_group" "pipeline-public-sphinxdoc-prod" {
egress = [
{
cidr_blocks = [ "0.0.0.0/0", ]
description = ""
from_port = 0
ipv6_cidr_blocks = []
prefix_list_ids = []
protocol = "-1"
security_groups = []
self = false
to_port = 0
}
]
ingress = [
{
cidr_blocks = [ "0.0.0.0/0", ]
description = ""
from_port = 80
ipv6_cidr_blocks = []
prefix_list_ids = []
protocol = "tcp"
security_groups = []
self = false
to_port = 80
}
]
tags = {
Name = "pipeline-Public-sphinxdoc"
}
}
# resource block for eip #
resource "aws_eip" "pipeline" {
vpc = true
instance = aws_instance.pipeline.id
associate_with_private_ip = aws_instance.pipeline.private_ip
depends_on = [aws_instance.pipeline]
}
# resource block for ec2 and eip (Elastic IP) association #
# resource "aws_eip_association" "eip_assoc" {
# instance_id = aws_instance.builder.id
# allocation_id = aws_eip.myeip.id
# }