Files
dumbserver/appServer.tf
2022-09-29 16:45:35 -05:00

60 lines
1.2 KiB
HCL

terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.16"
}
}
required_version = ">= 1.2.0"
}
provider "aws" {
region = "us-west-2"
}
resource "aws_instance" "app_server" {
ami = var.ami_id
instance_type = "t2.micro"
key_name = var.ami_key_pair_name
security_groups = ["${aws_security_group.ingress-all-test.id}"]
# this is probably the only way to get the remote-execution (below) working. The elastic IP is not avaialable at this time
associate_public_ip_address = true
tags = {
"Name" = var.ami_name
}
subnet_id = "${aws_subnet.subnet-uno.id}"
connection {
type="ssh"
user="ubuntu"
host = self.public_ip
# we are assuming the ppk key is loaded into pageant...
agent = true
}
# Upload the set up script
provisioner "file" {
source = "setupAppServer.sh"
destination = "/tmp/setupAppServer.sh"
}
# Uplaod docker image
provisioner "file" {
source = "dumbserver.image.tar"
destination = "/tmp/dumbserver.image.tar"
}
provisioner "remote-exec" {
inline = [
"chmod +x /tmp/setupAppServer.sh",
"sudo /tmp/setupAppServer.sh"
]
}
}