How to Create AWS Org With Prod, PreProd, and Sandbox?
Introduction
In this guide, we will walk through the process of creating an AWS Organization with three accounts: Prod, PreProd, and Sandbox. We will use Pulumi, a modern infrastructure as code platform, to define and manage these resources. The key services involved include AWS Organizations and IAM for managing accounts and permissions.
Step-by-Step Explanation
Step 1: Set Up Pulumi
- Install Pulumi CLI if you haven’t already:
curl -fsSL https://get.pulumi.com | sh
- Log in to Pulumi:
pulumi login
- Create a new Pulumi project:
pulumi new aws-typescript
Step 2: Define AWS Organization and Accounts
- Open the
index.ts
file in your Pulumi project. - Import the necessary Pulumi and AWS SDK packages:
import * as pulumi from "@pulumi/pulumi"; import * as aws from "@pulumi/aws";
- Create the AWS Organization:
const org = new aws.organizations.Organization("my-org", { featureSet: "ALL", });
- Create the Prod account:
const prodAccount = new aws.organizations.Account("prod-account", { email: "prod@example.com", name: "Prod", roleName: "OrganizationAccountAccessRole", parentId: org.roots[0].id, });
- Create the PreProd account:
const preProdAccount = new aws.organizations.Account("preprod-account", { email: "preprod@example.com", name: "PreProd", roleName: "OrganizationAccountAccessRole", parentId: org.roots[0].id, });
- Create the Sandbox account:
const sandboxAccount = new aws.organizations.Account("sandbox-account", { email: "sandbox@example.com", name: "Sandbox", roleName: "OrganizationAccountAccessRole", parentId: org.roots[0].id, });
Step 3: Deploy the Stack
- Preview the changes:
pulumi preview
- Deploy the stack:
pulumi up
- Confirm the deployment by typing
yes
when prompted.
Summary
In this guide, we created an AWS Organization with three accounts: Prod, PreProd, and Sandbox using Pulumi. We defined the organization and accounts in TypeScript and deployed them using the Pulumi CLI. This setup allows for structured and manageable AWS environments for different stages of development and production.
Full Code Example
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
// Create the AWS Organization
const org = new aws.organizations.Organization("my-org", {
featureSet: "ALL",
});
// Create the Prod account
const prodAccount = new aws.organizations.Account("prod-account", {
email: "prod@example.com",
name: "Prod",
roleName: "OrganizationAccountAccessRole",
parentId: org.roots[0].id,
});
// Create the PreProd account
const preProdAccount = new aws.organizations.Account("preprod-account", {
email: "preprod@example.com",
name: "PreProd",
roleName: "OrganizationAccountAccessRole",
parentId: org.roots[0].id,
});
// Create the Sandbox account
const sandboxAccount = new aws.organizations.Account("sandbox-account", {
email: "sandbox@example.com",
name: "Sandbox",
roleName: "OrganizationAccountAccessRole",
parentId: org.roots[0].id,
});
Deploy this code
Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.
Sign upNew to Pulumi?
Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.
Sign upThank you for your feedback!
If you have a question about how to use Pulumi, reach out in Community Slack.
Open an issue on GitHub to report a problem or suggest an improvement.