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

parse outputs changes #4

Open
rvoitenko opened this issue Feb 4, 2024 · 6 comments · Fixed by #6 · May be fixed by #7
Open

parse outputs changes #4

rvoitenko opened this issue Feb 4, 2024 · 6 comments · Fixed by #6 · May be fixed by #7

Comments

@rvoitenko
Copy link

Hi!

not an issue, more a proposal/question.
Do you think it would be difficult to parse "Changes to Outputs:" from the plan as well?
It's also an essential part of terraform plan information.

@containerscrew
Copy link
Owner

Hey @rvoitenko, let me take a look at it and get back to you as soon as I can!

@containerscrew
Copy link
Owner

Hello @rvoitenko Sorry for the time, I haven't been able to review this feature before. Looking at the library, it seems that it would be possible to show the changes in the outputs. I need to research more about it, I will try to get a new release out as soon as possible :)

image

@danielewood
Copy link
Contributor

@containerscrew You may want to have a look at my current branch:
https://github.com/danielewood/tftools/blob/tags-and-change-summary/

I have this functionality, but its terrible code quality wise. That said, this branch has been in production for the past four months, being used hundreds of times per day on many different repositories.

You may also want to copy a few things from my bash function. Terraform plan locks remote state, so if you throw away the plan file, you end up with locked remote state. My bash function addresses this.

@rvoitenko
Copy link
Author

@containerscrew, @danielewood why is this issue marked as completed?
#6 doesn't consist any logic related to output changes if I understand correctly.

I've tested it:

$ terraform plan
Terraform will perform the following actions:

  # local_file.foo will be created
  + resource "local_file" "foo" {
      + content              = "foo!"
      + content_base64sha256 = (known after apply)
      + content_base64sha512 = (known after apply)
      + content_md5          = (known after apply)
      + content_sha1         = (known after apply)
      + content_sha256       = (known after apply)
      + content_sha512       = (known after apply)
      + directory_permission = "0777"
      + file_permission      = "0777"
      + filename             = "./foo.bar"
      + id                   = (known after apply)
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Changes to Outputs:
  + output1 = "test2"
$ ./tftools version                                                                                                                                                                     ─╯
tftools: v0.9.0 with go version go1.22.2 darwin/arm64
$ ./tftools summarize --show-tags --show-unchanged --compact <plan.json                                                                                                                 ─╯
🟢 Create:
  + local_file.foo

@containerscrew containerscrew reopened this May 6, 2024
@containerscrew
Copy link
Owner

containerscrew commented May 6, 2024

Hi @rvoitenko . Let's see if I understood you correctly.

Imagine you are declaring the following:

output "my_lambda_function_public_url" { value = module.mylambda.lambda_function_url }
In this example above, I would be getting the URL of my lambda. (just an example)

https://registry.terraform.io/modules/terraform-aws-modules/lambda/aws/latest?tab=outputs.

Imagine the URL change, so the output of that lambda changes because its URL has changed. Do you want it to also be reflected in the tftools summarize command?

@rvoitenko
Copy link
Author

Hi @rvoitenko . Let's see if I understood you correctly.

Imagine you are declaring the following:

output "my_lambda_function_public_url" { value = module.mylambda.lambda_function_url } In this example above, I would be getting the URL of my lambda. (just an example)

https://registry.terraform.io/modules/terraform-aws-modules/lambda/aws/latest?tab=outputs.

Imagine the URL change, so the output of that lambda changes because its URL has changed. Do you want it to also be reflected in the tftools summarize command?

Yes, exactly. Because changes in outputs can be crucial in some cases.

Currently I have to do some dirty hack with bash to add output changes to summary:

terraform show --json plan.tfplan > plan.json
cat plan.json | tftools summarize > summary.txt
PLAN_OUTPUT=$(terraform show plan.tfplan -compact-warnings| grep -Ev "You can apply this plan|without changing any real infrastructure")
if echo "$PLAN_OUTPUT" | grep -q "Changes to Outputs:"; then
  echo "🔵 Changes to Outputs:" >> summary.txt
  echo "$PLAN_OUTPUT" | sed -n '/Changes to Outputs:/,$p' | grep -v "Changes to Outputs:" |grep -v '^   '|awk '{print "  +", $2}' >> summary.txt
fi

So it would be much nicer if tftools can add output changes to summary.

@containerscrew containerscrew linked a pull request May 7, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants