9
9
FMT_CMD = "terraform fmt -check=true -write=false -recursive -diff"
10
10
INIT_CMD = "terraform init -no-color"
11
11
VALIDATE_CMD = "terraform validate -no-color"
12
- REFRESH_CMD = "terraform refresh -no-color"
13
- PLAN_CMD = "terraform plan -detailed-exitcode -refresh=false -no-color"
12
+ PLAN_CMD = "terraform plan -detailed-exitcode -no-color"
14
13
15
14
parser = argparse .ArgumentParser ()
16
15
parser .add_argument ("path" , help = "path to run terraform checks" , type = str )
@@ -44,8 +43,6 @@ class CheckResult:
44
43
fmt_output : str
45
44
validate_success : bool
46
45
validate_output : str
47
- refresh_success : bool
48
- refresh_output : str
49
46
plan_returncode : int
50
47
plan_success : bool
51
48
plan_changes : bool
@@ -75,9 +72,6 @@ def fmt_result(self) -> str:
75
72
def validate_result (self ) -> str :
76
73
return "success" if self .validate_success else "failed"
77
74
78
- def refresh_result (self ) -> str :
79
- return "success" if self .refresh_success else "failed"
80
-
81
75
def plan_result (self ) -> str :
82
76
return "success" if self .plan_success else "failed"
83
77
@@ -115,9 +109,6 @@ def check(path: str) -> CheckResult:
115
109
# Terraform validate
116
110
validate = run (VALIDATE_CMD , path )
117
111
118
- # Terraform refresh
119
- refresh = run (REFRESH_CMD , path )
120
-
121
112
# Terraform plan
122
113
plan = run (PLAN_CMD , path )
123
114
@@ -129,8 +120,6 @@ def check(path: str) -> CheckResult:
129
120
fmt_output = fmt .stdout ,
130
121
validate_success = not validate .returncode ,
131
122
validate_output = validate .stdout ,
132
- refresh_success = refresh .returncode ,
133
- refresh_output = refresh .stdout ,
134
123
# Terraform plan return code 2 = Succeeded with non-empty diff (changes present)
135
124
plan_returncode = plan .returncode ,
136
125
plan_success = plan .returncode in [0 , 2 ],
@@ -145,6 +134,21 @@ def check(path: str) -> CheckResult:
145
134
result = check (args .path )
146
135
print (f"Terraform check on { args .path } { result .check_result_msg ()} " )
147
136
137
+ # Remove refreshing messages from plan output
138
+ if args .hide_refresh :
139
+ result .plan_output = "\n " .join (
140
+ line
141
+ for line in result .plan_output .split ("\n " )
142
+ if not any (
143
+ pattern in line
144
+ for pattern in (
145
+ "Refreshing state..." ,
146
+ "Reading..." ,
147
+ "Read complete after" ,
148
+ )
149
+ )
150
+ )
151
+
148
152
if args .report :
149
153
args .report .write (
150
154
template .render (
@@ -153,7 +157,6 @@ def check(path: str) -> CheckResult:
153
157
check_result = result .check_result_msg (),
154
158
fmt_result = result .fmt_result (),
155
159
validate_result = result .validate_result (),
156
- refresh_output = "" if args .hide_refresh else result .refresh_output ,
157
160
plan_result = result .plan_result (),
158
161
plan_output = result .plan_output ,
159
162
plan_msg = result .plan_msg (),
0 commit comments