AWS with Terraform (Day 16)
Advanced AWS IAM User Management with Terraform (CSV-Driven, MFA Enabled, Policies Added)
Today I pushed my IAM automation project further by turning a basic CSV-driven setup into a production-ready IAM onboarding system powered entirely by Terraform.
This wasn’t just about creating IAM users — the goal was to build a repeatable, scalable, secure identity-management workflow that any DevOps team can adopt.
What I Built Today
A complete IAM onboarding automation pipeline, including:
Bulk IAM user creation from CSV
-
Extended CSV now includes:
first_name,last_name,email,phone,employe_id,department,job_title,location -
Terraform loads the CSV with
csvdecode() -
Creates a typed list/map for dynamic iteration
Automated username generation
-
Normalized, lowercase usernames
-
Combines first name + last name + emp_id
-
Ensures uniqueness & traceability
Console access + MFA-first login
-
Users get a login profile
-
password_reset_required = true -
Enforced MFA via IAM policies + dynamic group assignment
-
Strong security baseline for all new accounts
IAM Groups + Dynamic Membership
Automatically assigns users to groups based on CSV fields:
-
Engineering, HR, Education, Management, etc.
-
Filters built using
for,for_each, conditional expressions -
Uses
can()to safely evaluate optional CSV keys
IAM Policies Attached
I added:
-
Least-privilege policies
-
MFA enforcement policy
-
Department-specific permissions
-
Custom JSON policies for restricted & privileged roles
Everything is driven by Terraform for reproducibility.
S3 Backend for Team Usage
-
Remote state stored in an encrypted S3 bucket
-
DynamoDB table for state locking
-
Safe for collaboration & CI/CD pipelines
Why This Matters
Traditional IAM user creation is:
❌ Manual
❌ Error-prone
❌ Inconsistent
❌ Hard to audit
My Day-16 setup fixes all of that.
Now IAM onboarding is:
✅ Automated
✅ Consistent
✅ Secure
✅ Version-controlled
✅ Auditable
✅ Scalable
A single CSV commit becomes the source of truth for onboarding/offboarding.
Key Terraform Concepts I Used
-
csvdecode()for structured data -
for_eachloops for IAM users -
Dynamic group membership with list comprehensions
-
Conditional logic with
can() -
Sensitive variables & MFA enforcement
-
Reusable locals for usernames, tags, and department mapping
-
S3 backend + DynamoDB locking
Great real-world Terraform practice.
What’s Next
For Day 17, I plan to:
-
Turn this into a reusable Terraform module
-
Push passwords into AWS Secrets Manager
-
Add Slack/Email notifications for new user onboarding
-
Build a CI workflow for automated validation of CSV changes
Day 16 Summary
IAM user management is more than creating users — it's building a secure, automated identity workflow.
Today’s work was a deep dive into real DevOps foundations: automation, repeatability, and security-first design.
You can check out the code here: https://github.com/Mo-Adnan-Mo-Ayyub/Aws-with-Terraform
You can check out the session here:
Comments
Post a Comment