-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
88 lines (74 loc) · 2.26 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
82
83
84
85
86
87
88
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.27"
}
}
required_version = ">= 0.14.9"
}
##################################################################################
# PROVIDERS
##################################################################################
provider "aws" {
access_key = var.aws_access_key
secret_key = var.aws_secret_key
region = var.aws_region
}
##################################################################################
# RESOURCES
##################################################################################
# SECURITY GROUPS #
# Nginx security group
resource "aws_security_group" "nginx-sg" {
name = "nginx-sg"
tags = local.common_tags
# HTTP access from anywhere
ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
# HTTPS access from anywhere
ingress {
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
# outbound internet access
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_security_group" "ssh-sg" {
name = "ssh-sg"
tags = local.common_tags
# SSH access from anywhere
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
}
# INSTANCES #
resource "aws_instance" "intime_server" {
ami = "ami-04505e74c0741db8d"
instance_type = var.instance_type
associate_public_ip_address = true
vpc_security_group_ids = [aws_security_group.nginx-sg.id, aws_security_group.ssh-sg.id]
key_name = var.key_name
tags = local.common_tags
user_data = <<EOF
#! /bin/bash
apt install -y nginx git
service nginx start
rm /usr/share/nginx/html/index.html
echo '<html><head><title>Intime Test Server</title></head><body style=\"background-color:#1F778D\"><p style=\"text-align: center;\"><span style=\"color:#FFFFFF;\"><span style=\"font-size:28px;\">Intime is live</span></span></p></body></html>' | sudo tee /var/www/html/index.html
EOF
}