Compare commits

..

13 Commits
main ... main

Author SHA1 Message Date
Ryan Malloy 2e6eb0e2e2 add volume_size 2024-03-28 18:59:03 +00:00
Ryan Malloy 458c366bef add volume_size 2024-03-28 18:58:32 +00:00
Ryan Malloy 533b81d43a Update main.tf 2024-03-28 18:57:13 +00:00
Ryan Malloy 9eeee51b90 add instance_type 2024-03-28 18:56:38 +00:00
Ryan Malloy a71702f198 add ingress_cidr 2024-03-28 18:53:47 +00:00
Ryan Malloy 6a88ac1065 add allowed_ingress_cidr 2024-03-28 18:52:31 +00:00
Ryan Malloy be72306645 add public_cidr 2024-03-28 18:50:40 +00:00
Ryan Malloy d018e9f3e6 add vpc_cidr 2024-03-28 18:49:57 +00:00
Ryan Malloy 5f9f239a15 add vpc_cidr 2024-03-28 18:49:02 +00:00
Ryan Malloy 360bc45e11 add tls_key_algorithm 2024-03-28 18:46:27 +00:00
Ryan Malloy c5de5f6c9f generate key, use variables 2024-03-28 18:45:55 +00:00
Ryan Malloy ace065d9d2 use input variables for aws variables 2024-03-28 18:39:16 +00:00
Ryan Malloy 769ce803de add variables.tf 2024-03-28 18:38:15 +00:00
3 changed files with 181 additions and 100 deletions

27
main.tf
View File

@ -1,5 +1,7 @@
resource "aws_vpc" "sgtm_vpc" {
cidr_block = "10.123.0.0/16"
cidr_block = var.vpc_cidr
enable_dns_hostnames = true
enable_dns_support = true
@ -10,7 +12,7 @@ resource "aws_vpc" "sgtm_vpc" {
resource "aws_subnet" "sptm_public_subnet" {
vpc_id = aws_vpc.sgtm_vpc.id
cidr_block = "10.123.1.0/24"
cidr_block = var.public_cidr
map_public_ip_on_launch = true
availability_zone = "us-east-1a"
@ -55,7 +57,7 @@ resource "aws_security_group" "sgtm_sg" {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["172.59.221.135/32"]
cidr_blocks = [var.allowed_ingress_cidr]
}
egress {
@ -66,13 +68,24 @@ resource "aws_security_group" "sgtm_sg" {
}
}
resource "tls_private_key" "key" {
algorithm = var.tls_key_algorithm
}
resource "aws_key_pair" "sgtm_auth" {
key_name = "sgtmkey"
public_key = file("~/.ssh/sgtmkey.pub")
key_name = "${var.name_prefix}-key-${var.name_suffix}"
public_key = tls_private_key.key.public_key_openssh
provisioner "local-exec" {
command = <<EOF
echo "${tls_private_key.key.private_key_pem}" > key.pem
chmod 0600 key.pem
EOF
}
}
resource "aws_instance" "dev_node" {
instance_type = "t2.micro"
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]
@ -80,7 +93,7 @@ resource "aws_instance" "dev_node" {
user_data = file ("userdata.tpl")
root_block_device {
volume_size = 10
volume_size = var.volume_size
}
tags = {

View File

@ -5,8 +5,9 @@ terraform {
}
}
}
# Configure the AWS Provider
provider "aws" {
region = "us-east-1"
shared_credentials_files = ["~/.aws/credentials"]
profile = "vscode"
region = var.aws_region
access_key = var.aws_access_key
secret_key = var.aws_secret_key
}

67
variables.tf Normal file
View File

@ -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
}