From 879269010bb02ddf8075cce0a925de5379487e38 Mon Sep 17 00:00:00 2001 From: KeisukeYamashita <19yamashita15@gmail.com> Date: Tue, 1 Feb 2022 16:53:11 +0900 Subject: [PATCH 1/2] Support outputs changes only plan Signed-off-by: KeisukeYamashita <19yamashita15@gmail.com> --- terraform/parser.go | 2 +- terraform/parser_test.go | 100 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+), 1 deletion(-) diff --git a/terraform/parser.go b/terraform/parser.go index 9fd5f52..938afc4 100644 --- a/terraform/parser.go +++ b/terraform/parser.go @@ -61,7 +61,7 @@ func NewFmtParser() *FmtParser { // NewPlanParser is PlanParser initialized with its Regexp func NewPlanParser() *PlanParser { return &PlanParser{ - Pass: regexp.MustCompile(`(?m)^(Plan: \d|No changes.)`), + Pass: regexp.MustCompile(`(?m)^((Plan: \d|No changes.)|(Changes to Outputs:))`), 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.)`), diff --git a/terraform/parser_test.go b/terraform/parser_test.go index 605300e..b5d5e7c 100644 --- a/terraform/parser_test.go +++ b/terraform/parser_test.go @@ -86,6 +86,80 @@ can't guarantee that exactly these actions will be performed if "terraform apply" is subsequently run. ` +const planOutputChangesOnlySuccessResult0_12 = ` +Refreshing Terraform state in-memory prior to plan... +The refreshed state will be used to calculate this plan, but will not be +persisted to local or remote state storage. + +data.terraform_remote_state.teams_platform_development: Refreshing state... +google_project.my_project: Refreshing state... +aws_iam_policy.datadog_aws_integration: Refreshing state... +aws_iam_user.teams_terraform: Refreshing state... +aws_iam_role.datadog_aws_integration: Refreshing state... +google_project_services.my_project: Refreshing state... +google_bigquery_dataset.gateway_access_log: Refreshing state... +aws_iam_role_policy_attachment.datadog_aws_integration: 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... +google_dns_managed_zone.tfnotifyapps_com: Refreshing state... +google_dns_record_set.dev_tfnotifyapps_com: Refreshing state... + +------------------------------------------------------------------------ + +An execution plan has been generated and is shown below. +Resource actions are indicated with the following symbols: + + create + +Terraform will perform the following actions: + +Plan: 0 to add, 0 to change, 0 to destroy. + +Changes to Outputs: + + aws_instance_name = "my-instance" + +------------------------------------------------------------------------ + +Note: You didn't specify an "-out" parameter to save this plan, so Terraform +can't guarantee that exactly these actions will be performed if +"terraform apply" is subsequently run. +` + +const planOutputChangesOnlySuccessResult0_15 = ` +Refreshing Terraform state in-memory prior to plan... +The refreshed state will be used to calculate this plan, but will not be +persisted to local or remote state storage. + +data.terraform_remote_state.teams_platform_development: Refreshing state... +google_project.my_project: Refreshing state... +aws_iam_policy.datadog_aws_integration: Refreshing state... +aws_iam_user.teams_terraform: Refreshing state... +aws_iam_role.datadog_aws_integration: Refreshing state... +google_project_services.my_project: Refreshing state... +google_bigquery_dataset.gateway_access_log: Refreshing state... +aws_iam_role_policy_attachment.datadog_aws_integration: 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... +google_dns_managed_zone.tfnotifyapps_com: Refreshing state... +google_dns_record_set.dev_tfnotifyapps_com: Refreshing state... + +------------------------------------------------------------------------ + +An execution plan has been generated and is shown below. +Resource actions are indicated with the following symbols: + + create + +Terraform will perform the following actions: + +Changes to Outputs: + + aws_instance_name = "my-instance" + +------------------------------------------------------------------------ + +Note: You didn't specify an "-out" parameter to save this plan, so Terraform +can't guarantee that exactly these actions will be performed if +"terraform apply" is subsequently run. +` + const planFailureResult0_12 = ` xxxxxxxxx xxxxxxxxx @@ -459,6 +533,32 @@ func TestPlanParserParse(t *testing.T) { Error: nil, }, }, + { + name: "plan output changes only pattern 0.12", + body: planOutputChangesOnlySuccessResult0_12, + result: ParseResult{ + Result: "Plan: 0 to add, 0 to change, 0 to destroy.", + HasAddOrUpdateOnly: true, + HasDestroy: false, + HasNoChanges: false, + HasPlanError: false, + ExitCode: 0, + Error: nil, + }, + }, + { + name: "plan output changes only pattern 0.15", + body: planOutputChangesOnlySuccessResult0_15, + result: ParseResult{ + Result: "Changes to Outputs:", + HasAddOrUpdateOnly: true, + HasDestroy: false, + HasNoChanges: false, + HasPlanError: false, + ExitCode: 0, + Error: nil, + }, + }, { name: "no stdin", body: "", From 163a31ef794a6d65ae8d2bc8211b56b46c40f30e Mon Sep 17 00:00:00 2001 From: KeisukeYamashita <19yamashita15@gmail.com> Date: Tue, 1 Feb 2022 16:53:49 +0900 Subject: [PATCH 2/2] Fix variable name 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 b5d5e7c..3ff0c79 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 planOutputChangesOnlySuccessResult0_12 = ` +const planOnlyOutputChangesSuccessResult0_12 = ` Refreshing Terraform state in-memory prior to plan... The refreshed state will be used to calculate this plan, but will not be persisted to local or remote state storage. @@ -124,7 +124,7 @@ can't guarantee that exactly these actions will be performed if "terraform apply" is subsequently run. ` -const planOutputChangesOnlySuccessResult0_15 = ` +const planOnlyOutputChangesSuccessResult0_15 = ` Refreshing Terraform state in-memory prior to plan... The refreshed state will be used to calculate this plan, but will not be persisted to local or remote state storage. @@ -535,7 +535,7 @@ func TestPlanParserParse(t *testing.T) { }, { name: "plan output changes only pattern 0.12", - body: planOutputChangesOnlySuccessResult0_12, + body: planOnlyOutputChangesSuccessResult0_12, result: ParseResult{ Result: "Plan: 0 to add, 0 to change, 0 to destroy.", HasAddOrUpdateOnly: true, @@ -548,7 +548,7 @@ func TestPlanParserParse(t *testing.T) { }, { name: "plan output changes only pattern 0.15", - body: planOutputChangesOnlySuccessResult0_15, + body: planOnlyOutputChangesSuccessResult0_15, result: ParseResult{ Result: "Changes to Outputs:", HasAddOrUpdateOnly: true,