Skip to content

Commit bcc0e13

Browse files
authored
Merge pull request #392 from dflook/auto-json
Ensure json var-files have a .json extension
2 parents 78e37da + 0cfb10b commit bcc0e13

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

.github/workflows/test-plan.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,28 @@ jobs:
844844
my_var="single"
845845
var_file: tests/workflows/test-plan/test.tfvars
846846

847+
plan_json_tfvars:
848+
runs-on: ubuntu-24.04
849+
name: Plan JSON tfvars
850+
permissions:
851+
contents: read
852+
pull-requests: write
853+
env:
854+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
855+
steps:
856+
- name: Checkout
857+
uses: actions/checkout@v4
858+
with:
859+
persist-credentials: false
860+
861+
- name: Plan
862+
uses: ./terraform-plan
863+
with:
864+
path: tests/workflows/test-plan/vars
865+
variables: |
866+
my_var="single"
867+
var_file: tests/workflows/test-plan/test.tfvars.json
868+
847869
plan_single_sensitive_variable:
848870
runs-on: ubuntu-24.04
849871
name: Plan single sensitive variable

image/actions.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,10 +399,16 @@ function create-auto-tfvars() {
399399
fi
400400

401401
local file_name="${file_path##*/}"
402-
local name="${file_name%.tfvars}"
402+
local extension="${file_name##*.}"
403403

404-
debug_log "Creating autoloading tfvars file for $file_path: zzzz-dflook-terraform-github-actions-$AUTO_TFVARS_COUNTER.$name.auto.tfvars"
405-
cp "$file_path" "$INPUT_PATH/zzzz-dflook-terraform-github-actions-$AUTO_TFVARS_COUNTER.$name.auto.tfvars"
404+
if [[ "$extension" == "json" ]]; then
405+
link_name="zzzz-dflook-terraform-github-actions-$AUTO_TFVARS_COUNTER.${file_name%.json}.auto.tfvars.json"
406+
else
407+
link_name="zzzz-dflook-terraform-github-actions-$AUTO_TFVARS_COUNTER.${file_name%.tfvars}.auto.tfvars"
408+
fi
409+
410+
debug_log "Creating autoloading tfvars file for $file_path: $link_name"
411+
cp "$file_path" "$INPUT_PATH/$link_name"
406412
AUTO_TFVARS_COUNTER=$(printf "%02d\n" "$((AUTO_TFVARS_COUNTER + 1))")
407413
done
408414
fi
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"my_var_from_file": "monkey",
3+
"my_var": "this should be overridden"
4+
}

0 commit comments

Comments
 (0)