-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathec2.tf
38 lines (32 loc) · 824 Bytes
/
ec2.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
# Configure the AWS provider
provider "aws" {
region = "eu-west-1"
}
# Create a Security Group for an EC2 instance
resource "aws_security_group" "instance" {
name = "terraform-example-instance"
ingress {
from_port = 8080
to_port = 8080
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
}
# Create an EC2 instance
resource "aws_instance" "example" {
ami = "ami-785db401"
instance_type = "t2.micro"
vpc_security_group_ids = ["${aws_security_group.instance.id}"]
user_data = <<-EOF
#!/bin/bash
echo "Hello, World" > index.html
nohup busybox httpd -f -p 8080 &
EOF
tags {
Name = "terraform-example"
}
}
# Output variable: Public IP address
output "public_ip" {
value = "${aws_instance.example.public_ip}"
}