-
-
Notifications
You must be signed in to change notification settings - Fork 160
115 lines (99 loc) · 3.36 KB
/
test-new-workspace.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
name: Test terraform-new/destroy-workspace
on:
- pull_request
permissions:
contents: read
jobs:
workspace_management:
runs-on: ubuntu-24.04
name: Workspace management
strategy:
fail-fast: false
matrix:
tf_version: ['~> 0.12.0', '~> 0.13.0', '~> 0.14.0', '~> 1.0.0', '~> 1.1.0']
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Setup remote backend
run: |
cat >tests/workflows/test-new-workspace/backend.tf <<EOF
terraform {
backend "s3" {
bucket = "terraform-github-actions"
key = "terraform-new-workspace-${{ matrix.tf_version }}"
region = "eu-west-2"
}
required_version = "${{ matrix.tf_version }}"
}
EOF
- name: Create first workspace
uses: ./terraform-new-workspace
with:
path: tests/workflows/test-new-workspace
workspace: test-workspace
- name: Create first workspace again
uses: ./terraform-new-workspace
with:
path: tests/workflows/test-new-workspace
workspace: test-workspace
- name: Apply in first workspace
uses: ./terraform-apply
with:
path: tests/workflows/test-new-workspace
workspace: test-workspace
variables: my_string="hello"
auto_approve: true
- name: Create a second workspace
uses: ./terraform-new-workspace
with:
path: tests/workflows/test-new-workspace
workspace: ${{ github.head_ref }}
- name: Apply in second workspace
uses: ./terraform-apply
with:
path: tests/workflows/test-new-workspace
workspace: ${{ github.head_ref }}
variables: my_string="world"
auto_approve: true
- name: Get first workspace outputs
uses: ./terraform-output
id: first
with:
path: tests/workflows/test-new-workspace
workspace: test-workspace
- name: Get second workspace outputs
uses: ./terraform-output
id: second
with:
path: tests/workflows/test-new-workspace
workspace: ${{ github.head_ref }}
- name: Verify outputs
env:
FIRST_MY_STRING: ${{ steps.first.outputs.my_string }}
SECOND_MY_STRING: ${{ steps.second.outputs.my_string }}
run: |
if [[ "$FIRST_MY_STRING" != "hello" ]]; then
echo "::error:: output my_string not set correctly for first workspace"
exit 1
fi
if [[ "$SECOND_MY_STRING" != "world" ]]; then
echo "::error:: output my_string not set correctly for second workspace"
exit 1
fi
- name: Destroy first workspace
uses: ./terraform-destroy-workspace
with:
path: tests/workflows/test-new-workspace
workspace: test-workspace
variables: my_string="hello"
- name: Destroy second workspace
uses: ./terraform-destroy-workspace
with:
path: tests/workflows/test-new-workspace
workspace: ${{ github.head_ref }}
variables: my_string="world"