File tree Expand file tree Collapse file tree 3 files changed +36
-3
lines changed Expand file tree Collapse file tree 3 files changed +36
-3
lines changed Original file line number Diff line number Diff line change 11import hashlib
22import json
33import os
4+ import re
45import sys
56from pathlib import Path
67from typing import (NewType , Optional , cast )
@@ -108,18 +109,26 @@ def format_classic_description(action_inputs: PlanPrInputs) -> str:
108109def create_summary (plan : Plan ) -> Optional [str ]:
109110 summary = None
110111
112+ to_move = 0
113+
111114 for line in plan .splitlines ():
112115 if line .startswith ('No changes' ) or line .startswith ('Error' ):
113116 return line
114117
118+ if re .match (r' # \S+ has moved to \S+$' , line ):
119+ to_move += 1
120+
115121 if line .startswith ('Plan:' ):
116122 summary = line
117123
124+ if to_move and 'move' not in summary :
125+ summary = summary .rstrip ('.' ) + f', { to_move } to move.'
126+
118127 if line .startswith ('Changes to Outputs' ):
119128 if summary :
120129 return summary + ' Changes to Outputs.'
121130 else :
122- return 'Changes to Outputs'
131+ return 'Changes to Outputs. '
123132
124133 return summary
125134
Original file line number Diff line number Diff line change @@ -158,3 +158,27 @@ def test_summary_unknown():
158158This is not anything like terraform output we know. We don't want to generate a summary for this.
159159"""
160160 assert create_summary (plan ) is None
161+
162+ def test_summary_move_only ():
163+ plan = """Terraform will perform the following actions:
164+
165+ # random_string.your_string has moved to random_string.my_string
166+ resource "random_string" "my_string" {
167+ id = "Iyh3jLKc"
168+ length = 8
169+ # (8 unchanged attributes hidden)
170+ }
171+
172+ # random_string.blah_string has moved to random_string.my_string2
173+ resource "random_string" "my_string2" {
174+ id = "Iyh3jLKc"
175+ length = 8
176+ # (8 unchanged attributes hidden)
177+ }
178+
179+ Plan: 0 to add, 0 to change, 0 to destroy.
180+ """
181+
182+ expected = "Plan: 0 to add, 0 to change, 0 to destroy, 2 to move."
183+
184+ assert create_summary (plan ) == expected
Original file line number Diff line number Diff line change @@ -226,7 +226,7 @@ def test_plan_15():
226226 output = '\n ' .join (compact_plan (input .splitlines ()))
227227 assert output == expected_output
228228
229- def test_plan_refresh_on_changes_11 ():
229+ def test_plan_refresh_no_changes_11 ():
230230 input = """
231231Refreshing Terraform state in-memory prior to plan...
232232The refreshed state will be used to calculate this plan, but will not be
@@ -510,7 +510,7 @@ 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 ():
513+ def test_plan_move_only ():
514514 input = """
515515random_string.my_string: Refreshing state... [id=Iyh3jLKc]
516516
You can’t perform that action at this time.
0 commit comments