-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.tf
More file actions
43 lines (33 loc) · 875 Bytes
/
main.tf
File metadata and controls
43 lines (33 loc) · 875 Bytes
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
# Get the latest ubuntu AMI
data "aws_ami" "ubuntu" {
most_recent = true
filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
owners = ["099720109477"] # Canonical
}
# Create an elastic IP
resource "aws_eip" "elastic_ip" {
}
resource "aws_eip_association" "epi_assoc" {
instance_id = aws_instance.app_server.id
allocation_id = aws_eip.elastic_ip.id
}
# Set region
provider "aws" {
profile = "default"
region = "us-east-1"
}
# Create EC2 instance. Attach security groups (defined in security_groups.tf) and key
resource "aws_instance" "app_server" {
ami = data.aws_ami.ubuntu.id
instance_type = "t2.micro"
security_groups = ["sg_nextcloud"]
# Key must already exist in AWS
key_name = "nextcloud-2"
}