Skip to content

Commit d912440

Browse files
authored
Merge pull request #105 from KeisukeYamashita/support-terraform-0-15-or-later
Support Terraform `0.15` or later
2 parents 04274c9 + 823ebf5 commit d912440

File tree

2 files changed

+84
-8
lines changed

2 files changed

+84
-8
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)^(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)^(Error: )`),
76+
Fail: regexp.MustCompile(`(?m)^(\|\s{1})?(Error: )`),
7777
}
7878
}
7979

terraform/parser_test.go

Lines changed: 82 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ can't guarantee that exactly these actions will be performed if
8686
"terraform apply" is subsequently run.
8787
`
8888

89-
const planFailureResult = `
89+
const planFailureResult0_12 = `
9090
xxxxxxxxx
9191
xxxxxxxxx
9292
xxxxxxxxx
@@ -99,6 +99,19 @@ Error: Error refreshing state: 4 error(s) occurred:
9999
* google_sql_user.proxyuser_main: 1 error(s) occurred:
100100
`
101101

102+
const planFailureResult0_15 = `
103+
xxxxxxxxx
104+
xxxxxxxxx
105+
xxxxxxxxx
106+
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:
113+
`
114+
102115
const planNoChanges = `
103116
google_bigquery_dataset.tfnotify_echo: Refreshing state...
104117
google_project.team: Refreshing state...
@@ -300,7 +313,7 @@ google_dns_record_set.dev_tfnotifyapps_com: Refreshing state...
300313
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
301314
`
302315

303-
const applyFailureResult = `
316+
const applyFailureResult0_12 = `
304317
data.terraform_remote_state.teams_platform_development: Refreshing state...
305318
google_project.tfnotify_jp_tfnotify_prod: Refreshing state...
306319
google_project_services.tfnotify_jp_tfnotify_prod: Refreshing state...
@@ -331,6 +344,37 @@ Error: Batch "project/tfnotify-jp-tfnotify-prod/services:batchEnable" for reques
331344
332345
`
333346

347+
const applyFailureResult0_15 = `
348+
data.terraform_remote_state.teams_platform_development: Refreshing state...
349+
google_project.tfnotify_jp_tfnotify_prod: Refreshing state...
350+
google_project_services.tfnotify_jp_tfnotify_prod: Refreshing state...
351+
google_bigquery_dataset.gateway_access_log: Refreshing state...
352+
google_compute_global_address.reviews_web_tfnotify_in: Refreshing state...
353+
google_compute_global_address.chartmuseum_tfnotifyapps_com: Refreshing state...
354+
google_storage_bucket.chartmuseum: Refreshing state...
355+
google_storage_bucket.ark_tfnotify_prod: Refreshing state...
356+
google_compute_global_address.reviews_api_tfnotify_in: Refreshing state...
357+
google_logging_project_sink.gateway_access_log_bigquery_sink: Refreshing state...
358+
google_project_iam_member.gateway_access_log_bigquery_sink_writer_is_bigquery_data_editor: Refreshing state...
359+
aws_s3_bucket.terraform_backend: Refreshing state...
360+
aws_s3_bucket.teams_terraform_private_modules: Refreshing state...
361+
aws_iam_policy.datadog_aws_integration: Refreshing state...
362+
aws_iam_role.datadog_aws_integration: Refreshing state...
363+
aws_iam_user.teams_terraform: Refreshing state...
364+
aws_iam_user_policy.teams_terraform: Refreshing state...
365+
aws_iam_role_policy_attachment.datadog_aws_integration: Refreshing state...
366+
google_dns_managed_zone.tfnotifyapps_com: Refreshing state...
367+
google_dns_record_set.dev_tfnotifyapps_com: Refreshing state...
368+
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+
|
376+
`
377+
334378
func TestDefaultParserParse(t *testing.T) {
335379
testCases := []struct {
336380
body string
@@ -428,8 +472,8 @@ func TestPlanParserParse(t *testing.T) {
428472
},
429473
},
430474
{
431-
name: "plan ng pattern",
432-
body: planFailureResult,
475+
name: "plan ng pattern 0.12",
476+
body: planFailureResult0_12,
433477
result: ParseResult{
434478
Result: `Error: Error refreshing state: 4 error(s) occurred:
435479
@@ -445,6 +489,24 @@ func TestPlanParserParse(t *testing.T) {
445489
Error: nil,
446490
},
447491
},
492+
{
493+
name: "plan ng pattern 0.15",
494+
body: planFailureResult0_15,
495+
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:`,
502+
HasAddOrUpdateOnly: false,
503+
HasDestroy: false,
504+
HasNoChanges: false,
505+
HasPlanError: true,
506+
ExitCode: 1,
507+
Error: nil,
508+
},
509+
},
448510
{
449511
name: "plan no changes",
450512
body: planNoChanges,
@@ -531,8 +593,8 @@ func TestApplyParserParse(t *testing.T) {
531593
},
532594
},
533595
{
534-
name: "apply ng pattern",
535-
body: applyFailureResult,
596+
name: "apply ng pattern 0.12",
597+
body: applyFailureResult0_12,
536598
result: ParseResult{
537599
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
538600
@@ -544,6 +606,20 @@ func TestApplyParserParse(t *testing.T) {
544606
Error: nil,
545607
},
546608
},
609+
{
610+
name: "apply ng pattern 0.15",
611+
body: applyFailureResult0_15,
612+
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+
|`,
619+
ExitCode: 1,
620+
Error: nil,
621+
},
622+
},
547623
}
548624
for _, testCase := range testCases {
549625
result := NewApplyParser().Parse(testCase.body)

0 commit comments

Comments
 (0)