Forked from devops-school/terraform-aws-ec2-instance-remote-exec-provisioner.tf
Created
August 1, 2024 21:15
-
-
Save fbatroni/ead99f1c4c7bd35fe0b7c8e75c685b56 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