Skip to content

Terraform

Vojtech Mašek edited this page Aug 19, 2019 · 2 revisions

Terraform is tool for managing infrastructure as a code. We should aim to have all infrastructure as a code. This ensures that the infrastructure can be replicated and it will prevent human mistakes. Infrastructure as a code can be stored in repository and all changes can be reviewed before they are applied.

Providers

Terraform Provider is a set of resources that can be declared in a code. Common used providers @FlowUp:

Modules

Modules are used within Terraform to create reusable parts of the infrastructure. Modules wrap different resources from different providers.

Testing

Modules can be tested with Terraform testing framework Terratest. Right now, Terratest supports only AWS, GCP and Kubernetes APIs.

Best practices

Remote state

Each Terraform configuration should include configuration of remote state. Remote state is needed to make sure that everyone who is responsible for infrastructure uses the same state. Otherwise, this can lead to inconsistencies between environment and state file.

State can be defined by adding this to main.tf:

terraform {
  backend "gcs" {
    bucket = "flowup-terraform-state" // Name of the bucket
    prefix = "staging/egress-nat"     // Directory used (should be the same as the path in infra repo)
  }
}
Clone this wiki locally