Skip to content

Instantly share code, notes, and snippets.

@ian-bartholomew
Last active August 26, 2019 19:08
Show Gist options
  • Save ian-bartholomew/f477fcac985486f8e2ee1cee81fb013b to your computer and use it in GitHub Desktop.
Save ian-bartholomew/f477fcac985486f8e2ee1cee81fb013b to your computer and use it in GitHub Desktop.
Terraform Hello World
provider "aws" {
region = "us-east-1"
}
resource "aws_security_group" "instance" {
name = "terraform-example-instance"
ingress {
from_port = "${var.server_port}"
to_port = "${var.server_port}"
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_instance" "web" {
ami = "ami-2d39803a"
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 "public_ip" {
value = "${aws_instance.web.public_ip}"
}
variable "server_port" {
description = "The port the server will use for HTTP requests"
default = 8080
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment