Troubleshooting¶
This document provides solutions to common issues with the Terraformer module.
Deployment Issues¶
Error: environment validation failed¶
Problem:
Error: Invalid value for variable
│
│ on variables.tf line 13:
│ 13: variable "environment" {
│
│ environment must contain only lowercase letters, numbers, and underscores (no hyphens)
Solution:
The environment variable has strict validation. Ensure it contains only lowercase letters, numbers, and underscores:
# ❌ Invalid
environment = "production-us" # Contains hyphen
environment = "Production" # Contains uppercase
# ✅ Valid
environment = "production"
environment = "prod_us"
environment = "dev2"
Error: No default value for environment¶
Problem:
Solution:
This is intentional to prevent deployment mistakes. You must explicitly set the environment:
Error: Circular dependency with CloudWatch log group¶
Problem:
Solution:
This was fixed in version 2.0+. The log group now uses a static name /aws/ec2/terraformer instead of including the instance ID.
Upgrade to the latest version:
module "terraformer" {
source = "registry.infrahouse.com/infrahouse/terraformer/aws"
version = "~> 2.0" # Use latest
# ...
}
SNS Notification Issues¶
Not receiving alarm notifications¶
Problem:
CloudWatch alarms are triggering but you're not receiving email notifications.
Solutions:
- Confirm SNS subscription:
After deployment, AWS SNS sends a confirmation email to each address in alarm_emails. You must click the confirmation link in each email to activate notifications.
Check subscription status:
# Get SNS topic ARN
INSTANCE_ID=$(terraform output -raw instance_id)
TOPIC_ARN=$(aws sns list-topics --query "Topics[?contains(TopicArn, 'terraformer-alarms-${INSTANCE_ID}')].TopicArn" --output text)
# List subscriptions and their status
aws sns list-subscriptions-by-topic --topic-arn "$TOPIC_ARN"
Look for SubscriptionArn. If it shows PendingConfirmation, the email was not confirmed.
- Resend confirmation email:
If you missed or deleted the confirmation email:
# Delete the pending subscription
aws sns unsubscribe --subscription-arn <pending-subscription-arn>
# Re-run Terraform to recreate the subscription
terraform apply -target=module.terraformer.aws_sns_topic_subscription.alarm_email
Check your spam/junk folder for emails from AWS Notifications <no-reply@sns.amazonaws.com>.
- Verify email address is correct:
Check your Terraform configuration:
Confirmation email not received¶
Problem:
You added an email to alarm_emails but never received the confirmation email.
Solutions:
-
Check spam/junk folder — AWS SNS emails often get filtered
-
Verify email domain accepts AWS emails:
- Some corporate email filters block automated emails
-
Contact your email admin to whitelist
no-reply@sns.amazonaws.com -
Check SNS delivery logs:
-
Try alternative endpoint:
If email continues to fail, consider using an SMS or HTTPS endpoint instead.
Multiple email addresses not all receiving notifications¶
Problem:
You specified multiple emails in alarm_emails but only some receive notifications.
Solution:
Each email address requires individual confirmation. Check status of all subscriptions:
aws sns list-subscriptions-by-topic --topic-arn "$TOPIC_ARN" \
| jq -r '.Subscriptions[] | "\(.Endpoint): \(.SubscriptionArn)"'
Any showing PendingConfirmation need to be confirmed by clicking the link in the email sent to that address.
SSH Access Issues¶
Cannot connect via SSH¶
Problem:
$ ssh ubuntu@terraformer.example.com
ssh: connect to host terraformer.example.com port 22: Connection timed out
Solutions:
- Check instance is in private subnet:
If it returns an IP, the instance has public access (not recommended). If null, it's correctly in a private subnet.
- Connect via bastion/VPN:
The terraformer is intentionally not publicly accessible. Connect through: - Bastion host in public subnet - VPN connection to VPC - AWS Systems Manager Session Manager
- Check security group:
Verify SSH (port 22) allows your source IP or VPC CIDR.
SSH key permission denied¶
Problem:
$ ssh -i ~/.ssh/terraformer.pem ubuntu@terraformer.example.com
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for '/home/user/.ssh/terraformer.pem' are too open.
Solution:
Wrong SSH key¶
Problem:
$ ssh -i ~/.ssh/my-key.pem ubuntu@terraformer.example.com
ubuntu@terraformer.example.com: Permission denied (publickey).
Solution:
-
If using auto-generated key:
-
If using custom key:
Verify ssh_key_name in your configuration matches the key you're using:
IAM and Permissions Issues¶
Error: User is not authorized to perform logs:CreateLogStream¶
Problem:
An error occurred (AccessDeniedException) when calling the CreateLogStream operation:
User: arn:aws:sts::123456789012:assumed-role/terraformer-XXXX/i-xxxxxxxxx is not authorized
to perform: logs:CreateLogStream on resource: arn:aws:logs:us-west-2:123456789012:log-group:/aws/ec2/terraformer
Solution:
This indicates the instance IAM role lacks CloudWatch Logs permissions. This should be automatically granted by the module.
Check if you're using an old version:
Upgrade to version 2.0+ which includes CloudWatch permissions:
module "terraformer" {
source = "registry.infrahouse.com/infrahouse/terraformer/aws"
version = "~> 2.0"
# ...
}
terraform init -upgrade
terraform apply
Cannot assume role in target account¶
Problem:
$ aws sts assume-role --role-arn arn:aws:iam::TARGET-ACCOUNT:role/admin
An error occurred (AccessDenied) when calling the AssumeRole operation:
User: arn:aws:sts::SOURCE-ACCOUNT:assumed-role/terraformer-XXXX/i-xxxxxxxxx is not authorized
to perform: sts:AssumeRole on resource: arn:aws:iam::TARGET-ACCOUNT:role/admin
Solutions:
- Check trust relationship in target account:
The target role must trust the terraformer instance role:
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::SOURCE-ACCOUNT:role/terraformer-XXXXXXXXXXXX"
},
"Action": "sts:AssumeRole"
}]
}
-
Get the correct role ARN:
-
Verify source account has AssumeRole permission:
The terraformer role should have this by default, but verify:
aws iam get-role-policy \
--role-name $(terraform output -raw instance_role_name) \
--policy-name terraformer-policy
Auto-Recovery Issues¶
Instance not recovering from failures¶
Problem:
Instance experienced a failure but didn't auto-recover.
Solutions:
-
Check alarm state:
-
Check alarm history:
-
Verify alarm actions are enabled:
If false, enable:
Alarm exists but instance didn't reboot¶
Problem:
Instance status check failed but alarm didn't trigger reboot.
Solution:
The alarm requires 3 consecutive failures (3 minutes). Check if the failure was transient:
# Check instance status check history
aws ec2 describe-instance-status \
--instance-ids $(terraform output -raw instance_id) \
--include-all-instances
If you need more aggressive recovery, create a custom alarm with lower evaluation periods (not recommended for production).
CloudWatch Issues¶
Logs not appearing in CloudWatch¶
Problem:
Terraformer instance is running but logs aren't appearing in CloudWatch Logs.
Solutions:
-
Check CloudWatch agent status:
-
Verify agent configuration:
-
Check Puppet facts:
Should return /aws/ec2/terraformer and terraformer respectively.
- Restart agent:
Cannot publish metrics¶
Problem:
$ aws cloudwatch put-metric-data --namespace "terraformer" --metric-name "Test" --value 1
An error occurred (AccessDenied) when calling the PutMetricData operation
Solution:
Verify IAM permissions restrict to correct namespace:
# This should work
aws cloudwatch put-metric-data \
--namespace "terraformer" \
--metric-name "TestMetric" \
--value 1
# This should fail (different namespace)
aws cloudwatch put-metric-data \
--namespace "other-namespace" \
--metric-name "TestMetric" \
--value 1
If both fail, check IAM role policy includes CloudWatch PutMetricData permission.
Puppet Issues¶
Puppet run failures¶
Problem:
Instance launches but Puppet fails to configure it properly.
Solutions:
-
Check Puppet logs:
-
Verify Puppet facts:
-
Check marker file:
-
Manually run Puppet:
DNS Issues¶
DNS record not resolving¶
Problem:
$ nslookup terraformer.example.com
Server: 8.8.8.8
Address: 8.8.8.8#53
** server can't find terraformer.example.com: NXDOMAIN
Solutions:
-
Verify Route53 record exists:
-
Check DNS name configuration:
-
Verify zone_id is correct:
State File Issues¶
State lock errors¶
Problem:
Solution:
If working from terraformer instance and encountering locks:
# View DynamoDB lock table
aws dynamodb scan --table-name terraform-locks
# Force unlock (use with caution)
terraform force-unlock <LOCK_ID>
Getting Help¶
If you encounter issues not covered here:
-
Check module version:
-
Enable debug logging:
-
Review CloudWatch Logs:
-
Open an issue:
github.com/infrahouse/terraform-aws-terraformer/issues
Include: - Terraform version - Module version - Error messages - Relevant Terraform state output - CloudWatch logs (redacted)