|
| 1 | +name: Test terraform-refresh |
| 2 | + |
| 3 | +on: |
| 4 | + - pull_request |
| 5 | + |
| 6 | +permissions: |
| 7 | + contents: read |
| 8 | + |
| 9 | +jobs: |
| 10 | + refresh: |
| 11 | + runs-on: ubuntu-24.04 |
| 12 | + name: Refresh |
| 13 | + permissions: |
| 14 | + contents: read |
| 15 | + pull-requests: write |
| 16 | + env: |
| 17 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 18 | + steps: |
| 19 | + - name: Checkout |
| 20 | + uses: actions/checkout@v4 |
| 21 | + with: |
| 22 | + persist-credentials: false |
| 23 | + |
| 24 | + - name: Apply |
| 25 | + uses: ./terraform-apply |
| 26 | + with: |
| 27 | + path: tests/workflows/test-refresh |
| 28 | + auto_approve: true |
| 29 | + |
| 30 | + - name: Check no changes |
| 31 | + uses: ./terraform-check |
| 32 | + with: |
| 33 | + path: tests/workflows/test-refresh |
| 34 | + |
| 35 | + - name: Make untracked changes |
| 36 | + run: | |
| 37 | + echo "qewasdasd" > tests/workflows/test-refresh/test |
| 38 | + echo "cxvbbxcbb" > tests/workflows/test-refresh/test2 |
| 39 | + echo "tyuityuiy" > tests/workflows/test-refresh/test3 |
| 40 | +
|
| 41 | + - name: Create a normal plan |
| 42 | + uses: ./terraform-plan |
| 43 | + id: plan-with-refresh |
| 44 | + with: |
| 45 | + add_github_comment: false |
| 46 | + path: tests/workflows/test-refresh |
| 47 | + |
| 48 | + - name: Check normal plan picks up changes |
| 49 | + env: |
| 50 | + CHANGES: ${{ steps.plan-with-refresh.outputs.changes }} |
| 51 | + TO_ADD: ${{ steps.plan-with-refresh.outputs.to_add }} |
| 52 | + run: | |
| 53 | + if [[ "$CHANGES" != "true" ]]; then |
| 54 | + echo "::error:: Plan did not have changes" |
| 55 | + exit 1 |
| 56 | + fi |
| 57 | +
|
| 58 | + if [[ "$TO_ADD" != "3" ]]; then |
| 59 | + echo "::error:: Wrong number of resources to add" |
| 60 | + exit 1 |
| 61 | + fi |
| 62 | +
|
| 63 | + - name: Create a non-refresh plan |
| 64 | + uses: ./terraform-plan |
| 65 | + id: plan-without-refresh |
| 66 | + with: |
| 67 | + add_github_comment: false |
| 68 | + label: test-refresh refresh non-refresh |
| 69 | + path: tests/workflows/test-refresh |
| 70 | + refresh: false |
| 71 | + |
| 72 | + - name: Check non-refresh plan doesn't pick up changes |
| 73 | + env: |
| 74 | + CHANGES: ${{ steps.plan-without-refresh.outputs.changes }} |
| 75 | + TO_ADD: ${{ steps.plan-without-refresh.outputs.to_add }} |
| 76 | + run: | |
| 77 | + if [[ "$CHANGES" != "false" ]]; then |
| 78 | + echo "::error:: Plan has changes" |
| 79 | + exit 1 |
| 80 | + fi |
| 81 | +
|
| 82 | + - name: Targeted refresh |
| 83 | + uses: ./terraform-refresh |
| 84 | + with: |
| 85 | + path: tests/workflows/test-refresh |
| 86 | + target: | |
| 87 | + local_file.one |
| 88 | +
|
| 89 | + - name: Plan after targeted refresh |
| 90 | + uses: ./terraform-plan |
| 91 | + id: plan-after-targeted-refresh |
| 92 | + with: |
| 93 | + path: tests/workflows/test-refresh |
| 94 | + refresh: false |
| 95 | + |
| 96 | + - name: Check plan after targeted refresh |
| 97 | + env: |
| 98 | + CHANGES: ${{ steps.plan-after-targeted-refresh.outputs.changes }} |
| 99 | + TO_ADD: ${{ steps.plan-after-targeted-refresh.outputs.to_add }} |
| 100 | + run: | |
| 101 | + if [[ "$CHANGES" != "true" ]]; then |
| 102 | + echo "::error:: Plan did not have changes" |
| 103 | + exit 1 |
| 104 | + fi |
| 105 | +
|
| 106 | + if [[ "$TO_ADD" != "1" ]]; then |
| 107 | + echo "::error:: Wrong number of resources to add" |
| 108 | + exit 1 |
| 109 | + fi |
| 110 | +
|
| 111 | + - name: Apply plan after targeted refresh |
| 112 | + uses: ./terraform-apply |
| 113 | + id: apply |
| 114 | + continue-on-error: true |
| 115 | + with: |
| 116 | + path: tests/workflows/test-refresh |
| 117 | + |
| 118 | + - name: Check failed to apply |
| 119 | + env: |
| 120 | + OUTCOME: ${{ steps.apply.outcome }} |
| 121 | + FAILURE_REASON: ${{ steps.apply.outputs.failure-reason }} |
| 122 | + run: | |
| 123 | + if [[ "$OUTCOME" != "failure" ]]; then |
| 124 | + echo "Apply did not fail correctly" |
| 125 | + exit 1 |
| 126 | + fi |
| 127 | +
|
| 128 | + if [[ "$FAILURE_REASON" != "plan-changed" ]]; then |
| 129 | + echo "::error:: failure-reason not set correctly" |
| 130 | + exit 1 |
| 131 | + fi |
| 132 | +
|
| 133 | + - name: Apply without refresh |
| 134 | + uses: ./terraform-apply |
| 135 | + with: |
| 136 | + path: tests/workflows/test-refresh |
| 137 | + refresh: false |
| 138 | + |
| 139 | + - name: Create another normal plan |
| 140 | + uses: ./terraform-plan |
| 141 | + id: plan-with-refresh-after-apply |
| 142 | + with: |
| 143 | + add_github_comment: false |
| 144 | + path: tests/workflows/test-refresh |
| 145 | + |
| 146 | + - name: Check normal plan picks up changes |
| 147 | + env: |
| 148 | + CHANGES: ${{ steps.plan-with-refresh-after-apply.outputs.changes }} |
| 149 | + TO_ADD: ${{ steps.plan-with-refresh-after-apply.outputs.to_add }} |
| 150 | + run: | |
| 151 | + if [[ "$CHANGES" != "true" ]]; then |
| 152 | + echo "::error:: Plan did not have changes" |
| 153 | + exit 1 |
| 154 | + fi |
| 155 | +
|
| 156 | + if [[ "$TO_ADD" != "2" ]]; then |
| 157 | + echo "::error:: Wrong number of resources to add" |
| 158 | + exit 1 |
| 159 | + fi |
| 160 | +
|
| 161 | + - name: Full refresh |
| 162 | + uses: ./terraform-refresh |
| 163 | + with: |
| 164 | + path: tests/workflows/test-refresh |
| 165 | + |
| 166 | + - name: Plan after full refresh |
| 167 | + uses: ./terraform-plan |
| 168 | + id: plan-after-full-refresh |
| 169 | + with: |
| 170 | + add_github_comment: false |
| 171 | + path: tests/workflows/test-refresh |
| 172 | + refresh: false |
| 173 | + |
| 174 | + - name: Check plan after full refresh |
| 175 | + env: |
| 176 | + CHANGES: ${{ steps.plan-after-full-refresh.outputs.changes }} |
| 177 | + TO_ADD: ${{ steps.plan-after-full-refresh.outputs.to_add }} |
| 178 | + run: | |
| 179 | + if [[ "$CHANGES" != "true" ]]; then |
| 180 | + echo "::error:: Plan did not have changes" |
| 181 | + exit 1 |
| 182 | + fi |
| 183 | +
|
| 184 | + if [[ "$TO_ADD" != "2" ]]; then |
| 185 | + echo "::error:: Wrong number of resources to add" |
| 186 | + exit 1 |
| 187 | + fi |
0 commit comments