Skip to main content

Automating AWS IAM Identity Center with Terraform for Multi-Account Environments

· 7 min read
Lucía López
Junior Platform Engineer

Managing access in AWS can seem simple at first: a few accounts, a handful of users, and permissions that are easy to control from the console. But as an organization grows — as accounts, teams, and roles multiply — that manual management becomes a problem. Errors accumulate, inconsistencies appear, and traceability fades.
Who has access to what? What permissions does each user actually have? What changes were applied last week? These once-trivial questions become increasingly difficult to answer.

That’s where AWS IAM Identity Center (formerly AWS Single Sign-On) comes in. This service centralizes the management of identities and permissions across all your AWS accounts, letting you define from a single place who can access what, and with which level of privilege. It also simplifies auditing and compliance by maintaining a consistent record of assignments and permissions.

However, the existence of IAM Identity Center alone doesn’t solve scalability challenges — manual configuration doesn’t scale. Each user, group, and permission set must be configured account by account, multiplying effort and increasing the likelihood of mistakes. Keeping environments consistent is difficult, and auditing changes becomes a tedious, unreliable process.
In short: manual management isn’t sustainable in the long run.

The solution lies in automating with Terraform, leveraging the Infrastructure as Code (IaC) approach. With Terraform, your entire configuration is defined in version-controlled files — you can review, replicate, and apply changes in a consistent and auditable way. This not only reduces errors but also turns access management into a scalable, controlled, and well-documented process.


Before you start, make sure you have the following:

  • An AWS Organization fully configured with all features enabled.
  • IAM Identity Center activated in the management account.
  • Terraform installed, and credentials with permissions to access the Organizations and SSO Admin APIs.
  • (Optional) A CI/CD pipeline to apply changes centrally and maintain traceability.

Structuring IAM Identity Center Automation with Terraform

When you think of IAM Identity Center through the Terraform lens, the goal is to mirror its real-world structure in code. Each entity (users, groups, permissions, and assignments) becomes a block you can define, modify, and version.

👤 Users
Users represent the people who need access to your AWS accounts. In Terraform, you define their basic data — name, email, full name — and associate them with groups. This avoids assigning permissions individually to each user and allows for consistent role-based management.

👥 Groups
Groups gather users who share similar responsibilities or functions, such as “Developers”, “Billing”, or “SecurityOps”. Instead of granting permissions user by user, you assign them to groups, which greatly simplifies management and reduces human error.

🧾 Permission Sets
Permission sets are the core component: they define what a user or group can do. They can consist of AWS-managed policies (like ReadOnlyAccess) or custom inline policies that grant specific access — for example, read-only access to certain S3 buckets or the ability to list EC2 instances.
This modular design lets you reuse the same permission sets across different accounts or groups, ensuring consistency and simplifying audits.

🗂️ Account Assignments
Finally, account assignments connect groups and permission sets to specific AWS accounts. A single group can have different access levels depending on the account — for example, “Developer” with read-only access in production but write access in staging.
This clear relationship between who, what, and where turns access management into a predictable and auditable system.

Terraform Configuration Example

Here’s an example showing how to define a group, a user, a permission set, and an account assignment in a single module — giving you a complete picture of how the structure fits together:

module "aws-iam-identity-center" {
source = "aws-ia/iam-identity-center/aws"
version = "1.0.2"

# -----------------------------
# Groups
# -----------------------------
sso_groups = {
Developers = {
group_name = "Developers"
group_description = "Group for development team"
}
}

# -----------------------------
# Users
# -----------------------------
sso_users = {
ana = {
group_membership = ["Developers"]
user_name = "ana"
given_name = "Ana"
family_name = "Perez"
email = "ana@example.com"
}
}

# -----------------------------
# Permission Sets
# -----------------------------
permission_sets = {
ReadS3AndEC2 = {
description = "Read-only access to S3 and EC2"
session_duration = "PT8H"
inline_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Action = ["s3:Get*", "s3:List*"]
Resource = "*"
},
{
Effect = "Allow"
Action = ["ec2:DescribeInstances", "ec2:DescribeTags"]
Resource = "*"
}
]
})
}
}

# -----------------------------
# Account Assignments
# -----------------------------
account_assignments = {
Developers = {
principal_name = "Developers"
principal_type = "GROUP"
principal_idp = "INTERNAL"
permission_sets = ["ReadS3AndEC2"]
account_ids = [aws_organizations_account.root.id]
}
}
}

🌟 Best Practices for a Secure and Scalable Setup

Automation is just the first step. To maintain a strong and sustainable setup, follow these design principles:


  • Separate environments (dev, staging, prod)
    Managing each environment separately allows you to test and validate changes before they affect production.
    For example, create specific groups and permission sets per environment — this prevents misconfigurations and ensures access matches the context.

  • Apply the principle of least privilege
    Each user or group should have only the permissions necessary to perform their role.
    This limits potential damage from mistakes or unauthorized access, strengthens overall security, and helps meet compliance requirements.

  • Integrate Terraform into CI/CD pipelines
    Automated pipelines (e.g., using GitHub Actions) can validate and apply Terraform changes safely.
    Before running terraform apply, the pipeline should:
    • Check formatting (terraform fmt)
    • Validate syntax (terraform validate)
    • Run a plan preview (terraform plan)

This ensures every modification goes through review before reaching production, maintaining traceability and governance over who changes what and when.


Example GitHub Actions workflow for Terraform:

name: Terraform CI/CD

on:
push:
branches:
- main
pull_request:

jobs:
terraform:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: 1.8.5

- name: Terraform Format
run: terraform fmt -check

- name: Terraform Validate
run: terraform validate

- name: Terraform Plan
run: terraform plan

- name: Terraform Apply
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
run: terraform apply -auto-approve

  • Use inline policies sparingly
    Inline policies are powerful for fine-tuned permissions but can increase complexity if overused.
    Prefer AWS-managed or organization-wide policies, and reserve inline policies for highly specific cases (e.g., access to a single S3 bucket or specific resource tags).

  • Version and review every change
    Keep your Terraform configuration in a Git repository.
    This enables full change history, branch-based testing, and easy rollback if needed.
    It also allows multiple teams to collaborate safely without overwriting each other’s changes.

🎯 Conclusion

Automating AWS IAM Identity Center with Terraform completely transforms how you manage access in multi-account environments.
You move from a manual, error-prone model to a centralized, reproducible, and auditable system.
This lets you scale without losing control, keep environments consistent, and strengthen security through least-privilege principles.


This approach delivers scalability, security, and efficiency:

  • Scalability – manage hundreds of accounts with a single, consistent codebase.
  • Security – every change is reviewed and governed by the principle of least privilege.
  • Efficiency – fewer manual tasks and faster onboarding for new users and environments.

In short, if your organization is growing and manual access management has become a bottleneck, automating IAM Identity Center with Terraform isn’t just a best practice — it’s the natural next step toward a secure, controlled, and agile cloud environment.