65 lines
1.4 KiB
HCL
65 lines
1.4 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 = "../docker/dumbserver.image.tar"
|
|
destination = "/tmp/dumbserver.image.tar"
|
|
}
|
|
|
|
# Upload example data file
|
|
provisioner "file" {
|
|
source = "../app/dataDir/data"
|
|
destination = "/tmp/data"
|
|
}
|
|
|
|
provisioner "remote-exec" {
|
|
inline = [
|
|
"chmod +x /tmp/setupAppServer.sh",
|
|
"sudo /tmp/setupAppServer.sh"
|
|
]
|
|
}
|
|
|
|
}
|