From f3cbdc26224e5cc3e3efae66881729dceddba8c9 Mon Sep 17 00:00:00 2001 From: KeisukeYamashita <19yamashita15@gmail.com> Date: Thu, 20 Jan 2022 23:11:39 +0900 Subject: [PATCH 1/3] Add testcase for 0.15 plan and apply error Signed-off-by: KeisukeYamashita <19yamashita15@gmail.com> --- terraform/parser_test.go | 84 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 80 insertions(+), 4 deletions(-) diff --git a/terraform/parser_test.go b/terraform/parser_test.go index 6f13626..e4f1c56 100644 --- a/terraform/parser_test.go +++ b/terraform/parser_test.go @@ -86,7 +86,7 @@ can't guarantee that exactly these actions will be performed if "terraform apply" is subsequently run. ` -const planFailureResult = ` +const planFailureResult0_12 = ` xxxxxxxxx xxxxxxxxx xxxxxxxxx @@ -99,6 +99,19 @@ Error: Error refreshing state: 4 error(s) occurred: * google_sql_user.proxyuser_main: 1 error(s) occurred: ` +const planFailureResult0_15 = ` +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: +` + const planNoChanges = ` google_bigquery_dataset.tfnotify_echo: Refreshing state... google_project.team: Refreshing state... @@ -300,7 +313,7 @@ google_dns_record_set.dev_tfnotifyapps_com: Refreshing state... Apply complete! Resources: 0 added, 0 changed, 0 destroyed. ` -const applyFailureResult = ` +const applyFailureResult0_12 = ` data.terraform_remote_state.teams_platform_development: Refreshing state... google_project.tfnotify_jp_tfnotify_prod: Refreshing state... google_project_services.tfnotify_jp_tfnotify_prod: Refreshing state... @@ -331,6 +344,37 @@ Error: Batch "project/tfnotify-jp-tfnotify-prod/services:batchEnable" for reques ` +const applyFailureResult0_15 = ` +data.terraform_remote_state.teams_platform_development: Refreshing state... +google_project.tfnotify_jp_tfnotify_prod: Refreshing state... +google_project_services.tfnotify_jp_tfnotify_prod: Refreshing state... +google_bigquery_dataset.gateway_access_log: Refreshing state... +google_compute_global_address.reviews_web_tfnotify_in: Refreshing state... +google_compute_global_address.chartmuseum_tfnotifyapps_com: Refreshing state... +google_storage_bucket.chartmuseum: Refreshing state... +google_storage_bucket.ark_tfnotify_prod: Refreshing state... +google_compute_global_address.reviews_api_tfnotify_in: Refreshing state... +google_logging_project_sink.gateway_access_log_bigquery_sink: Refreshing state... +google_project_iam_member.gateway_access_log_bigquery_sink_writer_is_bigquery_data_editor: Refreshing state... +aws_s3_bucket.terraform_backend: Refreshing state... +aws_s3_bucket.teams_terraform_private_modules: Refreshing state... +aws_iam_policy.datadog_aws_integration: Refreshing state... +aws_iam_role.datadog_aws_integration: Refreshing state... +aws_iam_user.teams_terraform: Refreshing state... +aws_iam_user_policy.teams_terraform: Refreshing state... +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" { +| +| +` + func TestDefaultParserParse(t *testing.T) { testCases := []struct { body string @@ -429,7 +473,7 @@ func TestPlanParserParse(t *testing.T) { }, { name: "plan ng pattern", - body: planFailureResult, + body: planFailureResult0_12, result: ParseResult{ Result: `Error: Error refreshing state: 4 error(s) occurred: @@ -445,6 +489,24 @@ func TestPlanParserParse(t *testing.T) { Error: nil, }, }, + { + name: "plan ng pattern", + 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:`, + HasAddOrUpdateOnly: false, + HasDestroy: false, + HasNoChanges: false, + HasPlanError: true, + ExitCode: 1, + Error: nil, + }, + }, { name: "plan no changes", body: planNoChanges, @@ -532,13 +594,27 @@ func TestApplyParserParse(t *testing.T) { }, { name: "apply ng pattern", - body: applyFailureResult, + body: applyFailureResult0_12, 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" { +`, + ExitCode: 1, + Error: nil, + }, + }, + { + name: "apply ng pattern", + 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" { +| `, ExitCode: 1, Error: nil, From b364d7a5c33a27dece162b50a56d0402e273d013 Mon Sep 17 00:00:00 2001 From: KeisukeYamashita <19yamashita15@gmail.com> Date: Thu, 20 Jan 2022 23:14:06 +0900 Subject: [PATCH 2/3] Update commet for testname Signed-off-by: KeisukeYamashita <19yamashita15@gmail.com> --- terraform/parser_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/terraform/parser_test.go b/terraform/parser_test.go index e4f1c56..f42c13e 100644 --- a/terraform/parser_test.go +++ b/terraform/parser_test.go @@ -472,7 +472,7 @@ func TestPlanParserParse(t *testing.T) { }, }, { - name: "plan ng pattern", + name: "plan ng pattern 0.12", body: planFailureResult0_12, result: ParseResult{ Result: `Error: Error refreshing state: 4 error(s) occurred: @@ -490,7 +490,7 @@ func TestPlanParserParse(t *testing.T) { }, }, { - name: "plan ng pattern", + name: "plan ng pattern 0.15", body: planFailureResult0_15, result: ParseResult{ Result: `| Error: Error refreshing state: 4 error(s) occurred: @@ -593,7 +593,7 @@ func TestApplyParserParse(t *testing.T) { }, }, { - name: "apply ng pattern", + name: "apply ng pattern 0.12", body: applyFailureResult0_12, 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 @@ -607,7 +607,7 @@ func TestApplyParserParse(t *testing.T) { }, }, { - name: "apply ng pattern", + 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 From 823ebf5810321a00c1ec68a48c36fd2352aeae7d Mon Sep 17 00:00:00 2001 From: KeisukeYamashita <19yamashita15@gmail.com> Date: Thu, 20 Jan 2022 23:25:18 +0900 Subject: [PATCH 3/3] Update regex for fail parser Signed-off-by: KeisukeYamashita <19yamashita15@gmail.com> --- terraform/parser.go | 4 ++-- terraform/parser_test.go | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/terraform/parser.go b/terraform/parser.go index 80687dc..d86c1c3 100644 --- a/terraform/parser.go +++ b/terraform/parser.go @@ -62,7 +62,7 @@ func NewFmtParser() *FmtParser { func NewPlanParser() *PlanParser { return &PlanParser{ Pass: regexp.MustCompile(`(?m)^(Plan: \d|No changes.)`), - Fail: regexp.MustCompile(`(?m)^(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.)`), @@ -73,7 +73,7 @@ func NewPlanParser() *PlanParser { func NewApplyParser() *ApplyParser { return &ApplyParser{ Pass: regexp.MustCompile(`(?m)^(Apply complete!)`), - Fail: regexp.MustCompile(`(?m)^(Error: )`), + Fail: regexp.MustCompile(`(?m)^(\|\s{1})?(Error: )`), } } diff --git a/terraform/parser_test.go b/terraform/parser_test.go index f42c13e..9ece0b9 100644 --- a/terraform/parser_test.go +++ b/terraform/parser_test.go @@ -368,7 +368,7 @@ 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" { | @@ -612,10 +612,10 @@ func TestApplyParserParse(t *testing.T) { 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" { +| 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, },