cleanup directory strucutre and fine tune

This commit is contained in:
Joe Tretter
2022-09-30 10:55:07 -05:00
parent dae7fbc9e7
commit 9b25fa2eda
19 changed files with 69 additions and 27 deletions

22
terraform/.terraform.lock.hcl generated Normal file
View File

@@ -0,0 +1,22 @@
# This file is maintained automatically by "terraform init".
# Manual edits may be lost in future updates.
provider "registry.terraform.io/hashicorp/aws" {
version = "4.32.0"
constraints = "~> 4.16"
hashes = [
"h1:CmNkbcfctajxal8fnFFWLSC5dDvQwSJrw7HiwpTdyUc=",
"zh:062c30cd8bcf29f8ee34c2b2509e4e8695c2bcac8b7a8145e1c72e83d4e68b13",
"zh:1503fabaace96a7eea4d73ced36a02a75ec587760850e58162e7eff419dcbb31",
"zh:39a1fa36f8cb999f048bf0000d9dab40b8b0c77df35584fb08aa8bd6c5052dee",
"zh:471a755d43b51cd7be3e386cebc151ad8d548c5dea798343620476887e721882",
"zh:61ed56fab811e62b8286e606d003f7eeb7e940ef99bb49c1d283d91c0b748cc7",
"zh:80607dfe5f7770d136d5c451308b9861084ffad08139de8014e48672ec43ea3f",
"zh:863bf0a6576f7a969a89631525250d947fbb207d3d13e7ca4f74d86bd97cdda3",
"zh:9a8f2e77e4f99dbb618eb8ad17218a4698833754b50d46da5727323a2050a400",
"zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425",
"zh:9b74ff6e638c2a470b3599d57c2081e0095976da0a54b6590884d571f930b53b",
"zh:da4fc553d50ae833d860ec95120e271c29b4cb636917ab5991327362b7486bb7",
"zh:f4b86e7df4e846a38774e8e648b41c5ebaddcefa913cfa1864568086b7735575",
]
}

64
terraform/appServer.tf Normal file
View File

@@ -0,0 +1,64 @@
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"
]
}
}

3
terraform/gateways.tf Normal file
View File

@@ -0,0 +1,3 @@
resource "aws_internet_gateway" "test-env-gw" {
vpc_id = "${aws_vpc.test-env.id}"
}

10
terraform/network.tf Normal file
View File

@@ -0,0 +1,10 @@
resource "aws_vpc" "test-env" {
cidr_block = "10.0.0.0/16"
enable_dns_hostnames = true
enable_dns_support = true
}
resource "aws_eip" "ip-test-env" {
instance = "${aws_instance.app_server.id}"
vpc = true
}

9
terraform/outputs.tf Normal file
View File

@@ -0,0 +1,9 @@
output "instance_public_ip" {
description = "Public IP address of the EC2 instance"
value = aws_instance.app_server.public_ip
}
output "elastic_ip" {
description = "ELASTIC IP"
value = aws_eip.ip-test-env.public_ip
}

27
terraform/security.tf Normal file
View File

@@ -0,0 +1,27 @@
resource "aws_security_group" "ingress-all-test" {
name = "allow-all-sg"
vpc_id = "${aws_vpc.test-env.id}"
ingress {
cidr_blocks = [
"0.0.0.0/0"
]
from_port = 22
to_port = 22
protocol = "tcp"
}
ingress {
cidr_blocks = [
"0.0.0.0/0"
]
from_port = 1280
to_port = 1280
protocol = "tcp"
}
// Terraform removes the default rule
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}

View File

@@ -0,0 +1,25 @@
#!/bin/bash
export DEBIAN_FRONTEND=noninteractive
apt -y update
apt -y upgrade
apt -y update
apt -y install podman
podman image load -i /tmp/dumbserver.image.tar
# create the directory for the data file and, if not existing (which is the default) copy the example file
mkdir -p /var/local/dumbserver
if [ ! -f /var/local/dumbserver/data ]; then
cp /tmp/data /var/local/dumbserver/
fi
podman run --name dumbserver -d -p 1280:1280 -v /var/local/dumbserver:/nodejsapp/dataDir dumbserver
# make sure it comes up after reboot...
podman generate systemd --new --name dumbserver > /etc/systemd/system/dumbserver-podman.service
systemctl daemon-reload
systemctl enable dumbserver-podman.service
# finally, all is set up and after all the updates we want to reboot into the new kernel version
shutdown -r 1

17
terraform/subnets.tf Normal file
View File

@@ -0,0 +1,17 @@
resource "aws_subnet" "subnet-uno" {
cidr_block = "${cidrsubnet(aws_vpc.test-env.cidr_block, 3, 1)}"
vpc_id = "${aws_vpc.test-env.id}"
availability_zone = "us-west-2a"
}
resource "aws_route_table" "route-table-test-env" {
vpc_id = "${aws_vpc.test-env.id}"
route {
cidr_block = "0.0.0.0/0"
gateway_id = "${aws_internet_gateway.test-env-gw.id}"
}
}
resource "aws_route_table_association" "subnet-association" {
subnet_id = "${aws_subnet.subnet-uno.id}"
route_table_id = "${aws_route_table.route-table-test-env.id}"
}

13
terraform/variables.tf Normal file
View File

@@ -0,0 +1,13 @@
variable "ami_id" {
type = string
default = "ami-017fecd1353bcc96e"
}
variable "ami_key_pair_name" {
type=string
default = "teraformtest1"
}
variable "ami_name" {
type = string
default = "dumbApplicationServer"
}