Compare commits
13 Commits
Author | SHA1 | Date |
---|---|---|
Ryan Malloy | 2e6eb0e2e2 | |
Ryan Malloy | 458c366bef | |
Ryan Malloy | 533b81d43a | |
Ryan Malloy | 9eeee51b90 | |
Ryan Malloy | a71702f198 | |
Ryan Malloy | 6a88ac1065 | |
Ryan Malloy | be72306645 | |
Ryan Malloy | d018e9f3e6 | |
Ryan Malloy | 5f9f239a15 | |
Ryan Malloy | 360bc45e11 | |
Ryan Malloy | c5de5f6c9f | |
Ryan Malloy | ace065d9d2 | |
Ryan Malloy | 769ce803de |
191
main.tf
191
main.tf
|
@ -1,90 +1,103 @@
|
||||||
resource "aws_vpc" "sgtm_vpc" {
|
|
||||||
cidr_block = "10.123.0.0/16"
|
|
||||||
enable_dns_hostnames = true
|
resource "aws_vpc" "sgtm_vpc" {
|
||||||
enable_dns_support = true
|
cidr_block = var.vpc_cidr
|
||||||
|
enable_dns_hostnames = true
|
||||||
tags = {
|
enable_dns_support = true
|
||||||
name = "dev"
|
|
||||||
}
|
tags = {
|
||||||
}
|
name = "dev"
|
||||||
|
}
|
||||||
resource "aws_subnet" "sptm_public_subnet" {
|
}
|
||||||
vpc_id = aws_vpc.sgtm_vpc.id
|
|
||||||
cidr_block = "10.123.1.0/24"
|
resource "aws_subnet" "sptm_public_subnet" {
|
||||||
map_public_ip_on_launch = true
|
vpc_id = aws_vpc.sgtm_vpc.id
|
||||||
availability_zone = "us-east-1a"
|
cidr_block = var.public_cidr
|
||||||
|
map_public_ip_on_launch = true
|
||||||
tags = {
|
availability_zone = "us-east-1a"
|
||||||
name = "dev-public"
|
|
||||||
}
|
tags = {
|
||||||
}
|
name = "dev-public"
|
||||||
|
}
|
||||||
resource "aws_internet_gateway" "sgtm_internet_gateway" {
|
}
|
||||||
vpc_id = aws_vpc.sgtm_vpc.id
|
|
||||||
|
resource "aws_internet_gateway" "sgtm_internet_gateway" {
|
||||||
tags = {
|
vpc_id = aws_vpc.sgtm_vpc.id
|
||||||
name = "dev-igw"
|
|
||||||
}
|
tags = {
|
||||||
}
|
name = "dev-igw"
|
||||||
|
}
|
||||||
resource "aws_route_table" "sgtm_public_rt" {
|
}
|
||||||
vpc_id = aws_vpc.sgtm_vpc.id
|
|
||||||
|
resource "aws_route_table" "sgtm_public_rt" {
|
||||||
tags = {
|
vpc_id = aws_vpc.sgtm_vpc.id
|
||||||
name = "dev_public_rt"
|
|
||||||
}
|
tags = {
|
||||||
}
|
name = "dev_public_rt"
|
||||||
|
}
|
||||||
resource "aws_route" "default_route" {
|
}
|
||||||
route_table_id = aws_route_table.sgtm_public_rt.id
|
|
||||||
destination_cidr_block = "0.0.0.0/0"
|
resource "aws_route" "default_route" {
|
||||||
gateway_id = aws_internet_gateway.sgtm_internet_gateway.id
|
route_table_id = aws_route_table.sgtm_public_rt.id
|
||||||
}
|
destination_cidr_block = "0.0.0.0/0"
|
||||||
|
gateway_id = aws_internet_gateway.sgtm_internet_gateway.id
|
||||||
resource "aws_route_table_association" "sgtm_public_assoc" {
|
}
|
||||||
subnet_id = aws_subnet.sptm_public_subnet.id
|
|
||||||
route_table_id = aws_route_table.sgtm_public_rt.id
|
resource "aws_route_table_association" "sgtm_public_assoc" {
|
||||||
}
|
subnet_id = aws_subnet.sptm_public_subnet.id
|
||||||
|
route_table_id = aws_route_table.sgtm_public_rt.id
|
||||||
resource "aws_security_group" "sgtm_sg" {
|
}
|
||||||
name = "dev-sg"
|
|
||||||
description = "dev security group"
|
resource "aws_security_group" "sgtm_sg" {
|
||||||
vpc_id = aws_vpc.sgtm_vpc.id
|
name = "dev-sg"
|
||||||
|
description = "dev security group"
|
||||||
ingress {
|
vpc_id = aws_vpc.sgtm_vpc.id
|
||||||
from_port = 0
|
|
||||||
to_port = 0
|
ingress {
|
||||||
protocol = "-1"
|
from_port = 0
|
||||||
cidr_blocks = ["172.59.221.135/32"]
|
to_port = 0
|
||||||
}
|
protocol = "-1"
|
||||||
|
cidr_blocks = [var.allowed_ingress_cidr]
|
||||||
egress {
|
}
|
||||||
from_port = 0
|
|
||||||
to_port = 0
|
egress {
|
||||||
protocol = "-1"
|
from_port = 0
|
||||||
cidr_blocks = ["0.0.0.0/0"]
|
to_port = 0
|
||||||
}
|
protocol = "-1"
|
||||||
}
|
cidr_blocks = ["0.0.0.0/0"]
|
||||||
|
}
|
||||||
resource "aws_key_pair" "sgtm_auth" {
|
}
|
||||||
key_name = "sgtmkey"
|
|
||||||
public_key = file("~/.ssh/sgtmkey.pub")
|
resource "tls_private_key" "key" {
|
||||||
}
|
algorithm = var.tls_key_algorithm
|
||||||
|
}
|
||||||
resource "aws_instance" "dev_node" {
|
|
||||||
instance_type = "t2.micro"
|
resource "aws_key_pair" "sgtm_auth" {
|
||||||
ami = data.aws_ami.server_ami.id
|
key_name = "${var.name_prefix}-key-${var.name_suffix}"
|
||||||
key_name = aws_key_pair.sgtm_auth.id
|
public_key = tls_private_key.key.public_key_openssh
|
||||||
vpc_security_group_ids = [aws_security_group.sgtm_sg.id]
|
|
||||||
subnet_id = aws_subnet.sptm_public_subnet.id
|
provisioner "local-exec" {
|
||||||
user_data = file ("userdata.tpl")
|
command = <<EOF
|
||||||
|
echo "${tls_private_key.key.private_key_pem}" > key.pem
|
||||||
root_block_device {
|
chmod 0600 key.pem
|
||||||
volume_size = 10
|
EOF
|
||||||
}
|
}
|
||||||
|
}
|
||||||
tags = {
|
|
||||||
name = "dev-node"
|
resource "aws_instance" "dev_node" {
|
||||||
}
|
instance_type = var.instance_type
|
||||||
|
ami = data.aws_ami.server_ami.id
|
||||||
|
key_name = aws_key_pair.sgtm_auth.id
|
||||||
|
vpc_security_group_ids = [aws_security_group.sgtm_sg.id]
|
||||||
|
subnet_id = aws_subnet.sptm_public_subnet.id
|
||||||
|
user_data = file ("userdata.tpl")
|
||||||
|
|
||||||
|
root_block_device {
|
||||||
|
volume_size = var.volume_size
|
||||||
|
}
|
||||||
|
|
||||||
|
tags = {
|
||||||
|
name = "dev-node"
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
23
providers.tf
23
providers.tf
|
@ -1,12 +1,13 @@
|
||||||
terraform {
|
terraform {
|
||||||
required_providers {
|
required_providers {
|
||||||
aws = {
|
aws = {
|
||||||
source = "hashicorp/aws"
|
source = "hashicorp/aws"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
provider "aws" {
|
# Configure the AWS Provider
|
||||||
region = "us-east-1"
|
provider "aws" {
|
||||||
shared_credentials_files = ["~/.aws/credentials"]
|
region = var.aws_region
|
||||||
profile = "vscode"
|
access_key = var.aws_access_key
|
||||||
|
secret_key = var.aws_secret_key
|
||||||
}
|
}
|
|
@ -0,0 +1,67 @@
|
||||||
|
# AWS variables
|
||||||
|
variable "aws_region" {
|
||||||
|
default = "us-east-2"
|
||||||
|
description = "The AWS Region"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "name_prefix" {
|
||||||
|
description = "The prefix for all your resources"
|
||||||
|
default = "testing"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "name_suffix" {
|
||||||
|
description = "The suffix for all your resources"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "aws_access_key" {
|
||||||
|
description = "AWS Access Key"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "aws_secret_key" {
|
||||||
|
description = "AWS Secret Key"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
variable "tls_key_algorithm" {
|
||||||
|
default = "RSA"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
variable "vpc_cidr" {
|
||||||
|
description = "VPC CIDR"
|
||||||
|
default = "10.123.0.0/16"
|
||||||
|
}
|
||||||
|
variable "public_cidr" {
|
||||||
|
description = "Public CIDR"
|
||||||
|
default = "10.123.1.0/24"
|
||||||
|
}
|
||||||
|
variable "ingress_cidr" {
|
||||||
|
description = "CIDR that is allowed ingress access"
|
||||||
|
default = "172.59.221.135/32"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "instance_type" {
|
||||||
|
description = "Instance Type"
|
||||||
|
default = "t2.micro"
|
||||||
|
validation {
|
||||||
|
condition = (
|
||||||
|
var.instance_type == "t2.micro" ||
|
||||||
|
var.instance_type == "t3.medium" ||
|
||||||
|
var.instance_type == "m5.large" ||
|
||||||
|
var.instance_type == "c5.large" ||
|
||||||
|
var.instance_type == "c5a.large" ||
|
||||||
|
var.instance_type == "m5.2xlarge" ||
|
||||||
|
var.instance_type == "c5.2xlarge" ||
|
||||||
|
var.instance_type == "m5.4xlarge" ||
|
||||||
|
var.instance_type == "c5.4xlarge"
|
||||||
|
)
|
||||||
|
error_message = "Instance_type must be set to a valid vm instance type."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "volume_size" {
|
||||||
|
description = "Instance volume size in Gigabytes"
|
||||||
|
default = 10
|
||||||
|
type = number
|
||||||
|
}
|
Loading…
Reference in New Issue