Skip to content

Instantly share code, notes, and snippets.

@nickithewatt
Last active January 22, 2017 01:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickithewatt/23eea1590158df2b8bb054e65dcc06f0 to your computer and use it in GitHub Desktop.
Save nickithewatt/23eea1590158df2b8bb054e65dcc06f0 to your computer and use it in GitHub Desktop.
...
resource "aws_instance" "nginx" {
count = "${var.demo_env_nginx_count}"
connection {
# The default username for our AMI, and use our on the fly created
# private key to do the initial bootstrapping (install of nginx)
user = "ubuntu"
private_key = "${tls_private_key.nginx-provisioner.private_key_pem}"
}
instance_type = "t2.micro"
ami = "${data.aws_ami.ubuntu.id}"
key_name = "${aws_key_pair.nginx-provisioning.id}"
vpc_security_group_ids = ["${aws_security_group.nginx-sg.id}"]
# We're going to launch into the same single (public) subnet as our ELB.
# In a production environment it's more common to have a separate
# private subnet for backend instances.
subnet_id = "${aws_subnet.public.id}"
# 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
provisioner "remote-exec" {
inline = [
"sudo apt-get -y update",
"sudo apt-get -y install nginx",
"sudo sed -i 's/nginx\\!/nginx - instance ${count.index + 1}/g' /var/www/html/index.nginx-debian.html",
"sudo systemctl start nginx",
]
}
}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment