Search code examples
variablesterraformrepository

terraform get variables from a file from other repo


our organization had decided to keep the terraform configuration files as DRY as possible, by separating the variables (tfvars) into a separate repository. this gives a flexibility for the developers too, to update any changes in the application level requirements, without much looking into the tf configuration files.

I am trying to figure out, if I maintain all the application profiles in a different repository, how would I be able to use them in my configurations.

my variables repo is expected to be

repo
    app_1
       dev.profile
       stage.profile
       prod.profile
    app_2
       dev.profile
       stage.profile
       prod.profile

how would I be able to read / get file <repo_url>/app_1/DEV.profile if I have to configure app_1 in DEV environment?


Solution

  • Not specifically what you asked for, but this is targeted at making terraform config DRY: https://terragrunt.gruntwork.io/docs/features/keep-your-terraform-code-dry/

    Note that there's a terraform git provider as well: https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository_file

    That gets you as far as pulling the file from GitHub, but then you need to load the data. Not sure if you can load new vars post init within terraform. Maybe it's a 2 pass process where the 1st extracts the file/data needed? Although, I'm having a hard time seeing the advantage to using terraform for that. I feel I'm missing something obvious in GitHub provider functionality.

    I haven't played with it yet, but the combination looks promising. I'm also looking into ways to decouple config from code for IAC and other use cases.