0xDones / tfgen

Terraform code generator for consistent codebase and DRY
GNU General Public License v3.0
81 stars 12 forks source link

[FEATURE] Add a target to root relative path variable #11

Open aleckramarczyk opened 3 months ago

aleckramarczyk commented 3 months ago

This would allow you to consistently reference the path to a directory as a variable. For instance, being able to reference a modules directory.

---
root_file: true
vars:
  tenant: default
  aws_region: us-west-1
template_files:
  _backend.tf: |
    terraform {
      backend "s3" {
        bucket         = "my-state-bucket"
        dynamodb_table = "my-lock-table"
        encrypt        = true
        key            = "{{ .Vars.tfgen_state_key }}/terraform.tfstate"
        region         = "{{ .Vars.aws_region }}"
        role_arn       = "arn:aws:iam::{{ .Vars.aws_account_id }}:role/terraformRole"
      }
    }
  _provider.tf: |
    provider "aws" {
      region = "{{ .Vars.aws_region }}"
      allowed_account_ids = [
        "{{ .Vars.aws_account_id }}"
      ]
    }
  _vars.tf: |
    variable "env" {
      type    = string
      default = "{{ .Vars.env }}"
    }
    variable "modules-directory" {
      type = string
      default = "{{ .Vars.target_to_root_relative_path }}/modules"
    }
0xDones commented 3 months ago

Hi @aleckramarczyk , what would be your usecase for this one, since using variables for the module's source isn't allowed?