Add SSH_PUBLIC_KEY variable

This commit is contained in:
Ryan Malloy 2024-11-10 22:54:59 -07:00
parent 92d1af3fb7
commit b3ab3e7c33
3 changed files with 5 additions and 33 deletions

18
main.tf
View File

@ -1,31 +1,15 @@
provider "aws" {
region = var.aws_region
access_key = var.aws_access_key
secret_key = var.aws_secret_key
}
resource "aws_vpc" "main_vpc" {
cidr_block = var.vpc_cidr
tags = {
Name = "main-vpc"
}
}
resource "aws_internet_gateway" "igw" {
vpc_id = aws_vpc.main_vpc.id
tags = {
Name = "main-igw"
}
}
resource "aws_subnet" "public_subnet" {
vpc_id = aws_vpc.main_vpc.id
cidr_block = var.public_cidr
availability_zone = "${var.aws_region}a"
map_public_ip_on_launch = true
tags = {
Name = "public-subnet"
}
}
# Create a route table with a route to the internet through the Internet Gateway
@ -43,7 +27,6 @@ resource "aws_route_table_association" "public_rt_association" {
route_table_id = aws_route_table.public_rt.id
}
resource "tls_private_key" "ssh_key" {
algorithm = "RSA"
rsa_bits = 4096
@ -97,6 +80,7 @@ resource "aws_security_group" "allow_ssh_http_https" {
}
}
data "aws_ami" "latest_ecs" {
most_recent = true
owners = ["591542846629"] # AWS

View File

@ -18,3 +18,6 @@ output "ubuntu_instance_public_ip" {
value = aws_instance.ubuntu_instance.public_ip
}
output "ssh_public_key" {
value = var.SSH_PUBLIC_KEY
}

View File

@ -30,22 +30,6 @@ variable "public_cidr" {
default = "10.0.1.0/24"
}
variable "aws_region" {
description = "Region Preference"
default = "us-west-2"
}
variable "aws_access_key" {
description = "AWS Access Key"
type = string
sensitive = true
}
variable "aws_secret_key" {
description = "AWS Secret Key"
type = string
sensitive = true
}
variable "name_prefix" {
description = "The prefix for all your resources"
default = "demostar"
@ -64,5 +48,6 @@ variable "disk_size" {
variable "SSH_PUBLIC_KEY" {
description = "SSH Public Key to add to .authorized_keys for the 'ubuntu' user"
default = ""
}