Skip to content
upload-cloud

GitHub Action

GitHub Action coping Terraform variables across modules

v0.2 Latest version

GitHub Action coping Terraform variables across modules

upload-cloud

GitHub Action coping Terraform variables across modules

GitHub Action automatically copying variables' definitions from a single file to many modules

Installation

Copy and paste the following snippet into your .yml file.

              

- name: GitHub Action coping Terraform variables across modules

uses: devops-infra/[email protected]

Learn more about this action in devops-infra/action-terraform-copy-vars

Choose a version

GitHub Action coping Terraform variables across modules

GitHub Action automatically copying variables' definitions from a single file to many modules.

Dockerized as devopsinfra/action-terraform-copy-vars.

Features:

  • It's main use will be everywhere where Terraform is used with more than one module in a monorepo.
  • Reads file defined with all_vars_file and will use whole definitions of variables from it.
  • For every module matching dirs_with_modules will search files matching files_with_vars and replace matching variables from all_vars_file.
  • To not loose the changes combine with my other action devops-infra/action-commit-push.

Badge swag

Master branch Other branches
GitHub repo GitHub code size in bytes GitHub last commit GitHub license
DockerHub Docker version Image size Docker Pulls

Reference

    - name: Fail on different veriables' definitions
      uses: devops-infra/[email protected]
      with:
        fail_on_changes: true
Input Variable Required Default Description
dirs_with_modules No terraform Comma separated list of directory prefixes with modules.
files_with_vars No variables.tf Comma separated list of files containing variables in directories matching dirs_with_modules.
all_vars_file No all-variables.tf Name of a file containing base definitions of all variables.
fail_on_missing No false Whether action should fail if all_vars_file is missing some definitions from modules.

Examples

Fail action if not all variables in variables.tf in terragrunt subdirectories match their definitions in all-variables.tf.

name: Check Terraform variables
on:
  push
jobs:
  terraform-copy-vars:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout repoistory
      uses: actions/checkout@v2
    - name: Fail on different veriables' definitions
      uses: devops-infra/[email protected]
      with:
        fail_on_changes: true

Copy variables definitions from all-variables.tf to all variables.tf in modules subdirectories and commit updated files back to the repository using my other action devops-infra/action-commit-push.

name: Copy Terraform variables accross modules
on:
  push
jobs:
  terraform-copy-vars:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout repoistory
      uses: actions/checkout@v2
    - name: Update Terraform variables
      uses: devops-infra/[email protected]
      with:
        dirs_with_modules: modules
        files_with_vars: variables.tf
        all_vars_file: all-variables.tf
    - name: Commit changes to repo
      uses: devops-infra/action-commit-push@master
      with:
        github_token: ${{ secrets.GITHUB_TOKEN }}
        commit_prefix: "[AUTO-VARIABLES]"