Skip to content

Instantly share code, notes, and snippets.

@koenighotze koenighotze/final.tf
Last active Mar 1, 2018

Embed
What would you like to do?
Terraform config for automagically configuring a simple EC2 with a LAMP stack
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}"
}
@daloulou

This comment has been minimized.

Copy link

commented Mar 1, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.