Skip to content

Commit a51ca44

Browse files
authored
Merge pull request #193 from dflook/only_moved
Fix compacting plans with only moved resources
2 parents 3972b2e + fef02c6 commit a51ca44

File tree

5 files changed

+41
-7
lines changed

5 files changed

+41
-7
lines changed

.github/workflows/test-apply.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ jobs:
122122
exit 1
123123
fi
124124
125-
if [[ $(jq -r .format_version "${{ steps.apply.outputs.json_plan_path }}") != "1.0" ]]; then
125+
cat "${{ steps.apply.outputs.json_plan_path }}"
126+
if [[ $(jq -r .format_version "${{ steps.apply.outputs.json_plan_path }}") != "1.1" ]]; then
126127
echo "::error:: json_plan_path not set correctly"
127128
exit 1
128129
fi
@@ -226,7 +227,7 @@ jobs:
226227
exit 1
227228
fi
228229
229-
if [[ $(jq -r .format_version "${{ steps.second-apply.outputs.json_plan_path }}") != "1.0" ]]; then
230+
if [[ $(jq -r .format_version "${{ steps.second-apply.outputs.json_plan_path }}") != "1.1" ]]; then
230231
echo "::error:: json_plan_path not set correctly"
231232
exit 1
232233
fi
@@ -623,7 +624,8 @@ jobs:
623624
exit 1
624625
fi
625626
626-
if [[ $(jq -r .format_version "${{ steps.apply.outputs.json_plan_path }}") != "1.0" ]]; then
627+
cat "${{ steps.apply.outputs.json_plan_path }}"
628+
if [[ $(jq -r .format_version "${{ steps.apply.outputs.json_plan_path }}") != "1.1" ]]; then
627629
echo "::error:: json_plan_path not set correctly"
628630
exit 1
629631
fi

.github/workflows/test-plan.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
fi
3030
3131
cat '${{ steps.plan.outputs.json_plan_path }}'
32-
if [[ $(jq -r .format_version "${{ steps.plan.outputs.json_plan_path }}") != "1.0" ]]; then
32+
if [[ $(jq -r .format_version "${{ steps.plan.outputs.json_plan_path }}") != "1.1" ]]; then
3333
echo "::error:: json_plan_path not set correctly"
3434
exit 1
3535
fi
@@ -69,7 +69,7 @@ jobs:
6969
- name: Verify outputs
7070
run: |
7171
cat '${{ steps.plan.outputs.json_plan_path }}'
72-
if [[ $(jq -r .format_version "${{ steps.plan.outputs.json_plan_path }}") != "1.0" ]]; then
72+
if [[ $(jq -r .format_version "${{ steps.plan.outputs.json_plan_path }}") != "1.1" ]]; then
7373
echo "::error:: json_plan_path not set correctly"
7474
exit 1
7575
fi

.github/workflows/test-version.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ jobs:
398398

399399
- name: Check the version
400400
run: |
401-
if [[ "${{ steps.terraform-version.outputs.terraform }}" != *"1.1"* ]]; then
401+
if [[ "${{ steps.terraform-version.outputs.terraform }}" != *"1.2"* ]]; then
402402
echo "::error:: Latest version was not used"
403403
exit 1
404404
fi

image/tools/compact_plan.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ def compact_plan(input):
1414
line.startswith('An execution plan has been generated and is shown below') or
1515
line.startswith('No changes') or
1616
line.startswith('Error') or
17-
line.startswith('Changes to Outputs:')
17+
line.startswith('Changes to Outputs:') or
18+
line.startswith('Terraform will perform the following actions:')
1819
):
1920
plan = True
2021

tests/test_compact_plan.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,37 @@ def test_plan_refresh_changes_15():
510510
output = '\n'.join(compact_plan(input.splitlines()))
511511
assert output == expected_output
512512

513+
def test_plan_refresh_changes_16():
514+
input = """
515+
random_string.my_string: Refreshing state... [id=Iyh3jLKc]
516+
517+
Terraform will perform the following actions:
518+
519+
# random_string.your_string has moved to random_string.my_string
520+
resource "random_string" "my_string" {
521+
id = "Iyh3jLKc"
522+
length = 8
523+
# (8 unchanged attributes hidden)
524+
}
525+
526+
Plan: 0 to add, 0 to change, 0 to destroy.
527+
"""
528+
529+
expected_output = """Terraform will perform the following actions:
530+
531+
# random_string.your_string has moved to random_string.my_string
532+
resource "random_string" "my_string" {
533+
id = "Iyh3jLKc"
534+
length = 8
535+
# (8 unchanged attributes hidden)
536+
}
537+
538+
Plan: 0 to add, 0 to change, 0 to destroy.
539+
"""
540+
541+
output = '\n'.join(compact_plan(input.splitlines()))
542+
assert output == expected_output
543+
513544
def test_error_11():
514545
input = """
515546
Error: random_string.my_string: length: cannot parse '' as int: strconv.ParseInt: parsing "ten": invalid syntax

0 commit comments

Comments
 (0)