Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Terraform locals instead of variables to manage application configs and environment variables #199

Open
longnd opened this issue Jun 29, 2023 · 0 comments

Comments

@longnd
Copy link
Contributor

longnd commented Jun 29, 2023

Why

In previous projects, we have extensively used Terraform variables to manage application configurations and environment variables. However, this creates a dependency between the infrastructure repository and Terraform Cloud, and we lose the ability to audit the changes made, i.e. the values of Terraform Cloud variables are mistakenly changed.

Recently, we adopted a new approach for the same purpose by using Terraform locals in a project (example implementation. We should update the infrastructure-template to follow this approach so that it can be used in future projects.

Example, instead of using a variable (and the value is controlled by a Terraform cloud variable) to hold the RDS instance type

variables "rds_instance_type" {
   type = string
}

it should be controlled by a local value instead

current_db_config = local.db_config[var.environment]
db_config = {
  staging = {
    rds_instance_type  = "db.t3.small"
  }

  prod = {
    rds_instance_type  = "db.t3.large"
  }
}

Who Benefits?

  • The project squad of the new client projects have a clean way to manage the application configs & environment variables.
  • The client as the infra-repo will be handed over to them; maintaining it will be easier.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant