π In This Post
Lab Overview
An AWS account exists. Who is allowed to log into it?
The problem. Answered by hand, it is always answered the same way: an IAM user per person per account, an access key handed over, and no one place that knows who can reach what. Those keys do not expire, and they are the first thing an AWS security review asks about.
The objective. Define the access once β three permission sets, three groups β and let AWS provision the matching role into every target account. Then sign in as a real test user and see exactly what she gets.
The outcome. It works, and the roles appear in the target account without being declared there. One optional Terraform argument, left at its default, quietly makes the whole thing a no-op.
- Define Once A permission set (e.g.
Engineers) is written once in Terraform, backed by an AWS managed policy and its own session duration. - Group, Don't User People join a group (
Engineers,ReadOnlyAuditors,BreakGlassAdmins) instead of getting individual per-account permissions. - Assign Across Accounts Terraform assigns each group's permission set to every target account in one pass β AWS auto-provisions the matching IAM role in each one.
- Sign In Once Users sign in to a single SSO portal and federate into whichever account/role they're assigned β temporary credentials only, never a static key.
Cloud Services and Concepts
| Service | Purpose here | What it is |
|---|---|---|
| IAM Identity Center | Defines who exists and what they may do, once, for every account | AWS's sign-in and assignment layer for people. Users and groups are defined once, and assignments grant them a role in each account. |
| Permission set | The three access levels, written once each | A reusable role template β a policy plus a session duration β that exists on its own until it is assigned to an account. |
| Account assignment | Binds a group to a permission set in one target account | The link between a group and a permission set, scoped to a single account. Making one is what causes AWS to provision the real role. |
| AWSReservedSSO role | What actually exists inside the target account | The IAM role Identity Center creates in the target account when an assignment is made. You never declare it, and it is auditable in that account's own IAM. |
| AWS access portal | Where a person signs in | One sign-in page that lists only the accounts and roles the signed-in user's own group memberships grant. |
| AWS Organizations | Supplies the target accounts | Groups AWS accounts under one management account, so policy and billing apply across all of them rather than account by account. |
| HCP Terraform | Provisioning, with no static keys | HashiCorp's hosted Terraform. It runs plans and applies on its own machines and keeps the state file, and it assumes an AWS role by OIDC so no static keys exist anywhere. |
Two ideas carry the whole build. A permission set is a role that does not exist anywhere yet; an assignment is what makes AWS create it, in one account, for one group. Everything else follows from that split.
Architecture and Workflow
Why Groups Instead of Per-User Assignments?
Permission sets are assigned to groups, never to individual users. Adding someone to Engineers grants every account that group already has, with no Terraform apply per person.
Why a Cross-Product for Assignments?
Every group needs its permission set in every account, so the module builds the set as setproduct(keys(groups), target_account_ids). Add an account to the OU and the next apply assigns every group to it.
Prerequisites
| Requirement | Why | How to check |
|---|---|---|
| An AWS Organization with at least one active account in the target OU | An assignment needs somewhere to land; Week 6's vending machine is what produces these | aws organizations list-accounts-for-parent --parent-id <ou-id> |
| IAM Identity Center enabled in the management account | A one-time manual switch. No aws_ssoadmin_* resource can create the instance itself, so Terraform fails before it starts without it | aws sso-admin list-instances returns an instance ARN |
| An HCP Terraform workspace with OIDC into the AWS role | Keeps credentials out of the repo and out of CI | The role's trust policy already wildcards workspace:*, so a new workspace inherits it with no IAM change |
| An email address for the test user | Identity Center users created by Terraform have no password and no MFA device; the invitation is sent to this address | Kept in terraform.tfvars, which is gitignored |
Implementation
Step 1: The identity-center Terraform Module
One module, six resource types, looped over a single groups map:
locals {
assignments = {
for pair in setproduct(keys(var.groups), var.target_account_ids) :
"${pair[0]}-${pair[1]}" => {
group_name = pair[0]
account_id = pair[1]
}
}
}
resource "aws_ssoadmin_account_assignment" "this" {
for_each = local.assignments
instance_arn = var.instance_arn
permission_set_arn = aws_ssoadmin_permission_set.this[each.value.group_name].arn
principal_id = aws_identitystore_group.this[each.value.group_name].group_id
principal_type = "GROUP"
target_id = each.value.account_id
target_type = "AWS_ACCOUNT"
}
The target accounts are not hardcoded. They are looked up from Week 6's vended OUs with aws_organizations_organizational_unit_child_accounts, so adding an account to Sandbox or Production becomes a new assignment target on the next apply.
Step 2: Enable IAM Identity Center (Manual, One-Time)
Enable it in the management account and choose the Organization instance type, not Account: only Organization lets assignments target every member account.
Step 3: The HCP workspace
week-07-dev was created through the HCP Terraform API rather than the UI, the same way Week 6's was; the exact call is in the lab guide. The OIDC trust policy on hcp-terraform-role already wildcards workspace:*, so the new workspace inherited working AWS auth with no IAM change at all.
The first apply added nine resources β three permission sets, three policy attachments, three groups. Confirmed directly in the console β the three groups exist:
And the permission sets, each backed by its managed policy:
Step 4: Adding a Test User and Assigning to a Real Account
A second apply added the test user jane.engineer to the Engineers group and created the three account assignments:
The assignment is visible from the account side too β all three groups now show up against the target account:
Step 5: Confirming AWS Auto-Provisioned the Roles
This is the part that makes Identity Center worth using: nothing was ever declared inside the target account's own IAM. Switching into it directly shows three roles that simply appeared the moment the assignment was made:
Step 6: Signing In as the Test User
Terraform-created users have no password and no MFA device, so the first sign-in needs an admin-initiated reset (see Troubleshooting). Signed in, the portal showed exactly one account and one role:
Validation and Evidence
Each row traces to a figure in this post. The lab was destroyed in July 2026, so these are the results recorded then, not a fresh run.
| Test | Expected | Actual | Status |
|---|---|---|---|
| Terraform creates the identity objects | Three groups and three permission sets | All three groups and all three permission sets present in Identity Center, each with its managed policy | Pass |
| Assignments reach the target account | Each group bound to its permission set on the target account | All three groups listed against the target account | Pass |
| AWS provisions the role itself | An AWSReservedSSO role per permission set, created by Identity Center and never declared in Terraform | Three AWSReservedSSO roles present in the target account's own IAM console | Pass |
| The portal scopes by group membership | The test user sees only the role her own group grants | Signed in as jane.engineer, the portal showed the target account with the Engineers role only | Pass |
| No static credential is issued | A temporary federated session, and no IAM user or access key in the target account | Federated console session issued by Identity Center; no IAM user or access key was created in any target account | Pass |
| Session durations differ by privilege | BreakGlassAdmins shorter than Engineers | Configured at 1 hour against 4 hours. Not recorded at the time whether a session was observed expiring | Configured, not observed |
Security and Cost
Security β Controls at Every Layer
- Least-privilege permission sets. Three distinct levels
(
ReadOnlyAccess,PowerUserAccess,AdministratorAccess) rather than one shared admin role handed to anyone who needs any access at all. - Shortest session for the highest privilege.
BreakGlassAdminsgets a 1-hour session, deliberately shorter than the 4-hourEngineersone. Full-admin access should expire fastest. - No static credentials anywhere. Every session is federated and temporary. No IAM user and no access key was created in any target account, not even for the test user used to validate this.
- Real emails stay out of git.
terraform.tfvarsis gitignored; the committed.exampleshows the shape only.
- MFA enforcement was relaxed to "Allow them to sign in" purely to unblock testing β must be reverted to requiring MFA registration before any real user gets one of these permission sets
- No automated lifecycle for removing a user's group membership when they leave a team or the org
BreakGlassAdminshas no approval workflow or alerting on use β a real break-glass process should notify someone the moment that permission set is actually assumed- Permission sets use broad AWS managed policies; a production rollout should move toward narrower customer-managed or inline policies per role
Cost
IAM Identity Center, permission sets, groups, users, and account assignments are all free β so are the IAM roles Identity Center provisions into target accounts.
Troubleshooting and Lessons
Problem. The first plan created zero account assignments and
reported success.
Root cause. The module derives its targets by listing the child
accounts of named OUs, and Week 6's Sandbox and
Production OUs existed but had nothing vended into them
yet. An empty OU is not an error: it returns an empty list, and
setproduct of three groups with zero accounts is zero
assignments.
Resolution. Overrode target_ou_names to
["Dev"] through an HCP workspace variable, pointing at an
older OU with one active account. A deliberate deviation, written into the README to
be reverted once accounts exist in the intended OUs.
Lesson. A cross-product over a data source yields nothing at all when
one side is empty, and Terraform calls that a successful plan. Assert the count.
Problem. Signing in as the Terraform-created test user returned
"You are required to provide multi-factor authentication that you do not
have" β for a user with no MFA device, and after the MFA setting had
already been relaxed.
Root cause. Not established. It behaved like a stuck sign-in state
left by an earlier blocked attempt rather than a policy being evaluated: relaxing the
setting and waiting for propagation did not clear it.
Resolution. Used the admin-initiated Reset password
on the user's detail page instead of the self-service "Forgot password?" flow. That
path issued a fresh credential and the block disappeared.
Lesson. Identity Center users created by Terraform have no password
and no MFA device, and there is no Terraform equivalent of "send the invitation". The
first sign-in is a manual step, and the admin path is the one that behaves.
Problem. All three permission sets were assigned to the target
account, but the test user's portal showed only Engineers,
which looked like two assignments having failed.
Root cause. Not a fault. The portal scopes by the signed-in user's own
group membership, not by everything assigned to the account, and the test user was only
in Engineers.
Resolution. None needed; confirmed against the assignment API, which
listed all three.
Lesson. The portal and the API answer different questions. Check the
one that reports configuration before concluding the configuration is wrong.
Cleanup and Key Takeaways
Cleanup β Tearing It Down
week-07-dev is VCS-connected, same restriction as Weeks 5β6 β destroy is confirmed from the HCP UI, not local CLI.
| Resource | Destroyed by Terraform? | Manual step needed? |
|---|---|---|
| Permission sets, policy attachments | Yes | AWS refuses to delete a permission set with live assignments anywhere β remove assignments first |
| Identity Store groups, users, membership | Yes | None |
| Account assignments | Yes | None |
| IAM Identity Center instance itself | No β never in state | Disable manually via console, if desired, the same way it was enabled |
The
target_ou_names = ["Dev"] workspace variable override and the relaxed MFA setting were both introduced purely to validate this module end-to-end. Reverting them is a settings/variable change, separate from a Terraform destroy.
References
- Full lab guide on GitHub β prerequisites, Terraform, commands, validation and cleanup.
- What is IAM Identity Center β permission sets, identity store, account assignments explained.
- aws_ssoadmin_permission_set / aws_ssoadmin_account_assignment β the two resources doing most of the work this week.
- aws_identitystore_user / aws_identitystore_group β full user/group management via Terraform, no console clicking required.
- aws_organizations_organizational_unit_child_accounts β how the target accounts are discovered dynamically from Week 6's OUs.
- HCP Terraform API β used to create the workspace and set its variables programmatically, same pattern as Week 6.
- Full source code β week-07-identity-center-sso
Takeaways β What I'd Do Differently
- Groups scale; per-user assignments do not. Onboarding becomes a group-membership change rather than a Terraform apply, so the access model scales independently of headcount.
- Verify the auto-provisioning. The account-side roles are real, auditable resources. Checking them inside the target account, rather than trusting the plan output, is what confirmed the pipeline end to end.
- "Not showing up" is not always a fault. The portal scopes by group membership. Checking the assignment API first saved a wrong fix.
- Document deviations rather than hiding them. Testing against a live account meant diverging from the stated design twice; both are written into the README as reversible.
Comments