diff --git a/.github/workflows/test-plan.yaml b/.github/workflows/test-plan.yaml index 1c30ac69..d539efa6 100644 --- a/.github/workflows/test-plan.yaml +++ b/.github/workflows/test-plan.yaml @@ -844,6 +844,28 @@ jobs: my_var="single" var_file: tests/workflows/test-plan/test.tfvars + plan_json_tfvars: + runs-on: ubuntu-24.04 + name: Plan JSON tfvars + permissions: + contents: read + pull-requests: write + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + persist-credentials: false + + - name: Plan + uses: ./terraform-plan + with: + path: tests/workflows/test-plan/vars + variables: | + my_var="single" + var_file: tests/workflows/test-plan/test.tfvars.json + plan_single_sensitive_variable: runs-on: ubuntu-24.04 name: Plan single sensitive variable diff --git a/image/actions.sh b/image/actions.sh index c193eeb8..b47b6482 100644 --- a/image/actions.sh +++ b/image/actions.sh @@ -399,10 +399,16 @@ function create-auto-tfvars() { fi local file_name="${file_path##*/}" - local name="${file_name%.tfvars}" + local extension="${file_name##*.}" - debug_log "Creating autoloading tfvars file for $file_path: zzzz-dflook-terraform-github-actions-$AUTO_TFVARS_COUNTER.$name.auto.tfvars" - cp "$file_path" "$INPUT_PATH/zzzz-dflook-terraform-github-actions-$AUTO_TFVARS_COUNTER.$name.auto.tfvars" + if [[ "$extension" == "json" ]]; then + link_name="zzzz-dflook-terraform-github-actions-$AUTO_TFVARS_COUNTER.${file_name%.json}.auto.tfvars.json" + else + link_name="zzzz-dflook-terraform-github-actions-$AUTO_TFVARS_COUNTER.${file_name%.tfvars}.auto.tfvars" + fi + + debug_log "Creating autoloading tfvars file for $file_path: $link_name" + cp "$file_path" "$INPUT_PATH/$link_name" AUTO_TFVARS_COUNTER=$(printf "%02d\n" "$((AUTO_TFVARS_COUNTER + 1))") done fi diff --git a/tests/workflows/test-plan/test.tfvars.json b/tests/workflows/test-plan/test.tfvars.json new file mode 100644 index 00000000..12a821be --- /dev/null +++ b/tests/workflows/test-plan/test.tfvars.json @@ -0,0 +1,4 @@ +{ + "my_var_from_file": "monkey", + "my_var": "this should be overridden" +}