Running an AWS Organization from Terraform in an AWS opt-in Region
Running an AWS Organization from Terraform in af-south-1, an opt-in region, from git clone to teardown. Covers enabling the region, the state bucket, cross-account AssumeRole that fails with AccessDenied unless STS is signed for us-east-1, Identity Center, the region allow-list, and the 90-day teardown wait. Includes a two-account comparison, real error text, and a list of what I did and didn't test.
I run an AWS Organization from Terraform in
af-south-1 , which is an opt-in region. I picked it without researching it, and I found out what that means one failure at a time. If you already run a setup like this and something is breaking, read on. This is what broke for me and what fixed it, plus the few commands I wish I'd had earlier. Some of it may match what you're stuck on. If you're starting fresh, us-east-1 skips most of this.How I ended up here
It started small. I wanted to learn how AWS Organizations work, so I created one and picked
af-south-1 as its region. My thinking was "why not?". I didn't research why most people stay in us-east-1 , and I had no idea that an opt-in region comes with caveats.Identity Center came in later, when I wanted to create users for Kiro. According to the Kiro supported regions documentation at the time of writing, a Kiro profile can only be created in
us-east-1 or Europe (Frankfurt), and the Identity Center instance has to sit in a region Kiro supports, which does not include af-south-1 . So Identity Center lives in us-east-1 while everything else lives in af-south-1 . That split is where a lot of the interesting problems came from.I also wasn't aware at the time that AWS Control Tower would have set up the accounts for me. I wanted to understand the pieces, so I wrote the whole thing in Terraform, the hard way, and I'm still running it in
af-south-1 for two reasons. It's how I'm learning, because doing it by hand shows me exactly where things break. And I've since gotten deep into a project on top of it, so rebuilding in us-east-1 now would cost far more than it gives back.The rest of this article follows the order I run things in, from a fresh clone to teardown, and stops at each place the opt-in region changed something. The commands come from
aws-org-terraform-starter , a cleaned-up public extract of my private repo. The extract defaults to us-east-1 , so the opt-in changes are what I do on top of it, and its status is at the end.

Architecture of the setup. The management account holds the state bucket, Organizations and the SCPs in af-south-1, and the global STS endpoint, Identity Center, IAM, the GitHub OIDC role and ACM in us-east-1. Member accounts sit to the right, reached by AssumeRole through the global STS endpoint.
Cloning and signing in

The order of the steps from clone to teardown. Yellow boxes are the steps that change because the region is opt-in.
I need Terraform 1.10 or newer, AWS CLI 2.32 or newer (the version that has
aws login ), git and the GitHub CLI. I work as an IAM user with AdministratorAccess , not root. That is simply what I already had, and I haven't tried the Identity Center route for this.git clone https://github.com/midega-g/aws-org-terraform-starter.gitcd aws-org-terraform-starter./scripts/setup-hooks.sh
aws login --profile org_mgmt_userexport AWS_PROFILE=org_mgmt_useraws sts get-caller-identityaws login signs in through the browser and keeps short-lived credentials, so there are no access keys on disk. When they expire, the CLI says Your session has expired , and I run the same aws login again.The first time you run it,
aws login asks for a default region for the profile. Which one you pick matters less than it looks, because Terraform takes its region from terraform.tfvars , not from the profile. If you don't need an opt-in region, us-east-1 is the simple choice. I entered af-south-1 , since that is the region I use. Either works for the CLI calls in this article that take an explicit --region . Later I also use a second profile that signs for us-east-1 on purpose, and that is a separate setting from this one.The state bucket
The bucket's region is the first place the choice shows up. In my private repo I put the Terraform state bucket in
af-south-1 , which meant three extra things.The region has to be enabled in the account before Terraform can create anything in it. In the management account that can be done from the console, or with the CLI, and it takes a few minutes to become active:
aws account enable-region --region-name af-south-1aws account list-regions --region-opt-status-contains ENABLED ENABLED_BY_DEFAULTlist-regions is how I check the result. On my management account it shows af-south-1 as ENABLED and us-east-1 as ENABLED_BY_DEFAULT . Running enable-region again on a region that is already on is harmless. It returns ValidationException: Unable to switch region status because of its current opt-in status , which I read as "nothing to do".The region has to be set in every workspace. I keep it in a gitignored
terraform.tfvars in each one:aws_region = "af-south-1"The bucket is created by a small bootstrap workspace that keeps its state locally, because the bucket can't store the state of its own creation:
cd terraform/00_bootstrapterraform initterraform apply -var 'aws_region=af-south-1' -var 'state_bucket_name=<your-unique-bucket-name>'The other workspaces use that bucket as their backend, with S3's own locking (
use_lockfile = true ), so there is no DynamoDB table. They find it through a gitignored backend.hcl , and the region in it has to match, or terraform init looks for the bucket in the wrong place:cd ..cp backend.hcl.example backend.hclbucket = "<your-unique-bucket-name>"region = "af-south-1"The Organization
The Organization comes next. I always run
plan and read it first, because this step turns the account into the management account of a new Organization:cd 01_orgterraform init -backend-config=../backend.hclterraform planterraform applyIt creates the Organization and three OUs (Security, Sandbox and Workloads). A member account is created only when I set
create_sandbox_account=true with a unique sandbox_account_email , and the teardown part explains why that is off by default. My private repo creates more accounts than the starter does (log archive, security tooling and others). Every member account, whichever repo creates it, needs the region enabled and a role assumed into it, which is where the first real opt-in failure appeared.Assuming a role into a member account
Creating an account through Organizations also creates a role in it called
OrganizationAccountAccessRole , which trusts the management account. My pattern is to sign in once to the management account and assume that role to work in a member account. For the CLI that is a second profile that borrows the first one's credentials:[profile sandbox]source_profile = org_mgmt_userrole_arn = arn:aws:iam::<SANDBOX_ACCOUNT_ID>:role/OrganizationAccountAccessRoleregion = us-east-1The last line matters. When I assumed the role into my sandbox account through the
af-south-1 STS endpoint, from the CLI and from a Terraform provider alike, I got this (account IDs replaced):An error occurred (AccessDenied) when calling the AssumeRole operation: User: arn:aws:iam::<MGMT_ACCOUNT_ID>:user/org_mgmt_user is not authorized to perform: sts:AssumeRole on resource: arn:aws:iam::<ACCOUNT_ID>:role/OrganizationAccountAccessRoleThat was confusing, because my operator policy explicitly allowed that exact role ARN and the role trusts the management account. Nothing in the message mentions a region.
What is actually different
My Organization gave me a controlled comparison. Two member accounts, the same management user, the same role name. I compared only the region setting and the role name. The accounts could differ in other ways I didn't check, such as creation date, SCP attachment or the role's trust policy. I read the region status by assuming the role through the global endpoint, using those temporary credentials, and asking the member account itself:
# run with the assumed-role credentials, so it answers for the member accountaws account list-regions \ --query 'Regions[?RegionName==`af-south-1`].RegionOptStatus|[0]' --output textWithout those credentials the same command answers for the account you are signed in to, which is the management account. A
sandbox profile like the one above should do the same job, but I ran it with exported temporary credentials, not with a profile.Member account | af-south-1 in that account | Assume through the af-south-1 endpoint | Assume through the global endpoint |
|---|---|---|---|
Sandbox | DISABLED | AccessDenied | works |
Log archive | ENABLED | works | works |
A successful call returns the assumed identity, for example:
aws sts assume-role \ --role-arn arn:aws:iam::<ACCOUNT_ID>:role/OrganizationAccountAccessRole \ --role-session-name test1 --region us-east-1 \ --endpoint-url https://sts.amazonaws.com \ --query AssumedRoleUser.Arn --output text# arn:aws:sts::<ACCOUNT_ID>:assumed-role/OrganizationAccountAccessRole/test1So the failure followed the member account's region setting, not my management credentials. That matches what AWS says: a manually enabled region has to be active in both the account making the request and the account the role is in ( AWS re:Post ). My first assumption was that the regional endpoint rejects credentials that come from an opt-in region, and this comparison doesn't support that. Two caveats. It is two accounts and one run, and I didn't enable the region in the sandbox account and run it again, because that would change a live account. The global endpoint works whether or not the member account has the region on. My reading is that this is why the fix works, and why it can be used to enable the region in the first place.
The fix
Sign the request for
us-east-1 and use the global STS endpoint. For a profile, it's the region = us-east-1 line above. For Terraform, I added sts_region to every provider that assumes a role:provider "aws" { alias = "member" region = var.aws_region sts_region = "us-east-1"
assume_role { role_arn = "arn:aws:iam::${aws_organizations_account.member.id}:role/OrganizationAccountAccessRole" }}In my private repo I also set the STS endpoint explicitly to
https://sts.amazonaws.com inside an endpoints block next to sts_region .An opt-in region is also off by default in every account, including the ones created later, so each member account needs it enabled. Each member account in my private repo gets an
aws_account_region resource that uses an assume-role provider. Here is a self-contained version, about 25 lines, for a member account that already exists. The account has to exist first, because the provider assumes into it, so I create accounts in an earlier step:terraform { required_providers { aws = { source = "hashicorp/aws", version = "~> 6.0" } }}
variable "aws_region" { default = "af-south-1" }variable "member_account_id" {}
provider "aws" { alias = "member" region = var.aws_region sts_region = "us-east-1"
assume_role { role_arn = "arn:aws:iam::${var.member_account_id}:role/OrganizationAccountAccessRole" }}
resource "aws_account_region" "member" { provider = aws.member region_name = var.aws_region enabled = true}I ran
terraform plan on this file against my sandbox account with the management profile, and did not apply anything. It ended with:Plan: 1 to add, 0 to change, 0 to destroy.The provider assumes the role as soon as it is used, so a denied call shows up at plan and not at apply. With the
sts_region line removed, the same plan against the same account fails before it plans anything:Error: Cannot assume IAM Role...Error: operation error STS: AssumeRole, https response error StatusCode: 403,RequestID: <REQUEST_ID>, api error AccessDenied:User: arn:aws:iam::<MGMT_ACCOUNT_ID>:user/org_mgmt_user is not authorized toperform: sts:AssumeRole on resource:arn:aws:iam::<ACCOUNT_ID>:role/OrganizationAccountAccessRoleApplying the resource when the region is already on does nothing, and it can take a few minutes to take effect the first time. I didn't apply it, since the resource would enable the region in a live account.
Identity Center in a different region
My Terraform and README treated
af-south-1 as the Identity Center home region. When I checked, list-instances returned nothing there:aws sso-admin list-instances --region af-south-1 # emptyaws sso-admin list-instances --region us-east-1 # the live instanceThe live instance was in
us-east-1 , owned by the management account, with my Kiro subscription attached to it. The config had assumed something that was never true. Since then, every Identity Center and Identity Store command I run has --region us-east-1 on it, because without it I query the wrong region and conclude that nothing exists.A few other things stay in
us-east-1 whatever region the rest of the Organization uses. CloudFront certificates in ACM and the billing and cost allocation tag APIs are two. I use a second provider alias pinned to us-east-1 for them. This is where each thing ended up in my setup:Thing | Region |
|---|---|
Terraform state bucket, member account resources | af-south-1 |
Identity Center instance and its APIs | us-east-1 |
ACM certificates for CloudFront | us-east-1 |
Billing and cost allocation tag APIs | us-east-1 |
STS for cross-account AssumeRole | global endpoint, signed for us-east-1 |
Guardrails and the region allow-list
Two more workspaces follow,
02_scps and 03_iam . Both read the Organization's outputs from the state bucket, so they take its name. The SCPs attach to the Sandbox OU, and the IAM policies (an operator policy and an explicit-deny backstop) are created but not attached to my user, for reasons in the lockout story near the end:cd ../02_scps && terraform init -backend-config=../backend.hcl && terraform apply -var 'state_bucket=<your-unique-bucket-name>'cd ../03_iam && terraform init -backend-config=../backend.hcl && terraform apply -var 'state_bucket=<your-unique-bucket-name>'One SCP denies activity outside a set of allowed regions. It has an exemption list for global services such as IAM, STS and Organizations, which would otherwise break. The one thing the opt-in region changes is the allow-list. My region has to be in it, and
us-east-1 has to stay, because of the services above. I set it in the same terraform.tfvars as the region:allowed_regions = ["af-south-1", "us-east-1"]If the opt-in region is missing from that list, everything in it is denied, in every account the policy covers.
The pipeline
The last workspace creates a GitHub OIDC provider and an IAM role that only my repo can assume. I apply it from the laptop, because the pipeline can't create the role it signs in with:
cd ../04_github_oidcterraform init -backend-config=../backend.hclterraform apply \ -var 'state_bucket=<your-unique-bucket-name>' \ -var 'github_owner=<your-github-user>' \ -var 'github_repo=aws-org-terraform-starter'
gh secret set AWS_ROLE_ARN --body "$(terraform output -raw role_arn)"gh secret set TF_STATE_BUCKET --body '<your-unique-bucket-name>'gh variable set ENABLE_AWS --body trueNothing here is specific to an opt-in region. The pipeline runs the same provider blocks, so I expect the same STS fix to apply there.
ENABLE_AWS is what switches the plan and apply jobs on.Verifying it worked
A successful apply only tells me Terraform did what it was asked. These checks tell me it works:
aws organizations describe-organization --query 'Organization.[FeatureSet,MasterAccountId]'aws organizations list-policies --filter SERVICE_CONTROL_POLICY --query 'Policies[].Name'To prove the allow-list denies a region, I test from a member account, because SCPs never apply to the management account and testing there proves nothing:
aws ec2 describe-vpcs --region us-east-1 --profile sandbox # allowed, returns dataaws ec2 describe-vpcs --region eu-west-1 --profile sandbox # expect an explicit-deny errorFor the pipeline, I open a pull request. The
Plan: 01_org job should sign in without any stored key, and its credentials step should show an assumed role named after OrgGitHubActionsRole .Tearing it down
Terraform can create member accounts but not delete them, so teardown has an order, and getting it wrong leaves errors that don't explain themselves. Destroy takes the same variables as apply. I start from the repo root, in a new terminal, because the earlier commands left my shell inside a workspace folder.
First the workspaces that sit on top, in reverse order. The bucket and the bootstrap workspace have to stay until the Organization is gone, because the bucket holds the Organization's state, and I must not empty it early. The explicit-deny policy in
03_iam also denies s3:DeleteBucket on the state bucket, so it has to go first: destroying 03_iam removes it, and if it is attached to my user I detach it before that:cd terraform/04_github_oidcterraform destroy -var 'state_bucket=<bucket>' -var 'github_owner=<your-github-user>' -var 'github_repo=aws-org-terraform-starter'cd ../03_iam && terraform destroy -var 'state_bucket=<bucket>'cd ../02_scps && terraform destroy -var 'state_bucket=<bucket>'Then the accounts. A sandbox account has to be closed by hand in the console, under Account, then Close account. A closed account stays in the Organization as suspended for up to 90 days, and AWS won't let me remove it or delete the Organization until that ends ( AWS documentation ). So destroying the Organization has to wait, and that is why the sandbox account is off by default. When I closed mine, my own explicit-deny policy also blocked the close, so I removed
organizations:CloseAccount from it, applied, closed the accounts and put it back. That was the policy doing exactly what I'd written.When
aws organizations list-accounts no longer shows the account, I remove it from state and destroy the Organization, which fails while any member account, even a suspended one, is still in it:cd ../01_orgterraform state rm 'aws_organizations_account.sandbox[0]'terraform destroyLast is the state bucket. It is versioned, so a plain delete isn't enough. I delete every object version and delete marker, then destroy the bootstrap. The loop reads keys with
read , so it is meant for a state bucket with simple keys, no spaces in them. The loop avoids the 1,000-key limit of delete-objects and skips the empty list the query returns when nothing is left:for kind in Versions DeleteMarkers; do aws s3api list-object-versions --bucket <bucket> \ --query "${kind}[].[Key,VersionId]" --output text | while read -r key ver; do [ "$key" = "None" ] && continue aws s3api delete-object --bucket <bucket> --key "$key" --version-id "$ver" donedone
cd ../00_bootstrapterraform destroy -var 'aws_region=af-south-1' -var 'state_bucket_name=<bucket>'I wrote these steps from the AWS documentation and from the way the workspaces fit together, and I haven't run the whole sequence end to end.
Not opt-in specific, but costly
These would happen in any region.
A guardrail locked me out. The explicit-deny policy is a backstop, and attaching it takes effect immediately. While renaming my operator user, Terraform destroyed the old policy attachments and my user instantly lost every permission, including access to the state bucket it needed to finish the apply and release its lock. A second admin user got me back in. When Terraform then wanted to re-create the attachments, my user no longer had permission to attach anything, so I attached a temporary inline policy from the other admin, applied, and removed it. The recovery command, run from the other admin, is in the list below. I keep a second way in now, and the policies aren't attached to my user by default.
Two smaller ones. The operator policy hit
LimitExceeded: Cannot exceed quota for PolicySize: 6144 , which I solved with a second managed policy, and a failed pipeline run left a stale state lock that terraform force-unlock <LOCK_ID> clears.What I'd keep next to the keyboard
Most of the problems above are in a runbook in my private repo, where each entry has the symptom, the cause, the fix and the exact commands. These are the ones I use most:
# Is the opt-in region enabled in this account?aws account list-regions --region-opt-status-contains ENABLED ENABLED_BY_DEFAULT
# Can I assume the role through us-east-1?aws sts assume-role --role-arn <ROLE_ARN> --role-session-name test \ --region us-east-1 --endpoint-url https://sts.amazonaws.com
# Where does Identity Center actually live?aws sso-admin list-instances --region us-east-1
# Clear a stale state lockterraform force-unlock <LOCK_ID>
# Get back in after a deny policy locks the user out (run as another admin)aws iam detach-user-policy --user-name <your-iam-user> --policy-arn <DENY_POLICY_ARN>I'm keeping the setup in
af-south-1 . If I started again I would use us-east-1 , and I'd still write down what the opt-in region cost, which is what this article is.The repo, and what is and isn't proven
The public repo,
aws-org-terraform-starter , is a cleaned-up extract of my private one, and its README has the same path from clone to clean-up. docs/OPT-IN-REGION.md lists the opt-in changes in order, with the snippets: enabling the region, the region in every workspace, the allow-list, enabling it in each member account, and STS through us-east-1 .I haven't run the public repo from scratch in an opt-in region. That needs a brand-new management account with its own payment details, and I can't share my private repo as proof, because it holds my real account IDs, OU layout, SCPs and OIDC trust. So here is what I did run, against the private setup:
list-regions and enable-region on the management account, the assume-role comparison above on two member accounts, and terraform plan of the example file, with and without sts_region . I only checked that force-unlock accepts a lock ID, not that it clears a real lock, and I syntax-checked the bucket-emptying loop without running it. I haven't run the destroy sequence. Closed accounts stay suspended for up to 90 days, so repeating it means rebuilding the Organization first.The opt-in region costs me almost nothing. The Organization, SCPs and IAM have no charge. My state bucket holds 268 object versions totalling under 1 MB, which is a fraction of a cent a month in storage. I didn't count API requests, so that part is an estimate, and with a first-year account most of it sits inside the free tier.
What I would test next: enable the region in the sandbox account and rerun the comparison, which would turn my two-account result into a before and after; run the destroy sequence on a throwaway Organization; and confirm the pipeline job assumes into a member account with
sts_region set. If you've hit one of these problems, or you tested something I haven't, reach out and I'll help where I can.Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article