mirror of
https://github.com/farcasclaudiu/terraform-course.git
synced 2026-06-22 05:01:55 +03:00
30 lines
749 B
Terraform
30 lines
749 B
Terraform
resource "aws_key_pair" "mykey" {
|
|
key_name = "mykey"
|
|
public_key = file(var.PATH_TO_PUBLIC_KEY)
|
|
}
|
|
|
|
resource "aws_instance" "example" {
|
|
ami = var.AMIS[var.AWS_REGION]
|
|
instance_type = "t2.micro"
|
|
key_name = aws_key_pair.mykey.key_name
|
|
|
|
provisioner "file" {
|
|
source = "script.sh"
|
|
destination = "/tmp/script.sh"
|
|
}
|
|
provisioner "remote-exec" {
|
|
inline = [
|
|
"chmod +x /tmp/script.sh",
|
|
"sudo sed -i -e 's/\r$//' /tmp/script.sh", # Remove the spurious CR characters.
|
|
"sudo /tmp/script.sh",
|
|
]
|
|
}
|
|
connection {
|
|
host = coalesce(self.public_ip, self.private_ip)
|
|
type = "ssh"
|
|
user = var.INSTANCE_USERNAME
|
|
private_key = file(var.PATH_TO_PRIVATE_KEY)
|
|
}
|
|
}
|
|
|