1. Answers
  2. How do I build an AWS organizations account with Pulumi?

How do I build an AWS organizations account with Pulumi?

Creating an AWS Organizations account involves setting up a few key resources. AWS Organizations helps you centrally manage and govern your environment as you grow and scale your AWS resources. In this example, we’ll show you how to set up an AWS Organization, create an Organizational Unit (OU), and add an account to that OU.

Steps

  1. Provider Configuration: Define the AWS provider to interact with the AWS API.
  2. Create AWS Organization: Establish an AWS Organization.
  3. Create Organizational Unit (OU): Create an OU within the organization.
  4. Create AWS Account: Add an account to the OU.

Below is the full example.

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

// Create the main AWS Organization
const main = new aws.organizations.Organization("main", {
    awsServiceAccessPrincipals: [
        "cloudtrail.amazonaws.com",
        "config.amazonaws.com",
    ],
    featureSet: "ALL",
});
// Create an Organizational Unit (OU)
const exampleOu = new aws.organizations.OrganizationalUnit("example_ou", {
    name: "ExampleOU",
    parentId: main.roots.apply(roots => roots[0].id),
});
// Create a new AWS Account
const exampleAccount = new aws.organizations.Account("example_account", {
    name: "example-account",
    email: "example@example.com",
    roleName: "OrganizationAccountAccessRole",
    parentId: exampleOu.id,
});
export const organizationId = main.id;
export const accountId = exampleAccount.id;

Summary

In this example, we set up an AWS Organization using the AWS provider. We established an Organizational Unit (OU) within this organization and created a new AWS account within this OU. The outputs display the organization ID and the account ID for reference. This setup helps manage multiple AWS accounts centrally and systematically.

Deploy this code

Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.

Sign up

New to Pulumi?

Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.

Sign up