• Stars
    star
    175
  • Rank 212,474 (Top 5 %)
  • Language HCL
  • License
    Apache License 2.0
  • Created over 5 years ago
  • Updated 17 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Example of a Truss Terraform project

terraform-layout-example

This repository is meant to serve as an example of how Truss builds out repositories for Terraform deployments. We've taken care to add as much documentation and code comments around why we do things the way they are outlined here as possible, so that newcomers to these patterns can gain some understanding of why we did things this way.

This repository is meant to be a living document -- if we change our method of doing things, we should update this repository, and engineers who have questions about why we do things that are not adequately explained or who have suggestions for improvements should feel free to file issues and/or PRs to improve the quality of the repo.

.
β”œβ”€β”€ bin
β”œβ”€β”€ modules
β”œβ”€β”€ orgname-org-root
β”‚Β Β  β”œβ”€β”€ admin-global
β”‚Β Β  └── bootstrap
└── orgname-id
β”‚Β Β  β”œβ”€β”€ admin-global
β”‚Β Β  └── bootstrap
└── orgname-infra
β”‚Β Β  β”œβ”€β”€ admin-global
β”‚Β Β  └── bootstrap
|Β Β  β”œβ”€β”€ <infra resource -- eg, atlantis>
└── orgname-<whatever>
 Β Β  β”œβ”€β”€ admin-global
Β  Β  └── bootstrap
 Β Β  β”œβ”€β”€ <stack>-global
 Β Β  └── <stack>-<environment>

Top-Level

The following files are expected to be found:

  • README.md β€”Β Should contain, at the very least, a configuration guide for accessing the necessary cloud services. For example, instructions on using aws-vault to configure your AWS credentials.
  • .envrc β€”Β Global settings across accounts. E.g., AWS_VAULT_KEYCHAIN_NAME, CHAMBER_KMS_KEY_ALIAS. See the example .envrc file.

bin

bin
β”œβ”€β”€ aws -> aws-vault-wrapper
β”œβ”€β”€ aws-vault-wrapper
β”œβ”€β”€ chamber -> aws-vault-wrapper
β”œβ”€β”€ packer -> aws-vault-wrapper
└── terraform -> aws-vault-wrapper

The bin directory typically contains an aws-vault-wrapper script with symlinks for things like aws, chamber, packer, terraform, etc. depending on the project's needs.

Additional tools and scripts needed for managing the infrastructure also go here.

Modules directory

In general, we should avoid having modules in the Terraform repository proper. We should make every effort to open source modules and add them to the Terraform Registry when we can; if the modules are specific to a project, we should put them in another repository and use them from there via the Git source method (see GitHub module sources in the Terraform docs). See the Modules directory README for a more thorough explanation.

AWS Organizations

Using AWS Organizations is highly recommended for all our projects. They provide a way to handle consolidated billing, compartmentalization of environments and permissions, and a variety of other advantages. For a full discussion of how to set up an AWS Organization properly, see these resources in the Truss Engineering Playbook:

AWS Accounts

For each AWS account, we create a directory with the name of the account alias.

The following files are expected to be found:

The bootstrap Directory

When initially creating Terraform infrastructure, we use the terraform-aws-bootstrap repository to create the resources needed to set up remote Terraform state and locking via DynamoDB. If this is an organization we started from scratch, this directory should exist (and if you are setting up this infrastructure from scratch, you should follow this pattern and the instructions in that repository to set up each account).

Once an account is bootstrapped, this directory should not be touched again unless the account is being torn down. The directory will contain the statefile for these resources, and therefore doing anything with this namespace could break Terraform for the entire account.

No resources should be defined here aside from the two S3 buckets and the DynamoDB table that the bootstrap script creates.

admin-global

The admin-global namespace is intended to hold resources that are used for overall account configuration. Resources defined here could include:

  • AWS Organization configurations (org-root account only)
  • Account level infrasec tools (eg, AWS Cloudtrail, AWS Config)
  • Non-application-specific IAM users, policies and roles
  • Non-stack-specific DNS configuration

Stack Environments

<stack>-<environment>
β”œβ”€β”€ terraform.tf
β”œβ”€β”€ providers.tf
β”œβ”€β”€ main.tf
└── variables.tf

This is where the meat of the matter is. For each stack and environment we create a directory with the name of the stack (or purpose) and environment. We try to make these distinctive so that it is easy to tell what is in each namespace at a glance.

A "stack" refers to a collection of resources serving a single purpose; if the "my-webapp" application consists of a frontend application, an API application, and a database, those three components make up a single stack.

The global environment is used for resources that might be shared between multiple individual environments. For instance, in this repo, the orgname-sandbox account holds two environments - the experimental environment and the dev environment. However, we decided we didn't need individual VPCs for those environments, so the single sandbox VPC is defined in the app-my-webapp-global namespace.

Other environments, like experimental, dev, or prod, contain all the resources for that isolated instance of the stack. Individual stacks should not interact with each other except through publically accessible methods (eg, an API interface exposed via an ALB).

The following files are expected to be found:

  • terraform.tf β€”Β Contains the terraform {} configuration block. This will set a minimum terraform version and configure the backend.
  • providers.tf β€” Contains the provider {} blocks indicating the version of each provider needed.
  • main.tf β€”Β The infrastructure code. As this file grows, consider breaking it up into smaller, well-named files. For example, a circleci.tf file could contain the IAM user, group, and policies needed for a CircleCI build to run.
  • variables.tf β€” This almost always has, at minimum, a region and environment variable set.

A Note on Variables vs Locals

You'll notice that instead of defining variables for the root module with locals, we define them in variables.tf with variable blocks. We do this because if you use locals, you cannot do a terraform import, which has caused us problems in the past. In addition, with variable declarations, you can also define the type and description for the variable, which can provide additional context for human users.

Requirements

No requirements.

Providers

No providers.

Modules

No modules.

Resources

No resources.

Inputs

No inputs.

Outputs

No outputs.

More Repositories

1

terraform-aws-config

Enables AWS Config and adds managed config rules with good defaults.
HCL
226
star
2

react-uswds

USWDS 3.0 components built in React
TypeScript
167
star
3

Engineering-Playbook

Repository of documentation on how we do Software Engineering at TrussWorks.
JavaScript
134
star
4

terraform-aws-ecs-service

Creates an ECS Service.
HCL
116
star
5

terraform-aws-wafv2

Creates a WAF using AWS WAFv2 and AWS Managed Rule Sets
HCL
101
star
6

terraform-aws-bootstrap

πŸ“ πŸ₯š Terraform for your Terraform remote state configuration
HCL
82
star
7

terraform-aws-s3-private-bucket

Creates a private, encrypted, versioned S3 bucket with good defaults.
HCL
76
star
8

terraform-aws-logs

Creates and configures an S3 bucket for storing AWS logs.
HCL
73
star
9

terraform-aws-waf

Configures an AWS Web Application Firewall.
HCL
61
star
10

terraform-aws-ses-domain

Configures a domain hosted on Route53 to work with AWS Simple Email Service (SES).
HCL
58
star
11

terraform-aws-ecs-cluster

Creates an ECS cluster backed by an Auto Scaling Group
HCL
58
star
12

terraform-aws-ou-scp

Combines AWS Organizations Service Control Policies (SCP)
HCL
50
star
13

distributed-playbook

A playbook about how we work together as a distributed team.
49
star
14

terraform-aws-cloudtrail

Creates and configures AWS CloudTrail
HCL
45
star
15

terraform-aws-s3-anti-virus

Creates and configures Anti-Virus Scanning of S3 Buckets.
HCL
38
star
16

terraform-module-template

Template repo with Terraform module basics
Makefile
23
star
17

terraform-aws-guardduty-notifications

Enables AWS GuardDuty and sends findings to an SNS topic.
HCL
22
star
18

truss-aws-tools

Assortment of AWS Lambda functions and CLI based tools for working with AWS.
Go
18
star
19

terraform-aws-cloudtrail-alarms

Provides CIS Benchmark-compliant Cloudwatch alarms for Cloudtrail events.
HCL
18
star
20

formik-to-react-hook-form-migration-guide

A guide for migrating projects to from Formik to React Hook Form
15
star
21

terraform-aws-destroy-default-vpc

Default VPC resource management for AWS Accounts
HCL
14
star
22

truss-interview

Truss software engineering interview
13
star
23

TPDWeakProxy

An NSProxy object for turning strong references into weak references.
Objective-C
12
star
24

terraform-aws-nlb-containers

Creates a Network Load Balancer (NLB) for serving an ECS backed service.
HCL
12
star
25

terraform-aws-mfa

Enforces MFA on an AWS account
HCL
11
star
26

terraform-aws-iam-sleuth

Lambda-based auditing tool for AWS Access keys
Python
10
star
27

setup-new-aws-user

Creates an MFA token and new access keys for an AWS user.
Go
10
star
28

terraform-aws-org-scp

Enables AWS Organizations Service Control Policies (SCP) with good defaults
HCL
10
star
29

terraform-aws-health-notifications

Health Notifications
HCL
9
star
30

accessibility

a11y resources and guild work
7
star
31

terraform-aws-saml-cognito

Creates AWS Cognito resources for using SAML authentication
HCL
6
star
32

pre-commit-hooks

Common pre-commit hooks
Shell
6
star
33

terraform-aws-rds-snapshot-cleaner

RDS Snapshot Cleaner
HCL
5
star
34

terraform-aws-lambda-ecs-manager

Creates a Lambda function to manage ECS services in Fargate
Python
5
star
35

terraform-aws-trusted-advisor-refresh

Trusted Advisor Refresh
HCL
5
star
36

terraform-aws-s3-file-uploads

Creates infrastructure needed to handle AWS S3 file uploads
HCL
5
star
37

dockling

Exercises for learning about docker
Go
5
star
38

terraform-aws-config-notifications

Config Notifications
HCL
5
star
39

terraform-aws-acm-cert

Creates a TLS certificate using AWS ACM for domains hosted on Route53.
HCL
5
star
40

terraform-aws-sftp

Configures an AWS SFTP Server (aka AWS Transfer Server)
HCL
5
star
41

terraform-aws-iam-ecr-ci

Creates an IAM user/group for CI to use to push images to ECR
HCL
4
star
42

trussels-guide

SCSS
4
star
43

terraform-aws-iam-user-group

Creates an IAM group with users where the group is only allowed to assume roles defined.
HCL
4
star
44

terraform-aws-route53-query-logs

Configures query logging on an existing Route53 hosted zones.
HCL
4
star
45

terraform-aws-route53-health-check

Route53 Health Check
HCL
4
star
46

terraform-aws-alb-web-containers

Creates an ALB for serving a web app.
HCL
4
star
47

terraform-aws-ecr-repo

Provides a basic ECR repository configuration for a single container image.
HCL
3
star
48

terraform-aws-rds-notifications

RDS Notifications
HCL
3
star
49

unemployment-insurance-modernization-demo

A sample repository for UI modernization sample code
TypeScript
3
star
50

terraform-aws-root-login-notifications

Root Login Notifications
HCL
3
star
51

shared-actions

Home of shared github actions
3
star
52

terraform-aws-sftp-user

SFTP User for AWS Transfer Server
HCL
3
star
53

health-checker

Website Health Check
Go
3
star
54

research-design-playbook

Research and Design Playbook https://trussworks.github.io/research-design-playbook/
SCSS
3
star
55

ecr-scan

Go
3
star
56

terraform-aws-lambda

Terraform module for creating AWS Lambda jobs with appropriate log configurations.
HCL
3
star
57

logindotgov-oidc-py

OpenID Connect (OIDC) Relying Party client in Python for login.gov.
Python
3
star
58

hello-infra-draft

Experimenting with a "Hello, World" infrastructure story
HCL
2
star
59

tls-checker

Website TLS Version Check
Go
2
star
60

TPDMapsApp

An interface to external mapping applications on iOS.
Objective-C
2
star
61

docker-nuker

A docker image to nuke an AWS account and its contents via AWS-Nuke.
Dockerfile
2
star
62

terraform-aws-sso-group

Creates AWS IAM Identity Center resources
HCL
2
star
63

find-guardduty-user

Easily identify IAM users that have triggered GuardDuty findings.
Go
2
star
64

lambda-dependabot

lambda function to rerun failed dependabot runs
Python
2
star
65

Learning-Resources

A selection of resources that Trussels have found useful for sharing mental state and aspirations
2
star
66

terraform-aws-lambda-packerjanitor

Terraform module for deploying a lambda job to clean up abandoned Packer resources
HCL
2
star
67

terraform-aws-rds-cloudwatch-logs

RDS Cloudwatch Logs
HCL
2
star
68

terraform-aws-lambda-amiclean

Terraform module for deploying AWS resources needed for amicleaner lambda
HCL
2
star
69

infra-exercise-circleci

A repo for CircleCI related exercises by InfraSec
Go
2
star
70

terraform-aws-cloudtrail-event-notifications

CloudTrail Event Notifications
HCL
2
star
71

terraform-aws-iam-cross-acct-dest

Creates an IAM role to allow cross account assumption from specified source role.
HCL
2
star
72

terraform-aws-vpc-flow-logs

Configures VPC flow logs for the given VPC.
HCL
1
star
73

terraform-aws-lambda-ecr-scan

Terraform module for deploying a lambda to parse ECR scan findings
HCL
1
star
74

go-sample-api

A sample API using Go
Go
1
star
75

golang-cli-template

Template repo with golang CLI basics
Go
1
star
76

terraform-aws-iam-cross-acct-src

Creates an IAM role to allow cross account assumption to specified destination role.
HCL
1
star
77

terraform-aws-opensearch

A module that spins up an OpenSearch cluster.
HCL
1
star
78

prereqs

A tool to check your project prerequisites so your engineers don't have to.
Shell
1
star
79

terraform-github-repo

Manage Github repos with Terraform with good defaults
HCL
1
star
80

Truss-PQVP

Truss's entry for the CA PQVP DS-AD
JavaScript
1
star
81

sesh

Open Source Session Management for Golang
Go
1
star
82

linters

Open source custom Truss linters that can be shared across projects.
1
star
83

terraform-aws-iam-keys-check

IAM Keys Check
HCL
1
star
84

terraform-aws-slack-pivotal-tracker-bot

[DEPRECATED] Terraform module for deploying slack-pivotal-tracker-bot to AWS Lambda
HCL
1
star
85

terraform-aws-nlb-tg-to-alb

Sets up a Lambda function to update an NLB's target group to point at an ALB's IPs.
Python
1
star
86

affinity-groups-slackbot

We made this slackbot to allow folks to opt into private affinity groups (read: private channels) within a Slack workspace without having to out themselves or forcing a public point of contact for the group to out themselves.
Python
1
star
87

ecs-service-logs

ecs-service-logs is used to filter JSON-formatted log lines in CloudWatch
Go
1
star
88

terraform-aws-acm-cert-akamai-dns

Creates a TLS certificate using AWS ACM for domains hosted on Akamai.
HCL
1
star
89

ecs-scaleup

This repository provides a github action which can provision a self-hosted github runner via AWS ECS/Fargate
JavaScript
1
star