Terraform setup
Ansible vs terraform
We use terraform to manage resources in GCP projects (CloudSQL, Firewall, Compute Engine, Load Balancers etc).
We use ansible to * configure postgres users /Â databases * configure services running inside Compute Engines
When in doubt, first check terraform if there is configuration for it. If yes, then use terraform.
On a longer run, we probably could let application repos define the application project content in .tf file, thus automating the set up for applications.
Install
Terraform configuration files
Terraform configuration files are stored in github in 'adi-infra' repository. Clone repository to your own device.
State files
State files are stored in adi-terraform-state bucket in attracs-devops -project. Bucket is versioned, 5 last version stored.
Terraform installation
On your device, follow Terraform installation procedure:
[
Install | Terraform | HashiCorp Developer
Explore Terraform product documentation, tutorials, and examples.
https://developer.hashicorp.com/terraform/downloads
](https://developer.hashicorp.com/terraform/downloads)
Offline-instructions (may be outdated)
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
sudo apt-get update && sudo apt-get install terraform
Usage
Terraform is set up project based, so each project has it's own state files. Refer to existing projects for configuration and usage of variables etc. There also ready made templates that can be utilized.
Always pull latest changes from repository before making changes.
Refer to terraform documentation how to make changes, but basically: * Pull latest changes from adi-infra * make changes to terraform configuration (use nightly project first) * run 'terraform plan' to review the changes. Verify resources to be changed and if they cause any interrupts (for example some of the CloudSQL flags require instance restart) * run 'terraform apply'
To Do: As we start using ${terraform.workspace} and [terraform.workspace] more, we can probably forgo the environment-based terraform files for Terraform workspaces.