This document summarizes the new features added to the AWS EC2 module for enhanced Session Manager support and automatic key pair creation.
- New IAM policy with enhanced Session Manager permissions
- Support for
ssmmessagesAPI calls required for Session Manager functionality - S3 encryption configuration access for session logs
enable_session_manager_permissions(bool, default: true) - Adds enhanced Session Manager permissions
{
"Effect": "Allow",
"Action": [
"ssmmessages:CreateControlChannel",
"ssmmessages:CreateDataChannel",
"ssmmessages:OpenControlChannel",
"ssmmessages:OpenDataChannel"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"s3:GetEncryptionConfiguration"
],
"Resource": "*"
}- Automatic key pair generation using Terraform TLS provider
- Option to use existing public key material
- Secure storage of private keys in SSM Parameter Store
- Support for both generated and user-provided public keys
create_key_pair(bool, default: false) - Create a new key pairkey_pair_name(string, default: "${instance_name}-key") - Name for the key pairpublic_key(string, default: null) - Use existing public key materialsave_private_key(bool, default: true) - Store private key in SSM Parameter Store
key_pair_created- Whether a key pair was createdkey_pair_name- Name of the key pair usedkey_pair_id- ID of the created key pairkey_pair_arn- ARN of the created key pairkey_pair_fingerprint- Fingerprint of the key pairprivate_key_ssm_parameter- SSM parameter path for private keyprivate_key_pem- Private key in PEM format (sensitive)public_key_openssh- Public key in OpenSSH format
- Bash script for Linux/Mac users (
scripts/download-private-key.sh) - PowerShell script for Windows users (
scripts/download-private-key.ps1) - Automatic permission setting (chmod 600 equivalent)
- Error handling and user guidance
- Download private keys from SSM Parameter Store
- Set proper file permissions
- Provide usage instructions for SSH/RDP
- Input validation and error handling
inputs = {
instance_name = "my-instance"
# Enhanced Session Manager permissions (enabled by default)
enable_session_manager_permissions = true
# Other configuration...
}inputs = {
instance_name = "windows-server-01"
operating_system = "windows"
# Auto-generate key pair for Windows password retrieval
create_key_pair = true
key_pair_name = "windows-server-01-key"
save_private_key = true
# Other configuration...
}# Get the SSM parameter path from Terraform output
terraform output private_key_ssm_parameter
# Download using the provided script
./scripts/download-private-key.sh "/ec2/keypair/windows-server-01-key/private_key"
# For Windows password retrieval
aws ec2 get-password-data --instance-id i-1234567890abcdef0 --priv-launch-key windows-server-01-key.pemAll changes are backward compatible:
- Existing deployments continue to work without modification
- New features are opt-in with sensible defaults
- No breaking changes to existing variables or outputs
main.tf- Added Session Manager policy and key pair creation logicvariables.tf- Added new variables for Session Manager and key pair featuresoutputs.tf- Added new outputs for key pair information
scripts/download-private-key.sh- Bash script for private key downloadscripts/download-private-key.ps1- PowerShell script for private key downloadKEY_PAIR_USAGE.md- Comprehensive guide for key pair functionalityFEATURE_UPDATES.md- This summary document
- Secure Key Storage: Private keys stored as SecureString in SSM Parameter Store
- Proper Permissions: Scripts automatically set restrictive file permissions
- Access Control: IAM permissions follow least-privilege principle
- Encryption: Support for encrypted session manager logs
- Manual key pair creation required
- No built-in Session Manager enhanced permissions
- Windows instances needed manual password retrieval setup
- Private key management left to users
- Automated key pair generation and management
- Enhanced Session Manager permissions included by default
- Seamless Windows password retrieval workflow
- Secure private key storage and retrieval system
This update significantly improves the user experience for both Linux SSH access and Windows RDP access scenarios.