Created
July 5, 2020 06:22
-
-
Save devops-school/a90d0bfd77b2be624bb76cc9d504863e to your computer and use it in GitHub Desktop.
Terrafrom - Example Code for AWS ec2-instance and remote-exec provisioner
This file contains 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" { | |
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