Skip to content

Commit

Permalink
Document Terraform state styleguide (#1297)
Browse files Browse the repository at this point in the history
* Document Terraform state styleguide

* Set @sourcegraph/distribution as CODEOWNERS for terraform style
  • Loading branch information
pecigonzalo committed Jul 29, 2020
1 parent f4676c1 commit fcef7b5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Expand Up @@ -31,6 +31,7 @@
/handbook/engineering/web @sourcegraph/web
/handbook/engineering/languages/go.md @sourcegraph/cloud
/handbook/engineering/languages/typescript.md @sourcegraph/web
/handbook/engineering/languages/terraform.md @sourcegraph/distribution
/handbook/marketing @sourcegraph/marketing

/handbook/engineering/adding_ping_data.md @ebrodymoore @dadlerj
30 changes: 30 additions & 0 deletions handbook/engineering/languages/terraform.md
Expand Up @@ -2,6 +2,36 @@

- General Terraform [styleguide](https://www.terraform.io/docs/configuration/style.html)

## State

State must be stored using a [GCS Terraform state backend](https://www.terraform.io/docs/backends/types/gcs.html).

Example configuration
```
terraform {
required_version = "0.12.26"
backend "gcs" {
bucket = "sourcegraph-tfstate"
prefix = "infrastructure/dns"
}
}
```

### State for state buckets

Because we need to create state buckets as code, we also need to store the state of the code that creates the state bucket. Given this code rarely changes and that moving it to be stored in a remote location creates a chicken and egg situation, we will store state bucket creation's state in Git.

### Bucket

State for all Sourcegraph resources is stored in [sourcegraph-tfstate bucket](https://github.com/sourcegraph/infrastructure/tree/master/terraform-state).

Managed instances resources will be stored on a per customer bucket following the pattern: `sourcegraph-managed-${NAME}`.

### Prefix

State for different pieces of infrastructure require separate state files. To facilitate matching state to resources and code, we will use the following pattern: `${REPOSITORY_NAME}/${INFRASTRUCTURE_NAME}`.

## Formatting

- Format all code using `terraform fmt`
Expand Down

0 comments on commit fcef7b5

Please sign in to comment.