|
6 | 6 | # terraform-root-modules [](https://travis-ci.org/cloudposse/terraform-root-modules) [](https://g.codefresh.io/pipelines/terraform-root-modules/builds) [](https://github.com/cloudposse/terraform-root-modules/releases/latest) [](https://slack.cloudposse.com) |
7 | 7 |
|
8 | 8 |
|
9 | | -This is a collection of reusable [Terraform root modules invocations](https://docs.cloudposse.com/terraform-modules/root/) for CloudPosse AWS accounts. |
| 9 | +This is a collection of reusable [Terraform "root modules" invocations](https://docs.cloudposse.com/terraform-modules/root/) for CloudPosse AWS accounts. |
10 | 10 |
|
11 | 11 | Terraform defines a "root module" as the current working directory holding the Terraform configuration files where the terraform apply or terraform get is run. |
12 | 12 |
|
@@ -37,6 +37,52 @@ It's 100% Open Source and licensed under the [APACHE2](LICENSE). |
37 | 37 |
|
38 | 38 |
|
39 | 39 |
|
| 40 | +## Introduction |
| 41 | + |
| 42 | +In this repo you'll find real-world examples of how we've implemented various common patterns using our [terraform modules](https://cpco.io/terraform-modules) for our customers. |
| 43 | + |
| 44 | +The "root modules" form the module catalog of your organization. It's from this catalog that other developers in your organization will pick and choose from anytime they need to deploy some new capability. |
| 45 | + |
| 46 | +Normally, a company should build up their own service catalog of terraform modules like this one, which is just a collection of terraform modules that capture the business logic, opinions, "best practices" and non-functional requirements of the organization. |
| 47 | +No two companies will ever have the same assembly of `terraform-root-modules`. |
| 48 | + |
| 49 | +The root modules are the most opinionated incarnations of modules that seldom translate verbatim across organizations. This is your secret sauce. We could never implement this in a sufficiently generic way without creating crazy bloat and complexity. Therefore treat the terraform-root-modules in this repository as your “starting off point” where you hardfork/diverge. |
| 50 | +These modules are very specific to how we do things in our environment, so they might not "drop in" smoothly in other environments as they make a lot of assumptions on how things are organized. |
| 51 | + |
| 52 | +A company writes their own root modules. It’s their flavor of how to leverage the [generic building blocks](https://cpco.io/terraform-modules) to achieve the specific customizations that are required without needing to write everything from the ground up because they are leveraging our general purpose modules. |
| 53 | +The idea is to write all of the [`terraform-aws-*`](https://cpco.io/terraform-modules) type modules very generically so they are easily composable inside of other modules. |
| 54 | + |
| 55 | +These `terraform-root-modules` make a lot of assumptions about how we've configured our environments. That said, they can still serve as an excellent reference for others. |
| 56 | + |
| 57 | +We recommend that you start with your clean `terraform-root-module` repo. Then start by creating a new project in there to describe the infrastructure that you want. |
| 58 | + |
| 59 | +## Best Practices |
| 60 | + |
| 61 | +* Every "root module" should include a `Makefile` that defines `init`, `plan`, and `apply` targets. |
| 62 | + This establishes a common interface for interacting with terraform without the need of a wrapper like `terragrunt`. |
| 63 | +* Never compose "root modules" inside of other root modules. If or when this is desired, then the module should be split off into a new repository and versioned independently as a standalone module. |
| 64 | + |
| 65 | +## Example Makefile |
| 66 | + |
| 67 | +Here's a good example of a `Makefile` for a terraform project: |
| 68 | + |
| 69 | +``` |
| 70 | +## Initialize terraform remote state |
| 71 | +init: |
| 72 | + [ -f .terraform/terraform.tfstate ] || init-terraform |
| 73 | +
|
| 74 | +## Clean up the project |
| 75 | +clean: |
| 76 | + rm -rf .terraform *.tfstate* |
| 77 | +
|
| 78 | +## Pass arguments through to terraform which require remote state |
| 79 | +apply console destroy graph plan output providers show: init |
| 80 | + terraform $@ |
| 81 | +
|
| 82 | +## Pass arguments through to terraform which do not require remote state |
| 83 | +get fmt validate version: |
| 84 | + terraform $@ |
| 85 | +``` |
40 | 86 |
|
41 | 87 | ## Usage |
42 | 88 |
|
@@ -86,6 +132,7 @@ Are you using this project or any of our other projects? Consider [leaving a tes |
86 | 132 |
|
87 | 133 | Check out these related projects. |
88 | 134 |
|
| 135 | +- [reference-architectures](https://github.com/cloudposse/reference-architectures) - Get up and running quickly with one of our reference architecture using our fully automated cold-start process. |
89 | 136 | - [audit.cloudposse.co](https://github.com/cloudposse/audit.cloudposse.co) - Example Terraform Reference Architecture of a Geodesic Module for an Audit Logs Organization in AWS. |
90 | 137 | - [prod.cloudposse.co](https://github.com/cloudposse/prod.cloudposse.co) - Example Terraform Reference Architecture of a Geodesic Module for a Production Organization in AWS. |
91 | 138 | - [staging.cloudposse.co](https://github.com/cloudposse/staging.cloudposse.co) - Example Terraform Reference Architecture of a Geodesic Module for a Staging Organization in AWS. |
@@ -159,7 +206,7 @@ In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow. |
159 | 206 |
|
160 | 207 | ## Copyright |
161 | 208 |
|
162 | | -Copyright © 2017-2018 [Cloud Posse, LLC](https://cpco.io/copyright) |
| 209 | +Copyright © 2017-2019 [Cloud Posse, LLC](https://cpco.io/copyright) |
163 | 210 |
|
164 | 211 |
|
165 | 212 |
|
|
0 commit comments