Skip to content

Commit b723c6a

Browse files
committed
Better detect the plan summary line
This is so we can ignore any warning text that follows. If a plan contains import operations, the line is different.
1 parent 6111533 commit b723c6a

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed

image/src/github_pr_comment/cmp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def remove_warnings(plan: str) -> str:
2323

2424
plan_lines.append(line)
2525

26-
if re.match(r'Plan: \d+ to add, \d+ to change, \d+ to destroy', line):
26+
if re.match(r'Plan: \d+ to \S+', line):
2727
plan_summary_reached = True
2828

2929
return '\n'.join(plan_lines).strip()

tests/github_pr_comment/test_cmp.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,80 @@ def test_remove_unchanged_attributes():
2121

2222
assert remove_unchanged_attributes(plan) == expected
2323

24+
25+
def test_remove_warnings_with_import():
26+
plan = '''
27+
Terraform used the selected providers to generate the following execution
28+
plan. Resource actions are indicated with the following symbols:
29+
+ create
30+
31+
Terraform will perform the following actions:
32+
33+
# random_string.count[0] will be created
34+
+ resource "random_string" "count" {
35+
+ id = (known after apply)
36+
+ length = 5
37+
+ lower = true
38+
+ min_lower = 0
39+
+ min_numeric = 0
40+
+ min_special = 0
41+
+ min_upper = 0
42+
+ number = true
43+
+ numeric = true
44+
+ result = (known after apply)
45+
+ special = false
46+
+ upper = true
47+
}
48+
49+
Plan: 26 to import, 1 to add, 0 to change, 0 to destroy.
50+
51+
Changes to Outputs:
52+
+ count = (known after apply)
53+
54+
Warning: Resource targeting is in effect
55+
56+
You are creating a plan with the -target option, which means that the result
57+
of this plan may not represent all of the changes requested by the current
58+
configuration.
59+
60+
The -target option is not for routine use, and is provided only for
61+
exceptional situations such as recovering from errors or mistakes, or when
62+
Terraform specifically suggests to use it as part of an error message.
63+
'''
64+
65+
expected = '''
66+
Terraform used the selected providers to generate the following execution
67+
plan. Resource actions are indicated with the following symbols:
68+
+ create
69+
70+
Terraform will perform the following actions:
71+
72+
# random_string.count[0] will be created
73+
+ resource "random_string" "count" {
74+
+ id = (known after apply)
75+
+ length = 5
76+
+ lower = true
77+
+ min_lower = 0
78+
+ min_numeric = 0
79+
+ min_special = 0
80+
+ min_upper = 0
81+
+ number = true
82+
+ numeric = true
83+
+ result = (known after apply)
84+
+ special = false
85+
+ upper = true
86+
}
87+
88+
Plan: 26 to import, 1 to add, 0 to change, 0 to destroy.
89+
90+
Changes to Outputs:
91+
+ count = (known after apply)
92+
93+
'''
94+
95+
assert remove_warnings(plan).strip() == expected.strip()
96+
97+
2498
def test_remove_warnings():
2599
plan = '''
26100
Terraform used the selected providers to generate the following execution

0 commit comments

Comments
 (0)