Skip to content

Commit 0d9fcb3

Browse files
authored
Merge pull request #107 from KeisukeYamashita/fix-error-parse-character
Fix error parse regex char for Terraform >= 0.15
2 parents 8309bd1 + 1425159 commit 0d9fcb3

File tree

2 files changed

+28
-27
lines changed

2 files changed

+28
-27
lines changed

terraform/parser.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func NewFmtParser() *FmtParser {
6262
func NewPlanParser() *PlanParser {
6363
return &PlanParser{
6464
Pass: regexp.MustCompile(`(?m)^(Plan: \d|No changes.)`),
65-
Fail: regexp.MustCompile(`(?m)^(\|\s{1})?(Error: )`),
65+
Fail: regexp.MustCompile(`(?m)^(\s{1})?(Error: )`),
6666
// "0 to destroy" should be treated as "no destroy"
6767
HasDestroy: regexp.MustCompile(`(?m)([1-9][0-9]* to destroy.)`),
6868
HasNoChanges: regexp.MustCompile(`(?m)^(No changes. Infrastructure is up-to-date.)`),
@@ -73,7 +73,7 @@ func NewPlanParser() *PlanParser {
7373
func NewApplyParser() *ApplyParser {
7474
return &ApplyParser{
7575
Pass: regexp.MustCompile(`(?m)^(Apply complete!)`),
76-
Fail: regexp.MustCompile(`(?m)^(\|\s{1})?(Error: )`),
76+
Fail: regexp.MustCompile(`(?m)^(\s{1})?(Error: )`),
7777
}
7878
}
7979

terraform/parser_test.go

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,14 @@ xxxxxxxxx
104104
xxxxxxxxx
105105
xxxxxxxxx
106106
107-
| Error: Error refreshing state: 4 error(s) occurred:
108-
|
109-
| * google_sql_database.main: 1 error(s) occurred:
110-
|
111-
| * google_sql_database.main: google_sql_database.main: Error reading SQL Database "main" in instance "main-master-instance": googleapi: Error 409: The instance or operation is not in an appropriate state to handle the request., invalidState
112-
| * google_sql_user.proxyuser_main: 1 error(s) occurred:
107+
108+
│ Error: Error refreshing state: 4 error(s) occurred:
109+
110+
│ * google_sql_database.main: 1 error(s) occurred:
111+
112+
│ * google_sql_database.main: google_sql_database.main: Error reading SQL Database "main" in instance "main-master-instance": googleapi: Error 409: The instance or operation is not in an appropriate state to handle the request., invalidState
113+
│ * google_sql_user.proxyuser_main: 1 error(s) occurred:
114+
113115
`
114116

115117
const planNoChanges = `
@@ -366,13 +368,12 @@ aws_iam_role_policy_attachment.datadog_aws_integration: Refreshing state...
366368
google_dns_managed_zone.tfnotifyapps_com: Refreshing state...
367369
google_dns_record_set.dev_tfnotifyapps_com: Refreshing state...
368370
369-
370-
| Error: Batch "project/tfnotify-jp-tfnotify-prod/services:batchEnable" for request "Enable Project Services tfnotify-jp-tfnotify-prod: map[logging.googleapis.com:{}]" returned error: failed to send enable services request: googleapi: Error 403: The caller does not have permission, forbidden
371-
|
372-
| on .terraform/modules/tfnotify-jp-tfnotify-prod/google_project_service.tf line 6, in resource "google_project_service" "gcp_api_service":
373-
| 6: resource "google_project_service" "gcp_api_service" {
374-
|
375-
|
371+
372+
│ Error: Batch "project/tfnotify-jp-tfnotify-prod/services:batchEnable" for request "Enable Project Services tfnotify-jp-tfnotify-prod: map[logging.googleapis.com:{}]" returned error: failed to send enable services request: googleapi: Error 403: The caller does not have permission, forbidden
373+
374+
│ on .terraform/modules/tfnotify-jp-tfnotify-prod/google_project_service.tf line 6, in resource "google_project_service" "gcp_api_service":
375+
│ 6: resource "google_project_service" "gcp_api_service" {
376+
376377
`
377378

378379
func TestDefaultParserParse(t *testing.T) {
@@ -493,12 +494,13 @@ func TestPlanParserParse(t *testing.T) {
493494
name: "plan ng pattern 0.15",
494495
body: planFailureResult0_15,
495496
result: ParseResult{
496-
Result: `| Error: Error refreshing state: 4 error(s) occurred:
497-
|
498-
| * google_sql_database.main: 1 error(s) occurred:
499-
|
500-
| * google_sql_database.main: google_sql_database.main: Error reading SQL Database "main" in instance "main-master-instance": googleapi: Error 409: The instance or operation is not in an appropriate state to handle the request., invalidState
501-
| * google_sql_user.proxyuser_main: 1 error(s) occurred:`,
497+
Result: `│ Error: Error refreshing state: 4 error(s) occurred:
498+
499+
│ * google_sql_database.main: 1 error(s) occurred:
500+
501+
│ * google_sql_database.main: google_sql_database.main: Error reading SQL Database "main" in instance "main-master-instance": googleapi: Error 409: The instance or operation is not in an appropriate state to handle the request., invalidState
502+
│ * google_sql_user.proxyuser_main: 1 error(s) occurred:
503+
╵`,
502504
HasAddOrUpdateOnly: false,
503505
HasDestroy: false,
504506
HasNoChanges: false,
@@ -610,12 +612,11 @@ func TestApplyParserParse(t *testing.T) {
610612
name: "apply ng pattern 0.15",
611613
body: applyFailureResult0_15,
612614
result: ParseResult{
613-
Result: `| Error: Batch "project/tfnotify-jp-tfnotify-prod/services:batchEnable" for request "Enable Project Services tfnotify-jp-tfnotify-prod: map[logging.googleapis.com:{}]" returned error: failed to send enable services request: googleapi: Error 403: The caller does not have permission, forbidden
614-
|
615-
| on .terraform/modules/tfnotify-jp-tfnotify-prod/google_project_service.tf line 6, in resource "google_project_service" "gcp_api_service":
616-
| 6: resource "google_project_service" "gcp_api_service" {
617-
|
618-
|`,
615+
Result: `│ Error: Batch "project/tfnotify-jp-tfnotify-prod/services:batchEnable" for request "Enable Project Services tfnotify-jp-tfnotify-prod: map[logging.googleapis.com:{}]" returned error: failed to send enable services request: googleapi: Error 403: The caller does not have permission, forbidden
616+
617+
│ on .terraform/modules/tfnotify-jp-tfnotify-prod/google_project_service.tf line 6, in resource "google_project_service" "gcp_api_service":
618+
│ 6: resource "google_project_service" "gcp_api_service" {
619+
╵`,
619620
ExitCode: 1,
620621
Error: nil,
621622
},

0 commit comments

Comments
 (0)