Skip to content

Commit c8d5fd5

Browse files
authored
Merge pull request #139 from dflook/remote-output
Add support for a remote backend using a fixed workspace name
2 parents 01ee72f + 33db26f commit c8d5fd5

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

.github/workflows/test-remote.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,40 @@ jobs:
7171
exit 1
7272
fi
7373
74+
- name: Get outputs
75+
uses: ./terraform-output
76+
id: output
77+
with:
78+
path: tests/terraform-cloud
79+
workspace: ${{ github.head_ref }}-1
80+
backend_config: "token=${{ secrets.TF_API_TOKEN }}"
81+
82+
- name: Verify auto_apply terraform outputs with workspace prefix
83+
run: |
84+
if [[ "${{ steps.output.outputs.default }}" != "default" ]]; then
85+
echo "::error:: Variables not set correctly"
86+
exit 1
87+
fi
88+
89+
- name: Setup terraform with workspace name
90+
run: |
91+
mkdir fixed-workspace-name
92+
sed -e 's/prefix.*/name = "github-actions-${{ github.head_ref }}-1"/' tests/terraform-cloud/main.tf > fixed-workspace-name/main.tf
93+
94+
- name: Get outputs
95+
uses: ./terraform-output
96+
id: name-output
97+
with:
98+
path: fixed-workspace-name
99+
backend_config: "token=${{ secrets.TF_API_TOKEN }}"
100+
101+
- name: Verify auto_apply terraform outputs with workspace name
102+
run: |
103+
if [[ "${{ steps.name-output.outputs.default }}" != "default" ]]; then
104+
echo "::error:: Variables not set correctly"
105+
exit 1
106+
fi
107+
74108
- name: Check no changes
75109
uses: ./terraform-check
76110
with:

image/actions.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,14 @@ function select-workspace() {
198198

199199
if [[ -s "$STEP_TMP_DIR/workspace_select" ]]; then
200200
start_group "Selecting workspace"
201-
cat "$STEP_TMP_DIR/workspace_select"
201+
202+
if [[ $WORKSPACE_EXIT -ne 0 ]] && grep -q "workspaces not supported" "$STEP_TMP_DIR/workspace_select" && [[ $INPUT_WORKSPACE == "default" ]]; then
203+
echo "The full name of a remote workspace is set by the terraform configuration, selecting a different one is not supported"
204+
WORKSPACE_EXIT=0
205+
else
206+
cat "$STEP_TMP_DIR/workspace_select"
207+
fi
208+
202209
end_group
203210
fi
204211

0 commit comments

Comments
 (0)