-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.tf
91 lines (81 loc) · 1.97 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
89
90
91
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~>4.8.0"
}
}
}
provider "aws" {
region = var.region
}
# Latest Amazon LINUX 2 AMI
data "aws_ami" "amazon-linux-2" {
most_recent = true
owners = ["amazon"]
filter {
name = "name"
values = ["amzn2-ami-hvm-*-gp2"]
}
filter {
name = "root-device-type"
values = ["ebs"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
filter {
name = "architecture"
values = ["x86_64"]
}
}
# limit SSH, HTTP and API (8080) ports to my IP
resource "aws_security_group" "hashicups-sg" {
name = "${var.prefix}-${var.environment}-hashicups-sg"
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 8080
to_port = 8080
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
prefix_list_ids = []
}
tags = {
Name = "${var.prefix}-${var.environment}-hashicups-sg"
}
}
# Provision in default VPC and subnet. Make sure the routing tables provide internet access
resource "aws_instance" "hashicups-docker-server" {
ami = "${data.aws_ami.amazon-linux-2.id}"
associate_public_ip_address = true
iam_instance_profile = var.iam_role_name
instance_type = var.instance_type
key_name = var.keypair
vpc_security_group_ids = ["${aws_security_group.hashicups-sg.id}"]
user_data = templatefile("${path.module}/configs/deploy_app.tpl", {})
tags = {
Name = "${var.prefix}-${var.environment}-hashicups-app"
Owner = "${var.prefix}"
Purpose = "Field Demo 1"
Project = "Proj1"
Environment = "${var.environment}"
}
}