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

fix: Set Terraform plan file as last argument in apply-all #1429

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

amontalban
Copy link

This PR should fix #1271 (The position of the Terraform plan file in the apply-all command).

I'm having the same problem as @ibacalu when running Terragrunt with:

  extra_arguments "save_plan" {
    commands = [
      "plan"
    ]

    arguments = [
      "-out=${get_terragrunt_dir()}/${trimspace(run_cmd("basename", "${get_terragrunt_dir()}"))}.tfplan"
    ]
  }

  extra_arguments "load_plan" {
    commands = [
      "apply"
    ]

    arguments = [
      "${get_terragrunt_dir()}/${trimspace(run_cmd("basename", "${get_terragrunt_dir()}"))}.tfplan"
    ]
  }

And then running plan-all and apply-all (I am aware that this is an antipattern as described by @yorinasub17 but I think it needs to be fixed anyway).

Thanks!

Copy link
Member

@brikis98 brikis98 left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! I suspect the current approach will not work correctly. To know for sure, this PR will need tests to validate the behavior. Check out test/integration_test.go and the fixtures it uses to see how to structure such a test.

Comment on lines +282 to +284
// We need to iterate over the argsToInsert to find an arg that is a file.
// If we found one, we treat it as the Terraform plan file and we then set it
// as lastArg to append it as last argument.
Copy link
Member

Choose a reason for hiding this comment

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

Hm, I'm not sure this is a safe assumption to make. That is, it's possible to have a different arg passed to Terraform that is a file—or worse yet, happens to match the name of a valid file—but isn't a plan file. Here's an example:

terraform apply \ 
  -state foo.tfstate \
  -var foo=bar

If there's a foo.tfstate already, the code above will move that parameter to the end of the command, as if it's a plan file.

Copy link
Author

Choose a reason for hiding this comment

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

Thank you @brikis98, I haven't considered that use case. I will write a test as well as validating the current ones work fine and come back to you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

terragrunt apply-all specific plan fails
2 participants