-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.tf
51 lines (46 loc) · 1.41 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
provider "aws" {
access_key = "<your-access-key>"
secret_key = "<your-secret-key>"
region = "eu-central-1"
}
data "aws_vpc" "default" {
default = true
}
data "aws_subnets" "all" {
filter {
name = "vpc-id"
values = [data.aws_vpc.default.id]
}
}
data "aws_ami" "amazon_linux" {
most_recent = true
owners = ["amazon"]
filter {
name = "name"
values = ["amzn2-ami-hvm-*-x86_64-gp2"]
}
filter {
name = "owner-alias"
values = ["amazon"]
}
}
module "security_group" {
source = "terraform-aws-modules/security-group/aws"
name = "image-compressor-aws-modules-sg"
description = "Security group made using an AWS module"
vpc_id = data.aws_vpc.default.id
ingress_cidr_blocks = ["0.0.0.0/0"]
ingress_rules = ["http-80-tcp", "all-icmp", "ssh-tcp"]
egress_rules = ["all-all"]
}
module "ec2" {
source = "terraform-aws-modules/ec2-instance/aws"
name = "image-compressor-aws-modules-ec2"
ami = data.aws_ami.amazon_linux.id
instance_type = "t2.micro"
key_name = "flask-app"
subnet_id = tolist(data.aws_subnets.all.ids)[0]
vpc_security_group_ids = [module.security_group.security_group_id]
associate_public_ip_address = true
user_data = file("./provision.sh")
}