-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
81 lines (65 loc) · 1.48 KB
/
main.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
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
}
}
}
provider "aws" {
region = "eu-north-1"
}
resource "aws_instance" "ec2-t3micro-zsfolio" {
ami = "ami-0014ce3e52359afbd"
instance_type = "t3.small"
key_name = var.ssh_key_name
vpc_security_group_ids = [aws_security_group.securityGroup-zsfolio.id]
tags = {
Name = var.prefix,
Value = "zs-portfolio"
}
user_data = data.template_file.userdata.rendered
provisioner "file" {
source = "./scripts/jenkins.sh"
destination = "/home/ubuntu/jenkins.sh"
}
volume_tags = {
Name = var.prefix,
Value = "zs-portfolio"
}
connection {
type = "ssh"
user = "ubuntu"
private_key = file(var.ssh_private_key_path)
host = self.public_ip
}
provisioner "remote-exec" {
inline = [
"sudo chmod +x jenkins.sh",
]
}
}
locals {
ingress_ports = [22,25, 443, 3000, 8080]
}
resource "aws_security_group" "securityGroup-zsfolio" {
name = "${var.prefix}-SG"
dynamic "ingress" {
for_each = local.ingress_ports
iterator = port
content {
from_port = port.value
protocol = "tcp"
to_port = port.value
cidr_blocks = ["0.0.0.0/0"]
}
}
egress {
from_port = 0
protocol = -1
to_port = 0
cidr_blocks = ["0.0.0.0/0"]
}
}
data "template_file" "userdata" {
template = file("${abspath(path.module)}/scripts/jenkins.sh")
}