Skip to content

Commit d09edbf

Browse files
authored
Merge pull request #118 from dflook/tf_1_0_10
Add tests for 1.0.10 workspace changes
2 parents 03739d0 + 9ac3689 commit d09edbf

File tree

3 files changed

+106
-1
lines changed

3 files changed

+106
-1
lines changed

.github/workflows/test-new-workspace.yaml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,3 +254,87 @@ jobs:
254254
path: tests/new-workspace/remote_14
255255
workspace: ${{ github.head_ref }}
256256
variables: my_string="world"
257+
258+
create_workspace_1_0_10:
259+
runs-on: ubuntu-latest
260+
name: Workspace tests 1.0.10
261+
env:
262+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
263+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
264+
steps:
265+
- name: Checkout
266+
uses: actions/checkout@v2
267+
268+
- name: Create first workspace
269+
uses: ./terraform-new-workspace
270+
with:
271+
path: tests/new-workspace/remote_1_0_10
272+
workspace: test-workspace
273+
274+
- name: Create first workspace again
275+
uses: ./terraform-new-workspace
276+
with:
277+
path: tests/new-workspace/remote_1_0_10
278+
workspace: test-workspace
279+
280+
- name: Apply in first workspace
281+
uses: ./terraform-apply
282+
with:
283+
path: tests/new-workspace/remote_1_0_10
284+
workspace: test-workspace
285+
variables: my_string="hello"
286+
auto_approve: true
287+
288+
- name: Create a second workspace
289+
uses: ./terraform-new-workspace
290+
with:
291+
path: tests/new-workspace/remote_1_0_10
292+
workspace: ${{ github.head_ref }}
293+
294+
- name: Apply in second workspace
295+
uses: ./terraform-apply
296+
with:
297+
path: tests/new-workspace/remote_1_0_10
298+
workspace: ${{ github.head_ref }}
299+
variables: my_string="world"
300+
auto_approve: true
301+
302+
- name: Get first workspace outputs
303+
uses: ./terraform-output
304+
id: first_1_0_10
305+
with:
306+
path: tests/new-workspace/remote_1_0_10
307+
workspace: test-workspace
308+
309+
- name: Get second workspace outputs
310+
uses: ./terraform-output
311+
id: second_1_0_10
312+
with:
313+
path: tests/new-workspace/remote_1_0_10
314+
workspace: ${{ github.head_ref }}
315+
316+
- name: Verify outputs
317+
run: |
318+
if [[ "${{ steps.first_1_0_10.outputs.my_string }}" != "hello" ]]; then
319+
echo "::error:: output my_string not set correctly for first workspace"
320+
exit 1
321+
fi
322+
323+
if [[ "${{ steps.second_1_0_10.outputs.my_string }}" != "world" ]]; then
324+
echo "::error:: output my_string not set correctly for second workspace"
325+
exit 1
326+
fi
327+
328+
- name: Destroy first workspace
329+
uses: ./terraform-destroy-workspace
330+
with:
331+
path: tests/new-workspace/remote_1_0_10
332+
workspace: test-workspace
333+
variables: my_string="hello"
334+
335+
- name: Destroy second workspace
336+
uses: ./terraform-destroy-workspace
337+
with:
338+
path: tests/new-workspace/remote_1_0_10
339+
workspace: ${{ github.head_ref }}
340+
variables: my_string="world"

image/actions.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ function init-backend() {
164164
if [[ $INIT_EXIT -eq 0 ]]; then
165165
cat "$STEP_TMP_DIR/terraform_init.stderr" >&2
166166
else
167-
if grep -q "No existing workspaces." "$STEP_TMP_DIR/terraform_init.stderr" || grep -q "Failed to select workspace" "$STEP_TMP_DIR/terraform_init.stderr"; then
167+
if grep -q "No existing workspaces." "$STEP_TMP_DIR/terraform_init.stderr" || grep -q "Failed to select workspace" "$STEP_TMP_DIR/terraform_init.stderr" || grep -q "Currently selected workspace.*does not exist" "$STEP_TMP_DIR/terraform_init.stderr"; then
168168
# Couldn't select workspace, but we don't really care.
169169
# select-workspace will give a better error if the workspace is required to exist
170170
:
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
resource "random_string" "my_string" {
2+
length = 5
3+
}
4+
5+
variable "my_string" {
6+
type = string
7+
}
8+
9+
output "my_string" {
10+
value = var.my_string
11+
}
12+
13+
terraform {
14+
backend "s3" {
15+
bucket = "terraform-github-actions"
16+
key = "terraform-new-workspace-1-0-10"
17+
region = "eu-west-2"
18+
}
19+
20+
required_version = "~> 1.0.10"
21+
}

0 commit comments

Comments
 (0)