Last active
March 1, 2018 13:51
-
-
Save koenighotze/362a0903d0121a4ce7e71b6fdd84cac8 to your computer and use it in GitHub Desktop.
Terraform config for automagically configuring a simple EC2 with a LAMP stack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
provider "aws" { | |
region = "eu-west-1" | |
} | |
resource "aws_instance" "stage1" { | |
instance_type = "t2.micro" | |
ami = "ami-a8d2d7ce" | |
vpc_security_group_ids = ["${aws_security_group.stage1-sec-group.id}"] | |
key_name = "terraform-test-key" | |
provisioner "remote-exec" { | |
inline = [ | |
"sudo apt update", | |
"sudo apt -q -y upgrade", | |
"DEBIAN_FRONTEND=noninteractive sudo -E apt install -q -y lamp-server^", | |
"cd /var/www/html/", | |
"sudo mv index.html index.html.backup", | |
"sudo echo 'Hello World' | sudo tee index.html" | |
] | |
connection { | |
timeout = "5m" | |
user = "ubuntu" | |
} | |
} | |
tags { | |
Name = "stage1" | |
} | |
} | |
resource "aws_security_group" "stage1-sec-group" { | |
name = "Allow SSH" | |
ingress { | |
from_port = 22 | |
to_port = 22 | |
protocol = "tcp" | |
cidr_blocks = ["0.0.0.0/0"] | |
} | |
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"] | |
} | |
tags { | |
Name = "stage1" | |
} | |
} | |
resource "aws_eip" "ip" { | |
instance = "${aws_instance.stage1.id}" | |
} | |
output "ip" { | |
value = "${aws_eip.ip.public_ip}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
I'm trying to implement this use case but i'm still having the timeout issue and i don't really understand how you fixed it.
Thank you in advance.
Dan