Skip to content
This repository has been archived by the owner on Oct 7, 2021. It is now read-only.

Document process #1

Merged
merged 49 commits into from
Dec 28, 2018
Merged
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
1d6f338
Document process
osterman Dec 19, 2018
8da506a
wip
osterman Dec 19, 2018
9aab36b
disable git
osterman Dec 19, 2018
2863b81
fmt
osterman Dec 19, 2018
b06b536
fmt
osterman Dec 19, 2018
3feba69
add vars
osterman Dec 19, 2018
b620a20
refactor to support make driven execution
osterman Dec 20, 2018
89171be
Update README
osterman Dec 20, 2018
67a1e49
Update readme
osterman Dec 20, 2018
056a072
Use details
osterman Dec 20, 2018
f895994
Update notes
osterman Dec 20, 2018
5136d85
Start container after bootstrapping
osterman Dec 20, 2018
a027c78
bootstrap root account id
osterman Dec 20, 2018
f065eb9
Refactor makefiles
osterman Dec 20, 2018
072e6ea
Parameterize images and root modules
osterman Dec 20, 2018
0808e0a
docs
osterman Dec 20, 2018
b4796c1
root provisioning
osterman Dec 21, 2018
da29795
Update readme
osterman Dec 21, 2018
ad43368
Update readme
osterman Dec 21, 2018
f029c61
Update README.md
aknysh Dec 21, 2018
8fe9672
Update configs/audit.tfvars
aknysh Dec 21, 2018
690d1bd
Update configs/audit.tfvars
aknysh Dec 21, 2018
fb2aa54
Update configs/corp.tfvars
aknysh Dec 21, 2018
7f6f191
Update configs/dev.tfvars
aknysh Dec 21, 2018
f764631
Update modules/child/main.tf
aknysh Dec 21, 2018
3884ff3
Update configs/staging.tfvars
aknysh Dec 21, 2018
7f148b8
Update configs/testing.tfvars
aknysh Dec 21, 2018
4984420
Update configs/prod.tfvars
aknysh Dec 21, 2018
49a7728
use variables.tf
osterman Dec 21, 2018
1d28744
Update scripts/init-root.sh
aknysh Dec 21, 2018
8dcfb1b
Update configs/data.tfvars
aknysh Dec 21, 2018
d78e650
Update configs/audit.tfvars
aknysh Dec 21, 2018
860fd99
Update readme
osterman Dec 21, 2018
c535f7e
Update readme
osterman Dec 21, 2018
4c2a3ce
Use consistent order of merge
osterman Dec 21, 2018
12f6ffe
add missing vars
osterman Dec 21, 2018
7ede56e
Add user creation
osterman Dec 21, 2018
dee8bc5
upgrade tfrm
osterman Dec 21, 2018
406ed2c
disable agent prompt
osterman Dec 21, 2018
b255ea7
Fix spelling
osterman Dec 21, 2018
272123b
Updated to use bootstrap user
osterman Dec 23, 2018
c07bc6d
Introduce bootstrap user
osterman Dec 24, 2018
beff5bc
child bootstrapping
osterman Dec 24, 2018
b8337d7
Child account provisioning
osterman Dec 26, 2018
8237b09
e2e provisioning
osterman Dec 26, 2018
2b341a5
First e2e working version
osterman Dec 27, 2018
79c0e5e
Addressed CR
osterman Dec 27, 2018
2778d77
Address CR
osterman Dec 28, 2018
37762e9
Address CR
osterman Dec 28, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true

# Override for Makefile
[{Makefile, makefile, GNUmakefile}]
indent_style = tab
indent_size = 4

[Makefile.*]
indent_style = tab
indent_size = 4

[shell]
indent_style = tab
indent_size = 4

[*.sh]
indent_style = tab
indent_size = 4

[*.{tf,tfvars,tpl}]
indent_size = 2
indent_style = space
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.envrc
.build-harness
build-harness
repos/
accounts/
.terraform
*.tfstate
*.tfstate.backup
osterman marked this conversation as resolved.
Show resolved Hide resolved
.idea
*.iml
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]
Copyright 2018 Cloud Posse, LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
30 changes: 30 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Import the cloudposse/build-harness
include $(shell curl -sSL -o .build-harness "https://git.io/build-harness"; echo .build-harness)
include tasks/Makefile.*

# Run time environment passed to terraform
export TF_VAR_artifacts_dir ?= $(CURDIR)/artifacts
export TF_VAR_repos_dir ?= $(CURDIR)/repos
export TF_VAR_templates_dir ?= $(CURDIR)/templates

# The target called when calling `make` with no arguments
export DEFAULT_HELP_TARGET = help/short

# The command we'll use to start the container
export DOCKER_RUN = docker run --rm -it -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY -e SSH_KEY=false \
-v $(CURDIR)/artifacts:/artifacts -v $(CURDIR)/scripts:/scripts

# The directory containing configs
export CONFIGS ?= configs

## Clean up
clean::
rm -rf repos accounts .terraform *.tfstate* artifacts/*

## Format all terraform code
fmt:
find $(CONFIGS) -type f -name '*.tfvars' -exec terraform fmt {} \;
terraform fmt modules

finalize: root/finalize children/finalize
@exit 0
181 changes: 180 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,181 @@
# reference-architectures
Get up and running quickly with one of our reference architecture using our cold start process.

Get up and running quickly with one of our reference architectures using our fully automated cold-start process.

__NOTE:__ This project is under active development and subject to change. Please [file issues](https://github.com/cloudposse/reference-architectures/issues/new) for all bugs encountered.

## Table of Contents

- [reference-architectures](#reference-architectures)
- [Table of Contents](#table-of-contents)
- [Known Limitations](#known-limitations)
- [High Level Overview](#high-level-overview)
- [Architecture](#architecture)
- [Assumptions](#assumptions)
- [Checklist](#checklist)
- [1. Provision Root Account](#1-provision-root-account)
- [2. Provision Subaccounts](#2-provision-subaccounts)
- [3. Delegate DNS](#3-delegate-dns)
- [Next Steps](#next-steps)
- [Getting Help](#getting-help)

## Known Limitations

- AWS does not support programmatic deletion of accounts. This means that if you use this project to create the account structure, terraform is not able to completely destroy it.
- AWS by default only permits one subaccount. This limit can be easily increased for your organization, but can take up to several days.

## High Level Overview

You can provision the basic reference architecture in 3 "easy" steps. =)

All accounts will leverage our [`terraform-root-modules`](https://github.com/cloudposse/terraform-root-modules/) service catalog to get you started. Later, we recommend you fork this and start your own service catalog suitable for your organization.

This process involves using `terraform` to generate the code (`Dockerfile`, `Makefile`, `terraform.tfvar`, etc) that you will use to manage your infrastructure.

This is a "bootstrap" process that gets you running from a cold-start. You do it once and then you literally throw *this* (e.g. `reference-architectures/`) repo away. This project generates all the pre-configured boilerplate scaffolding you need in the `repos/` directory.

When you're done, in the `repos/` directory you'll have one Git repo for each AWS account. These repos are what you'll want to push up to GitHub. Each repo contains everything necessary to administer that account. We practice a strict "share nothing" approach, which is why each account gets it's own repo, terraform state backend, and DNS zone. This maximally reduces the blast radius of any human errors in one account affecting any other account. Also, because each account has it's own repo, it's *ideally* suited for larger enterprise or corporate environments where various stakeholders will be responsible for running services in their account.

## Architecture

Our "reference architecture" is an opinionated approach to architecting accounts for AWS.

This process provisions (7) accounts which have different designations.

Here is what it includes.

| Account | Description |
| ------- | ------------------------------------------------------------------------------------ |
| root | The "root" (parent) account creates all child accounts and is where users login |
| prod | The "production" is account where you run your most mission critical applications |
| staging | The "staging" account is where you run all of your QA/UAT/Testing |
| dev | The "dev" sandbox account is where you let your developers have fun and break things |
| audit | The "audit" account is where all logs end up |
| corp | The "corp" account is where you run platform services for the company |
| data | The "data" account is where the quants live =) |

Each account has its own [terraform state backend](https://github.com/cloudposse/terraform-aws-tfstate-backend), along with a [dedicated DNS zone](https://www.terraform.io/docs/providers/aws/r/route53_zone.html) for service discovery.

The root account owns the top-level DNS zone and then delegates NS authority to each child account.

### Assumptions

1. We are starting with a clean AWS environment and a new "root" (top-level) AWS account. This means you need the "root" credentials, since a fresh AWS account doesn't even have any AWS roles that can be assumed.
2. You have administrator access to this account
3. You have [docker](https://docs.cloudposse.com/tools/docker/) installed on your workstation
4. You have [terraform](https://www.terraform.io/downloads.html) installed on your workstation

### Checklist

Before we get started, make sure you have the following

- [ ] Before you can create new AWS accounts under your organization, you must [verify your email address](https://docs.aws.amazon.com/console/organizations/email-verification)
- [ ] Open a support ticket to [request the limit](https://console.aws.amazon.com/support/v1#/case/create) of AWS accounts be increased for your organization (the default is 1)
- [ ] Clone this repo on your workstation
- [ ] Create a *temporary* pair of [Access Keys](https://console.aws.amazon.com/iam/home#/security_credential). These should be deleted afterwards.
osterman marked this conversation as resolved.
Show resolved Hide resolved
- [ ] Export your AWS "root" account credentials as `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` (this is *temporary* for bootstrapping)
- [ ] An available domain we can use for DNS-base service discovery (E.g. `ourcompany.co`). This domain must not be in use elsewhere
- [ ] Ensure that any users who will be added during this bootstrap process have setup their [keybase](http://keybase.io) profile. You'll need this if setting them up in the `users` section of the [`config/root.tfvars`](https://github.com/cloudposse/reference-architectures/blob/master/configs/root.tfvars). For example you should be able to [verify their public key](https://keybase.io/osterman/key.asc) on `keybase.io` by running `curl https://keybase.io/$username/key.asc`.
osterman marked this conversation as resolved.
Show resolved Hide resolved

### 1. Provision Root Account

The "root" account is the top-most AWS account from which all other AWS accounts are programmatically created.

__WARNING:__ Terraform cannot remove an AWS account from an organization. Terraform will not close the account. The member account must be prepared to be a standalone account beforehand. See the [AWS Organizations documentation](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_accounts_remove.html) for more information.
osterman marked this conversation as resolved.
Show resolved Hide resolved

__WARNING:__ Do not chain the `make` targets together (e.g. `make root children finalize`) as it is not currently supported.

This account is provisioned slightly different from the other subaccounts.

Update the configuration for this account by editing the `configs/root.tfvar` file.

Then to get started, run:

```bash
make root
```

__NOTE:__ We need to know each account's `AWS_ACCOUNT_ID` for Step 2.
__NOTE:__ Sometimes provisioning of the `account` module fails due to rate limiting by AWS on creating subaccounts. If this happens, just run `make root/provision` to retry. If that works, just continue on to step 2, once it completes.

<details>
<summary>Here's what that roughly looks like (but entirely automated). </summary>

1. Create a new account git repo
2. Render templates into the repo (including `Dockerfile`)
3. Build a docker image
4. Run the docker image and start provisioning resources including the Terraform state backend and child accounts
5. Create the IAM groups to permit access to child accounts
6. Write a list of child account IDs so we can use them in the next phase

</details>

### 2. Provision Subaccounts

Subaccounts are created by the root account, but are ultimately provisioned using the subaccount containers.

Update the configuration for all the child accounts by editing the `configs/root.tfvar` file.

To get started, run:

```bash
make children
```

<details>

<summary>Here's what that roughly looks like (but entirely automated).</summary>

For each child account:

1. Create a new account git repo
2. Render the templates for a `child` account into the repo directory (include `Dockerfile`). Obtain the account ID from the previous phase.
3. Build a docker image
4. Run the docker image and start provisioning the child account's Terraform state bucket, DNS zone, cloudtrail logs, etc.

</details>

### 3. Delegate DNS

Now that each subaccount has been provisioned, we can delegate each DNS zone to those accounts.

To finish up, run:

```bash
make finalize
```

<details>
<summary>Here's what that roughly looks like (but entirely automated).</summary>

1. Re-use the docker images from phase (1) and phase (2)
2. Update DNS so that root account delegates DNS zones to the child accounts
3. Enable cloudtrail log forwarding to audit account

</details>

---

## Next Steps

At this point, you have everything you need to start terraforming your way to success.

All of your account configurations are currently in `repos/`

1. Commit the changes in `repos/`. Open Pull Requests.

2. Ensure that the name servers for the service discovery domain (e.g. `ourcompany.co`) have been configured with your domain registrar (e.g. GoDaddy)

3. Delete your root account credentials. They are no longer needed and should not be used. Instead use the created IAM users.

4. Request limits for EC2 instances to be raised in each account corresponding to the region you will be operating in.

5. Consider adding some other capabilities from our service catalog.

6. Create your own [`terraform-root-modules`](https://github.com/cloudposse/terraform-root-modules) service catalog for your organization

__NOTE:__ *This* repo can be deleted once you're all done and pushed your changes to GitHub. The rest of your development will happen inside your infrastructure repos.

## Getting Help

Did you get stuck? Find us on [slack](https://sweetops.cloudposse.com) in the `#geodesic` channel.
1 change: 1 addition & 0 deletions configs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update these configurations to suit your environment
20 changes: 20 additions & 0 deletions configs/audit.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This is a terraform configuration file

stage = "audit"

# List of templates to install
templates = [
"Dockerfile.child",
".gitignore",
".dockerignore",
"Makefile",
"conf/Makefile"
]

# List of terraform root modules to enable
terraform_root_modules = [
"aws/tfstate-backend",
"aws/account-dns",
"aws/chamber",
"aws/audit-cloudtrail"
]
21 changes: 21 additions & 0 deletions configs/corp.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This is a terraform configuration file

stage = "corp"

# List of templates to install
templates = [
"Dockerfile.child",
".gitignore",
".dockerignore",
"Makefile",
"conf/Makefile",
"conf/account-dns/terraform.tfvars"
]

# List of terraform root modules to enable
terraform_root_modules = [
"aws/tfstate-backend",
"aws/account-dns",
"aws/chamber",
"aws/cloudtrail"
]
21 changes: 21 additions & 0 deletions configs/data.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This is a terraform configuration file

stage = "data"

# List of templates to install
templates = [
"Dockerfile.child",
".gitignore",
".dockerignore",
"Makefile",
"conf/Makefile",
"conf/account-dns/terraform.tfvars"
]

# List of terraform root modules to enable
terraform_root_modules = [
"aws/tfstate-backend",
"aws/account-dns",
"aws/chamber",
"aws/cloudtrail"
]
21 changes: 21 additions & 0 deletions configs/dev.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This is a terraform configuration file

stage = "dev"

# List of templates to install
templates = [
"Dockerfile.child",
".gitignore",
".dockerignore",
"Makefile",
"conf/Makefile",
"conf/account-dns/terraform.tfvars"
]

# List of terraform root modules to enable
terraform_root_modules = [
"aws/tfstate-backend",
"aws/account-dns",
"aws/chamber",
"aws/cloudtrail"
]
21 changes: 21 additions & 0 deletions configs/prod.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This is a terraform configuration file

stage = "prod"

# List of templates to install
templates = [
"Dockerfile.child",
".gitignore",
".dockerignore",
"Makefile",
"conf/Makefile",
"conf/account-dns/terraform.tfvars"
]

# List of terraform root modules to enable
terraform_root_modules = [
"aws/tfstate-backend",
"aws/account-dns",
"aws/chamber",
"aws/cloudtrail"
]
Loading