-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.tf
73 lines (67 loc) · 1.7 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
variable "associate_public_ip" {
default = true
}
variable "public_key" {}
variable "image" {}
variable "disk" {}
variable "instance_type" {}
variable "volume_encrypted" {
default = true
}
variable "volume_delete_on_termination" {
default = true
}
variable "name" {}
variable "subnet" {}
variable "vpc_security_group_id" {}
variable "access_key" {}
variable "secret_key" {}
variable "region" {}
variable "tag_provisioner" {
default = "terraform"
}
variable "tag_owner" {
default = "hobbyfarm"
}
variable "volume_type" {
default = "gp3"
}
variable "cloud-config" {}
provider "aws" {
access_key = var.access_key
secret_key = var.secret_key
region = var.region
}
resource "aws_key_pair" "instance_keypair" {
key_name = "${var.name}-keypair"
public_key = var.public_key
}
resource "aws_instance" "instance" {
ami = var.image
instance_type = var.instance_type
key_name = aws_key_pair.instance_keypair.key_name
subnet_id = var.subnet
vpc_security_group_ids = ["${var.vpc_security_group_id}"]
associate_public_ip_address = var.associate_public_ip
user_data = var.cloud-config
tags = {
Name = var.name
Owner = var.tag_owner
provisioner = var.tag_provisioner
}
root_block_device {
volume_type = var.volume_type
volume_size = var.disk
encrypted = var.volume_encrypted
delete_on_termination = var.volume_delete_on_termination
}
}
output "private_ip" {
value = aws_instance.instance.private_ip
}
output "public_ip" {
value = aws_instance.instance.public_ip
}
output "hostname" {
value = aws_instance.instance.public_dns
}