-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
84 lines (69 loc) · 1.69 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
##############
# Data sources
##############
# Get instance image ID
data "aws_ami" "ami" {
most_recent = true
owners = ["self"]
filter {
name = "name"
values = ["cmdbuild"]
}
}
# Get the default VPC id to deploy the security group
data "aws_vpc" "main" {
id = var.vpc_id
}
resource "aws_instance" "cmdbuild" {
ami = data.aws_ami.ami.id
instance_type = var.instance_type
# the VPC subnet
subnet_id = var.subnet_id
# the security group
vpc_security_group_ids = [aws_security_group.allow-http.id]
associate_public_ip_address = var.associate_public_ip_address
# the public SSH key
key_name = var.key_name
depends_on = [resource.local_sensitive_file.private_key]
}
resource "aws_security_group" "allow-http" {
vpc_id = data.aws_vpc.main.id
name = "allow-http"
description = "security group that allows http, shh and all egress traffic"
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 8080
to_port = 8080
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
tags = {
Name = "allow-http"
}
}
################
# Key Pair
################
resource "tls_private_key" "private_key" {
algorithm = "RSA"
rsa_bits = 4096
}
resource "aws_key_pair" "private_key" {
key_name = var.key_name
public_key = tls_private_key.private_key.public_key_openssh
}
resource "local_sensitive_file" "private_key" {
content = tls_private_key.private_key.private_key_pem
filename = "artifacts/private.pem"
}