2015-06-09 21:57:17 +02:00
|
|
|
# Specify the provider and access details
|
|
|
|
provider "aws" {
|
2015-08-31 10:19:02 +02:00
|
|
|
region = "${var.aws_region}"
|
2015-06-09 21:57:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_eip" "default" {
|
2015-08-31 10:19:02 +02:00
|
|
|
instance = "${aws_instance.web.id}"
|
2016-09-22 13:49:09 +02:00
|
|
|
vpc = true
|
2015-06-09 21:57:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Our default security group to access
|
|
|
|
# the instances over SSH and HTTP
|
|
|
|
resource "aws_security_group" "default" {
|
2016-09-22 13:49:09 +02:00
|
|
|
name = "eip_example"
|
2015-08-31 10:19:02 +02:00
|
|
|
description = "Used in the terraform"
|
2015-06-09 21:57:17 +02:00
|
|
|
|
2015-08-31 10:19:02 +02:00
|
|
|
# SSH access from anywhere
|
|
|
|
ingress {
|
2016-09-22 13:49:09 +02:00
|
|
|
from_port = 22
|
|
|
|
to_port = 22
|
|
|
|
protocol = "tcp"
|
2015-08-31 10:19:02 +02:00
|
|
|
cidr_blocks = ["0.0.0.0/0"]
|
|
|
|
}
|
2015-06-09 21:57:17 +02:00
|
|
|
|
2015-08-31 10:19:02 +02:00
|
|
|
# HTTP access from anywhere
|
|
|
|
ingress {
|
2016-09-22 13:49:09 +02:00
|
|
|
from_port = 80
|
|
|
|
to_port = 80
|
|
|
|
protocol = "tcp"
|
2015-08-31 10:19:02 +02:00
|
|
|
cidr_blocks = ["0.0.0.0/0"]
|
|
|
|
}
|
2015-06-09 21:57:17 +02:00
|
|
|
|
2015-08-31 10:19:02 +02:00
|
|
|
# outbound internet access
|
|
|
|
egress {
|
2016-09-22 13:49:09 +02:00
|
|
|
from_port = 0
|
|
|
|
to_port = 0
|
|
|
|
protocol = "-1"
|
2015-08-31 10:19:02 +02:00
|
|
|
cidr_blocks = ["0.0.0.0/0"]
|
|
|
|
}
|
2015-06-09 21:57:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_instance" "web" {
|
|
|
|
instance_type = "t2.micro"
|
|
|
|
|
|
|
|
# Lookup the correct AMI based on the region
|
|
|
|
# we specified
|
|
|
|
ami = "${lookup(var.aws_amis, var.aws_region)}"
|
|
|
|
|
|
|
|
# The name of our SSH keypair you've created and downloaded
|
|
|
|
# from the AWS console.
|
|
|
|
#
|
|
|
|
# https://console.aws.amazon.com/ec2/v2/home?region=us-west-2#KeyPairs:
|
|
|
|
#
|
|
|
|
key_name = "${var.key_name}"
|
|
|
|
|
|
|
|
# Our Security group to allow HTTP and SSH access
|
|
|
|
security_groups = ["${aws_security_group.default.name}"]
|
|
|
|
|
|
|
|
# We run a remote provisioner on the instance after creating it.
|
|
|
|
# In this case, we just install nginx and start it. By default,
|
|
|
|
# this should be on port 80
|
|
|
|
user_data = "${file("userdata.sh")}"
|
2016-09-22 13:49:09 +02:00
|
|
|
|
2015-06-09 21:57:17 +02:00
|
|
|
#Instance tags
|
2015-08-31 10:19:02 +02:00
|
|
|
tags {
|
|
|
|
Name = "eip-example"
|
|
|
|
}
|
2015-06-09 22:24:05 +02:00
|
|
|
}
|