question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

delivery: Explicit environment in terraform configuration

See original GitHub issue

Background

The current Terraform implementation has two root modules: ops and app. For each application environment, we expect the developer to remove local state and re-run with a different project ID.

Proposal

Switch to a more conventional model, where our reusable modules are in one directory, and our “root modules” are in an environments directory. Each root module maps to a dedicated environment. ops is special because it’s handles environment-spanning infrastructure, such as Artifact Registry.

.
├── modules
│   ├── app
│   └── delivery
└── environments
    ├── ops
    ├── stage
    └── prod

Once this is done, we add a new environment by copying stage or prod and tweaking. (note, we have some special case logic in a Cloud Build stage to prod handoff.)

In setup.sh, we might setup this terraform structure like so:

gsutil mb gs://${OPS_PROJECT}-tf-state
for d in {'ops','stage','prod'}
do
  pushd $d
  terraform init \
    --backend-config "bucket=${OPS_PROJECT}-tf-state"
    --backend-config "prefix=${d}"
  terraform apply
  popd
done

Terraform-based operations we want to run across environments later could use a script like so:

for d in {'ops','stage','prod'}
do
  terraform -chdir=$d output -raw project_number
done

Problems this will solve

  • This will simplify our state management, which currently doesn’t have a way to simultaneously track multiple app environments
  • This will remove the naming confusion of an app root module containing an application supporting module
  • We will have an approach to minimal duplication of terraform config for environments that still allows environment-based special casing

Additional context

This plan was initially outlined during the prototyping of the last refactor: https://github.com/GoogleCloudPlatform/emblem/tree/main/experimental/flex-env-tf#limitations-of-this-approach

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
graysidecommented, Jun 10, 2022

Everything that can be done on this issue has been completed. There are several decision records to be added related to terraform structure and usage, but they can be pursued in a follow-up. Thank you!

1reaction
ace-ncommented, May 31, 2022

This may break/complicate #347 when merged; we should make sure [we have enough time] to deconflict these two changes.

We’ll also need to propagate #418 into this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configure the Terraform Execution Environment
The Terraform execution environment includes the layout of the folders and Terraform configuration files required to build the multitier network topology.
Read more >
Terraform With Multiple Environments - Codurance
Terraform codifies cloud APIs into declarative configuration files. Most of the time we deploy the infrastructure in multiple environments.
Read more >
Best practices for using Terraform | Google Cloud
This document provides guidelines and recommendations for effective development with Terraform across multiple team members and work streams.
Read more >
Secure Terraform Delivery Pipeline – Best Practices. Part 1/2.
The goal is to create a process that allows a user to introduce changes into a cloud environment without having explicit permissions for...
Read more >
Secure Terraform Delivery Pipeline – Best Practices - DZone
The goal is to create a process that allows a user to introduce changes into a cloud environment without having explicit permissions for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found