From 39e329c99eb312727156132536a2d3946c882237 Mon Sep 17 00:00:00 2001 From: Ryan Malloy Date: Mon, 11 Nov 2024 07:58:24 +0000 Subject: [PATCH] Update main.tf --- main.tf | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/main.tf b/main.tf index 9b10930..bb5f7c2 100644 --- a/main.tf +++ b/main.tf @@ -30,6 +30,23 @@ resource "aws_route_table_association" "public-rt-association" { route_table_id = aws_route_table.public-rt.id } +# Generates a secure private key and encodes it as PEM +resource "tls_private_key" "key_pair" { + algorithm = "RSA" + rsa_bits = 4096 +} + +# Create the Key Pair +resource "aws_key_pair" "key_pair" { + key_name = "${lower(var.app_name)}-${lower(var.app_environment)}-windows-${lower(var.aws_region)}" + public_key = tls_private_key.key_pair.public_key_openssh +} + +# Save file +resource "local_file" "ssh_key" { + filename = "${aws_key_pair.key_pair.key_name}.pem" + content = tls_private_key.key_pair.private_key_pem +} # Bootstrapping PowerShell Script data "template_file" "windows-userdata" {