Skip to content

Instantly share code, notes, and snippets.

@ThakurPriyanka
Created June 20, 2018 04:53
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 ThakurPriyanka/63aabe210ad4b6fcc56d48e4bb5f46e6 to your computer and use it in GitHub Desktop.
Save ThakurPriyanka/63aabe210ad4b6fcc56d48e4bb5f46e6 to your computer and use it in GitHub Desktop.
data "aws_ami" "ubuntu" {
most_recent = true
filter {
name = "name"
values = ["${var.image_name}"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
owners = [981997154569]
}
resource "aws_key_pair" "mykey" {
key_name = "mykey"
public_key = "${file("${var.PATH_TO_PUBLIC_KEY}")}"
}
resource "aws_instance" "bootstrap" {
ami = "${data.aws_ami.ubuntu.id}"
instance_type = "t2.micro"
key_name = "${aws_key_pair.mykey.key_name}"
count = "1"
provisioner "file" {
source = "program/hello-world.sh"
destination = "/tmp/hello-world.sh"
}
provisioner "remote-exec" {
inline = [
"chmod +x /tmp/hello-world.sh",
"/tmp/hello-world.sh",
]
}
connection {
user = "${var.INSTANCE_USERNAME}"
private_key = "${file("${var.PATH_TO_PRIVATE_KEY}")}"
}
}
output "ip" {
value = "${aws_instance.bootstrap.ami}"
}
output "name" {
value = "${var.image_name}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment