Skip to content

Conversation

@p0tr3c
Copy link
Contributor

@p0tr3c p0tr3c commented Jun 27, 2021

What this PR does / why we need it:

Terraform cloudprovider failed to execute with the latest terraform stable version 1.0.0. This PR addresses the issues caused by changes to command line flags, and

The directory parameter '.' has been changed to -chdir and is optional. This PR removes the flag from the command
The -lock=false is no longer valid parameter for init command. This PR removes the flag from the command.
I've tested the changed parameters with following terraform versions:

  • 1.0.0
  • 0.15.5
  • 0.14.11
  • 0.13.7

Parsing plan with no changes failed in latest terraform version. This is most likely due to subtle changes to the text output.

image

This PR proposes change to detect explicit exit status to parse only plans with changes. This method should be less error prone when the string output of terraform changes.

Which issue(s) this PR fixes:

Does this PR introduce a user-facing change?:

NONE

p0tr3c added 2 commits June 27, 2021 22:32
Terraform directory parameter has to be
specified via optional -chdir flag.
This commit removed the explicit '.' which
is invalid since terraform 1.0.0
Terraform provides detailed status code
which can be used in plan commands to determine
if plan contains any changes. This commit adds
explicit status check to before sending the
results for parsing
@pipecd-bot
Copy link
Collaborator

CLA

Welcome @p0tr3c!

Thanks for your contributing. It looks like this is your first PR to this repository 🎉. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). Please read the CLA and leave a /cla sign comment on this pull request to sign the CLA.

@p0tr3c
Copy link
Contributor Author

p0tr3c commented Jun 27, 2021

/cla sign

@pipecd-bot
Copy link
Collaborator

CLA

Thank you for signing the CLA. Your signing has been successfully committed.


func GetExitCode(err error) int {
if err == nil {
return 0
Copy link
Member

Choose a reason for hiding this comment

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

I wonder which value is better to set here. 0 or 2.
Because we are using the -detailed-exitcode flag, so with the new version of terraform, we expect err will not be nill, right?
So IMO, when err is nil, returning 2 is safer than 0.
How do you think about this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

even with -detailed-exitcode the err will be nil if the plan commands succeeds and produces plan with no changes.

-detailed-exitcode only gives us ability to differentiate between actual plan error (status code 1) and plan witch changes (status code 2).

So I would keep this as is

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for your explaination.
I got your point. 💯

@nghialv
Copy link
Member

nghialv commented Jun 28, 2021

@p0tr3c Hello.

Thank you for your pull request. We really appreciate this.
I have just left a comment. Please take a look.

@p0tr3c p0tr3c requested a review from nghialv June 28, 2021 18:56
@nghialv nghialv changed the title fix: obsolete terraform flags Fix: obsolete terraform flags Jun 29, 2021
@nghialv
Copy link
Member

nghialv commented Jun 29, 2021

/lgtm

@nghialv
Copy link
Member

nghialv commented Jun 29, 2021

/trigger presubmits

@pipecd-bot
Copy link
Collaborator

TRIGGER

@nghialv: Your requested presubmits has been scheduled in response to this comment.

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 32.44%. This pull request decreases coverage by -0.01%.

File Function Base Head Diff
pkg/app/piped/cloudprovider/terraform/terraform.go GetExitCode -- 0.00% +0.00%
pkg/app/piped/cloudprovider/terraform/terraform.go Terraform.Init 0.00% 0.00% +0.00%
pkg/app/piped/cloudprovider/terraform/terraform.go Terraform.Plan 0.00% 0.00% +0.00%
pkg/app/piped/cloudprovider/terraform/terraform.go Terraform.Apply 0.00% 0.00% +0.00%

@khanhtc1202
Copy link
Member

Thx
/approve

@pipecd-bot
Copy link
Collaborator

APPROVE

This pull request is APPROVED by khanhtc1202.

Approvers can cancel the approval by writing /approve cancel in a comment. Any additional commits also will change this pull request to be not-approved.

@pipecd-bot pipecd-bot merged commit a9abe24 into pipe-cd:master Jun 29, 2021
@nghialv
Copy link
Member

nghialv commented Jul 8, 2021

@p0tr3c Hello, I just want to say that your patch has been released recently.
You can try it with the latest version v0.11.0.
Hope that you have a good experience with PipeCD.

Btw, if you are using terraform our new feature Plan Preview may be useful too.

Thanks.

@p0tr3c
Copy link
Contributor Author

p0tr3c commented Jul 11, 2021

Yeah, really like the idea of PipeCD. Hopefully will find some more time to contribute.

@nghialv
Copy link
Member

nghialv commented Jul 11, 2021

It's great to hear that.
Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants