chanzuckerberg / fogg

Manage Infrastructure as Code with less pain.
https://chanzuckerberg.github.io/fogg/
MIT License
295 stars 20 forks source link

feat: allow variables to specify values in main.tf #1043

Closed jakeyheath closed 6 months ago

jakeyheath commented 6 months ago

Summary

This PR allows users to be able to change the default "locals.*" variable to something that is known ahead of time. This is handy when we want to code generate infra stacks that are very similar and we know most of the values ahead of time. Also, filters out non-existent variables on the module source. Fixes https://github.com/chanzuckerberg/fogg/issues/935

Example:

module_source:  github.com/chanzuckerberg/cztack//aws-aurora-postgres?ref=main
variables: 
  - env=var.tags.env
  - owner=var.tags.owner
  - project
  - blah # will be filtered out

Would generate:

module "aws-aurora-postgres" {
  source                = "github.com/chanzuckerberg/cztack//aws-aurora-postgres?ref=main"
  database_name         = local.database_name
  database_password     = local.database_password
  database_subnet_group = local.database_subnet_group
  database_username     = local.database_username
  env                   = var.tags.env
  owner                 = var.tags.owner
  project               = local.project
  service               = local.service
  vpc_id                = local.vpc_id

}

Test Plan

Say unittests, or list out steps to verify changes.

References

(Optional) Additional links to provide more context.