-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.tf.v2
More file actions
62 lines (50 loc) · 1.09 KB
/
main.tf.v2
File metadata and controls
62 lines (50 loc) · 1.09 KB
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
# Provider
provider "aws" {
region = "ap-northeast-1"
}
# data
data "aws_ami" "recent_amazon_linux_2" {
most_recent = true
owners = ["amazon"]
filter {
name = "name"
values = ["amzn2-ami-hvm-2.0.????????-x86_64-gp2"]
}
filter {
name = "state"
values = ["available"]
}
}
# local変数
locals {
example_instance_type = "t3.micro"
}
# resource security group
resource "aws_security_group" "example_ec2" {
name = "example-ec2"
ingress {
from_port = 80
to_port = 80
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"]
}
}
# resource instance
resource "aws_instance" "example" {
ami = data.aws_ami.recent_amazon_linux_2.image_id
instance_type = local.example_instance_type
vpc_security_group_ids = [aws_security_group.example_ec2.id]
user_data = file("./user_data.sh")
}
output "example_instance_id" {
value = aws_instance.example.id
}
output "example_public_dns" {
value = aws_instance.example.public_dns
}