Skip to content

Commit

Permalink
Merge pull request #107 from KeisukeYamashita/fix-error-parse-character
Browse files Browse the repository at this point in the history
Fix error parse regex char for Terraform >= 0.15
  • Loading branch information
drlau authored Jan 21, 2022
2 parents 8309bd1 + 1425159 commit 0d9fcb3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 27 deletions.
4 changes: 2 additions & 2 deletions terraform/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func NewFmtParser() *FmtParser {
func NewPlanParser() *PlanParser {
return &PlanParser{
Pass: regexp.MustCompile(`(?m)^(Plan: \d|No changes.)`),
Fail: regexp.MustCompile(`(?m)^(\|\s{1})?(Error: )`),
Fail: regexp.MustCompile(`(?m)^(\s{1})?(Error: )`),
// "0 to destroy" should be treated as "no destroy"
HasDestroy: regexp.MustCompile(`(?m)([1-9][0-9]* to destroy.)`),
HasNoChanges: regexp.MustCompile(`(?m)^(No changes. Infrastructure is up-to-date.)`),
Expand All @@ -73,7 +73,7 @@ func NewPlanParser() *PlanParser {
func NewApplyParser() *ApplyParser {
return &ApplyParser{
Pass: regexp.MustCompile(`(?m)^(Apply complete!)`),
Fail: regexp.MustCompile(`(?m)^(\|\s{1})?(Error: )`),
Fail: regexp.MustCompile(`(?m)^(\s{1})?(Error: )`),
}
}

Expand Down
51 changes: 26 additions & 25 deletions terraform/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,14 @@ xxxxxxxxx
xxxxxxxxx
xxxxxxxxx
| Error: Error refreshing state: 4 error(s) occurred:
|
| * google_sql_database.main: 1 error(s) occurred:
|
| * 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
| * google_sql_user.proxyuser_main: 1 error(s) occurred:
│ Error: Error refreshing state: 4 error(s) occurred:
│ * google_sql_database.main: 1 error(s) occurred:
│ * 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
│ * google_sql_user.proxyuser_main: 1 error(s) occurred:
`

const planNoChanges = `
Expand Down Expand Up @@ -366,13 +368,12 @@ aws_iam_role_policy_attachment.datadog_aws_integration: Refreshing state...
google_dns_managed_zone.tfnotifyapps_com: Refreshing state...
google_dns_record_set.dev_tfnotifyapps_com: Refreshing state...
| 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
|
| on .terraform/modules/tfnotify-jp-tfnotify-prod/google_project_service.tf line 6, in resource "google_project_service" "gcp_api_service":
| 6: resource "google_project_service" "gcp_api_service" {
|
|
│ 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
│ on .terraform/modules/tfnotify-jp-tfnotify-prod/google_project_service.tf line 6, in resource "google_project_service" "gcp_api_service":
│ 6: resource "google_project_service" "gcp_api_service" {
`

func TestDefaultParserParse(t *testing.T) {
Expand Down Expand Up @@ -493,12 +494,13 @@ func TestPlanParserParse(t *testing.T) {
name: "plan ng pattern 0.15",
body: planFailureResult0_15,
result: ParseResult{
Result: `| Error: Error refreshing state: 4 error(s) occurred:
|
| * google_sql_database.main: 1 error(s) occurred:
|
| * 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
| * google_sql_user.proxyuser_main: 1 error(s) occurred:`,
Result: `│ Error: Error refreshing state: 4 error(s) occurred:
│ * google_sql_database.main: 1 error(s) occurred:
│ * 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
│ * google_sql_user.proxyuser_main: 1 error(s) occurred:
╵`,
HasAddOrUpdateOnly: false,
HasDestroy: false,
HasNoChanges: false,
Expand Down Expand Up @@ -610,12 +612,11 @@ func TestApplyParserParse(t *testing.T) {
name: "apply ng pattern 0.15",
body: applyFailureResult0_15,
result: ParseResult{
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
|
| on .terraform/modules/tfnotify-jp-tfnotify-prod/google_project_service.tf line 6, in resource "google_project_service" "gcp_api_service":
| 6: resource "google_project_service" "gcp_api_service" {
|
|`,
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
│ on .terraform/modules/tfnotify-jp-tfnotify-prod/google_project_service.tf line 6, in resource "google_project_service" "gcp_api_service":
│ 6: resource "google_project_service" "gcp_api_service" {
╵`,
ExitCode: 1,
Error: nil,
},
Expand Down

0 comments on commit 0d9fcb3

Please sign in to comment.