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 19 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
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.envrc
.build-harness
build-harness
repos/
accounts/
.terraform
terraform.tfstate
terraform.tfstate.backup
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
24 changes: 24 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# 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_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 -it -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY -v $(CURDIR)/artifacts:/artifacts -v $(CURDIR)/scripts:/scripts

# The directory containing configs
export CONFIGS ?= configs

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

fmt:
find $(CONFIGS) -type f -name '*.tfvars' -exec terraform fmt {} \;
terraform fmt modules
174 changes: 173 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,174 @@
# 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 architecture using our cold start process.
osterman marked this conversation as resolved.
Show resolved Hide resolved

This is still under active development and subject to change.

## Known Limitations

* AWS does not support programatic deletion of accounts. This means that if you use this project to create the account structure, terraform is not able to completely destroy it.

__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.

## High Level Overview

You can provision the basic referrence architecutre in 3 "easy" steps. =)

All steps leverage our [`terraform-root-modules`](https://github.com/cloudposse/terraform-root-modules/) to get started.

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

This is a "bootstrap" process. You do it once and then you throw *this* repo away.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we need to elaborate why you throw *this* repo away (literally or figuratively)


## 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. |
osterman marked this conversation as resolved.
Show resolved Hide resolved
| 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

- [ ] 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 else where.
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 programatically created.

This account is provisioned slightly different from the other subccounts.

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

Then to get started, run:

```
make root
```

__NOTE:__ We need to know each account's `AWS_ACCOUNT_ID` for Step 2.

<details>
<summary>Here's the pseudo code of what that roughly looks like (but automated). </summary>

```
| mkdir repo
| cd repo
| git init
| Render dockerfile from template
| (Use multi-stage for tfstate, accounts, root-dns)
| Build docker image
| Docker run the image mounting `scripts/` and `artifacts/`
| Setup AWS vault
| aws-vault exec ${AWS_PROFILE} -- /scripts/init-tfstate
| aws-vault exec ${AWS_PROFILE} -- /scripts/init-accounts
```

</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:

```
make children
```

<details>

<summary>Here's the pseudo code of what that roughly looks like (but automated).</summary>

```
for account in ${ACCOUNTS}; do
mkdir $account
cd $account
git init
# Render dockerfile from template
# Use multi-stage for tfstate and account-dns
# Build docker image
# Docker run the image -v scripts/:/scripts
# Setup AWS vault
# assume-role
# init tfstate
# init account-dns
cd ..
done
```
</details>

### 3. Delegate DNS

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

To finish up, run:

```
make root/finalize
```


<details>
<summary>Here's the pseudo code of what that roughly looks like (but automated).</summary>

```
# Docker run the image
# assume role
# init tfstate
# init accounts
```
</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 nameservers 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 need and should not be used. Instead use IAM users.
osterman marked this conversation as resolved.
Show resolved Hide resolved

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

5. 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` channe channell
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
15 changes: 15 additions & 0 deletions configs/audit.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This is a terraform configuration file

stage = "testing"
osterman marked this conversation as resolved.
Show resolved Hide resolved

# List of templates to install
templates = ["Dockerfile.child", ".gitignore", ".dockerignore", "Makefile", "conf/Makefile"]
osterman marked this conversation as resolved.
Show resolved Hide resolved

# List of terraform root modules to enable
terraform_root_modules = [
"aws/tfstate-backend",
"aws/account-dns",
"aws/chamber",
"aws/audit-cloudtrails",
osterman marked this conversation as resolved.
Show resolved Hide resolved
"aws/cloudtrails",
osterman marked this conversation as resolved.
Show resolved Hide resolved
]
14 changes: 14 additions & 0 deletions configs/corp.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# This is a terraform configuration file

stage = "corp"

# 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/cloudtrails",
osterman marked this conversation as resolved.
Show resolved Hide resolved
]
14 changes: 14 additions & 0 deletions configs/data.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# This is a terraform configuration file

stage = "data"

# 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/cloudtrails",
osterman marked this conversation as resolved.
Show resolved Hide resolved
]
14 changes: 14 additions & 0 deletions configs/dev.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# This is a terraform configuration file

stage = "dev"

# 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/cloudtrails",
osterman marked this conversation as resolved.
Show resolved Hide resolved
]
14 changes: 14 additions & 0 deletions configs/prod.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# This is a terraform configuration file

stage = "prod"

# 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/cloudtrails",
osterman marked this conversation as resolved.
Show resolved Hide resolved
]
63 changes: 63 additions & 0 deletions configs/root.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# This is a terraform configuration file

# The "apex" service discovery domain for *all* infrastructure
domain = "test.co"

# The global namespace that should be shared by all accounts
namespace = "test"

# The default region for this account
aws_region = "us-west-2"

# The docker registry that will be used for the images built (nothing will get pushed)
docker_registry = "cloudposse"

# The templates to use for this account
templates = [
"Dockerfile.root",
".gitignore",
".dockerignore",
"Makefile",
"conf/Makefile",
"conf/accounts/terraform.tfvars",
"conf/iam/terraform.tfvars",
"conf/root-dns/terraform.tfvars",
]

# Account email address format (e.g. `ops+%s@example.co`). This is not easily changed later.
account_email = "ops+%s@test.co"

# List of accounts to enable
accounts_enabled = [
"dev",
"staging",
"prod",
"testing",
"data",
"corp",
"audit",
osterman marked this conversation as resolved.
Show resolved Hide resolved
]

# Terraform Root Modules Image (don't change this unless you know what you're doing)
# https://github.com/cloudposse/terraform-root-modules
osterman marked this conversation as resolved.
Show resolved Hide resolved
terraform_root_modules_image = "cloudposse/terraform-root-modules:0.11.0"

# Geodesic Base Image (don't change this unless you know what you're doing)
# https://github.com/cloudposse/geodesic
osterman marked this conversation as resolved.
Show resolved Hide resolved
geodesic_base_image = "cloudposse/geodesic:0.46.0"

# List of terraform root modules to enable
terraform_root_modules = [
"aws/tfstate-backend",
"aws/root-dns",
"aws/root-iam",
"aws/organization",
"aws/accounts",
"aws/account-settings",
"aws/iam",
"aws/users",
"aws/cloudtrail",
osterman marked this conversation as resolved.
Show resolved Hide resolved
]

# Message of the Day
motd_url = "https://geodesic.sh/motd"
14 changes: 14 additions & 0 deletions configs/staging.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# This is a terraform configuration file

stage = "staging"

# 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/cloudtrails",
osterman marked this conversation as resolved.
Show resolved Hide resolved
]
14 changes: 14 additions & 0 deletions configs/testing.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# This is a terraform configuration file

stage = "testing"

# 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/cloudtrails",
osterman marked this conversation as resolved.
Show resolved Hide resolved
]
1 change: 1 addition & 0 deletions modules/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This directory contains modules used to create all the scaffolding. It's basically a code generator which creates directories, `Dockerfiles` and builds docker images.
Loading