Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save devops-school/a90d0bfd77b2be624bb76cc9d504863e to your computer and use it in GitHub Desktop.
Save devops-school/a90d0bfd77b2be624bb76cc9d504863e to your computer and use it in GitHub Desktop.
Terrafrom - Example Code for AWS ec2-instance and remote-exec provisioner
provider "aws" {
profile = "default"
region = "us-west-2"
}
resource "aws_key_pair" "example" {
key_name = "examplekey"
public_key = file("~/.ssh/terraform.pub")
}
resource "aws_instance" "example" {
key_name = aws_key_pair.example.key_name
ami = "ami-04590e7389a6e577c"
instance_type = "t2.micro"
connection {
type = "ssh"
user = "ec2-user"
private_key = file("~/.ssh/terraform")
host = self.public_ip
}
provisioner "remote-exec" {
inline = [
"sudo amazon-linux-extras enable nginx1.12",
"sudo yum -y install nginx",
"sudo systemctl start nginx"
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment