Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Terraform >= 0.15 or later plan output only changes #109

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion terraform/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.)`),
Expand Down
100 changes: 100 additions & 0 deletions terraform/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,80 @@ can't guarantee that exactly these actions will be performed if
"terraform apply" is subsequently run.
`

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.

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"
Comment on lines +113 to +118
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've never seen terraform <0.15 output this. Is this some flag that is passed with terraform plan that makes it output this? I've only seen the "no changes" string.

Copy link
Contributor Author

@KeisukeYamashita KeisukeYamashita Feb 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@drlau Thank you for your review, can you check this issue, please? #108

I can reproduce with v0.14.10 🙏


------------------------------------------------------------------------

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 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.

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
Expand Down Expand Up @@ -459,6 +533,32 @@ func TestPlanParserParse(t *testing.T) {
Error: nil,
},
},
{
name: "plan output changes only pattern 0.12",
body: planOnlyOutputChangesSuccessResult0_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: planOnlyOutputChangesSuccessResult0_15,
result: ParseResult{
Result: "Changes to Outputs:",
HasAddOrUpdateOnly: true,
HasDestroy: false,
HasNoChanges: false,
HasPlanError: false,
ExitCode: 0,
Error: nil,
},
},
{
name: "no stdin",
body: "",
Expand Down