To Deploy Infrastructure on AWS using Pulumi while keeping secrets encrypted in code.
Because we always expect our Infrastructure and Secrets will get out of control. By keeping secrets encrypted in code this allows us to audit, rotate, version, and test them. Pulumi extends pure code so we can build stacks that are highly extensible.
- At least one AWS Account
- At least one IAM user per AWS account
- Python 3 installed locally
- The AWS CLI installed locally
- A method to securely pass IAM credentials to a Python script (we recommend using aws-vault)
- A Pulumi CLI installation (v3.0.0 or later)
Once you've got all the prerequisites taken care of you'll need to provision the following resources:
- An S3 Bucket to be used for keeping Pulumi state
- An IAM role to assume to to access the bucket
- A KMS key for encrypting secrets in state that one or more IAM users have access to
- An encryption key for encrypting secrets in Git
To provision all of these things we'll use the Pulumi service without the Automation API.
If you want to allow one or more IAM users to assume the bucket role you need to set iam_users
to true
and add them. There are examples below.
iam_name
will be the name of the IAM role and IAM policy granting access to the bucket.
We'll start out by deploying required resources in a single AWS account. If you want to allow users in other AWS accounts to access the bucket check out the Next Steps
-
cd shared-state
-
Create a new stack in your account:
pulumi config
-
Set configuration options for stack. Change the values to meet your needs: Required:
pulumi config set bucket_name my-pulumi-state pulumi config set iam_users true pulumi config set iam_name AccessPulumiStateBucket
Optional:
pulumi config set --path iam.users[0] arn:aws:iam::213597402033:user/user1 pulumi config set --path iam.users[1] arn:aws:iam::213597402033:user/user2
To provision the resources you need to run:
pulumi up
or
aws-vault exec {{some-profile}} -- pulumi up
Secrets are in their own stack. See the README.md at infra/secrets
for more details on how to manage your environment secrets.
CodePipeline is used to deploy all of the infrastructure in our environment - including updating itself.
There are a number of dependencies to deploying CodePipeline with CodeBuild Projects. These dependencies are in their separate stacks. For example pipeline-iam
is a stack that creates IAM Roles and Policies that allow the CodeBuild projects deploying infrastructure to do what they need to do.
- Requires a
/16
CIDR