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" {