Terraform Cloud IaC Hardening
A Terraform configuration granted EC2FullAccess, used an admin instance profile, and had no network filtering or monitoring. I replaced it with least-privilege IAM, a scoped security group, a service-account profile, VPC Flow Logs, and CloudTrail.
Status: HARDENED · VERIFIED
TOOLS
Objective
I set out to identify security weaknesses in a Terraform configuration and apply appropriate cloud security controls, including least-privilege IAM permissions, network filtering, secure instance profiles, and monitoring.
Scenario
A Terraform configuration was used to provision AWS infrastructure, but it contained several insecure defaults. The IAM policy granted AmazonEC2FullAccess, the instance profile used an admin-level role, and there were no security groups, VPC Flow Logs, or CloudTrail configured. I wanted to harden the configuration before it was applied.
What I found
IAM policy: AmazonEC2FullAccess
Instance profile: admin_profile
Scope: All EC2 actions on all resourcesExcessive IAM permissions
The Terraform configuration attached AmazonEC2FullAccess to the EC2 instances, granting far more permissions than the workload required.
Security group: Not configured
VPC Flow Logs: Not configured
CloudTrail: Not configured
SSH access: UnrestrictedNo network filtering or monitoring
The configuration had no security group to control inbound or outbound traffic, and neither VPC Flow Logs nor CloudTrail were configured for visibility.
What I did
- Reviewed the Terraform configuration
I identified the insecure IAM policy, admin instance profile, and missing network and monitoring controls.
- Replaced the IAM policy
I changed
AmazonEC2FullAccesstoAmazonEC2ReadOnlyAccessto apply least-privilege permissions. - Added a security group
I configured inbound SSH restrictions and outbound traffic controls.
- Changed the instance profile
I replaced
admin_profilewithservice_account_profileto scope the instance identity. - Enabled monitoring
I added VPC Flow Logs and CloudTrail to the Terraform configuration.
- Applied and validated
I completed the Review, Implement, and Destroy phases of the IaC exercise.
EVIDENCE
# Terraform hardening summary
IAM policy: AmazonEC2FullAccess → AmazonEC2ReadOnlyAccess
Instance profile: admin_profile → service_account_profile
Security group: Added (SSH + outbound controls)
VPC Flow Logs: Enabled
CloudTrail: EnabledValidation
The hardened Terraform configuration was applied successfully. The infrastructure was provisioned with least-privilege IAM, a scoped security group, a service-account instance profile, and both VPC Flow Logs and CloudTrail for monitoring.
Before and after
| CONTROL | BEFORE | AFTER |
|---|---|---|
| IAM policy | AmazonEC2FullAccess | AmazonEC2ReadOnlyAccess |
| Instance profile | admin_profile | service_account_profile |
| Security group | Not configured | SSH and outbound controls |
| VPC Flow Logs | Not configured | Enabled |
| CloudTrail | Not configured | Enabled |
What I recommend
- 01Apply least-privilege IAM policies in Terraform configurations; never use
FullAccessmanaged policies for workloads. - 02Use service-account instance profiles instead of admin-level profiles.
- 03Include security groups in every Terraform deployment to control network access.
- 04Enable VPC Flow Logs and CloudTrail in every environment for visibility and incident response.
- 05Review and scan Terraform configurations for security issues before applying them, using tools like
tfsecor Terraform Sentinel policies.
“Terraform can consistently deploy both secure and insecure infrastructure, so IaC configurations must undergo security review before they are applied to cloud environments.”
SKILLS IT PROVES
- Terraform
- Infrastructure as Code Security
- AWS Cloud Security
- IAM
- Least Privilege
- VPC Security
- Security Groups
- CloudTrail
- VPC Flow Logs
- Security Hardening
- Security Monitoring
- Access Control
- DevSecOps
- Cloud Infrastructure Security