TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/mcamacho97/terraform-mean-stack-aws/llms.txt
Use this file to discover all available pages before exploring further.
keypair module removes the manual step of generating an SSH key pair before running terraform apply. On the first apply, Terraform uses the hashicorp/tls provider to generate a 4096-bit RSA key entirely in memory, writes the private key to ${path.root}/keys/<project_name>.pem with restrictive 0400 permissions, and uploads the corresponding public key to AWS as a named Key Pair. The resulting key pair name is passed to all three EC2 instances so they are immediately accessible over SSH without any out-of-band setup.
How It Works
The module uses three resources in sequence:| Resource | Provider | Description |
|---|---|---|
tls_private_key.this | hashicorp/tls | Generates a 4096-bit RSA key in memory during the plan/apply phase |
local_file.private_key | hashicorp/local | Writes the private key PEM to keys/<project_name>.pem with 0400 file permissions |
aws_key_pair.this | hashicorp/aws | Uploads the public key in OpenSSH format to AWS, creating a Key Pair named <project_name>-key |
Key File Location
The private key is written to${path.root}/keys/<project_name>.pem relative to the Terraform root module directory. For example, with project_name = "terraform-mean" the file is saved at:
keys/ directory is gitignored to prevent accidental key exposure in version control.
Input Variables
Used to name the AWS Key Pair (
<project_name>-key) and the local private key file (keys/<project_name>.pem).Outputs
The name of the AWS Key Pair (e.g.
terraform-mean-key). Referenced by all three ec2-instance module calls via the key_name variable.The local filesystem path to the generated
.pem file (e.g. ./keys/terraform-mean.pem). Use this path with ssh -i to connect to public instances.Module Call
Using the Key
Afterterraform apply completes, retrieve the key path and SSH into a Node.js instance:
SSH access to instances requires that your IP is included in
var.allowed_ssh_ip (set in the security module). The MongoDB instance has no public IP and cannot be reached directly over SSH — use AWS SSM Session Manager instead.