Skip to content

Parameterize Environment Configuration Based on locals.tf #4

@jsandov

Description

@jsandov

Currently, there's duplication between locals.tf values and module parameters. Values defined in locals should be used consistently throughout the configuration

Current Code

locals {
  environment = "staging"
  domain_name = "staging.jdnguyen.tech"
}

module "website" {
  domain_name        = "staging.jdnguyen.tech"  # Duplicates locals.domain_name
  environment        = "staging"                 # Duplicates locals.environment
  aws_s3_bucket_name = "staging.jdnguyen.tech"  # Could use locals.domain_name
  logs_bucket_name   = "staging.logs.jdnguyen.tech"  # Could derive from locals
}

Proposed Changes

  1. Use local.environment for:

    • Environment tag
    • Module environment parameter
  2. Use local.domain_name for:

    • Module domain_name parameter
    • S3 bucket name
    • Base for logs bucket name
  3. Update provider tags to use locals

Benefits

  • Single source of truth
  • Easier environment management
  • Reduced chance of configuration errors

Implementation Note

Consider creating additional locals for derived values like logs bucket name:

locals {
  logs_bucket_name = "staging.logs.${local.domain_name}"
}

Metadata

Metadata

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions