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

Outputting plan file to specific path fails #55

Closed
1 of 2 tasks
Mornor opened this issue Apr 8, 2024 · 7 comments
Closed
1 of 2 tasks

Outputting plan file to specific path fails #55

Mornor opened this issue Apr 8, 2024 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@Mornor
Copy link

Mornor commented Apr 8, 2024

Describe the bug
The following commands fails to redirect the plan file

tg_command: plan -out {{ github.workspace }}/terragrunt.tfplan

To Reproduce

name: Deploy customer changes
on: push

env:
  TF_VERSION: 1.5.1
  TG_VERSION: 0.55.21

jobs:
  terragrunt-plan:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Plan
        uses: gruntwork-io/terragrunt-action@v2
        with:
          tf_version: ${{ env.TF_VERSION }}
          tg_version: ${{ env.TG_VERSION }}
          tg_dir: ${{ env.WORKING_DIR }}
          tg_command: plan -out {{ github.workspace }}/terragrunt.tfplan

Expected behavior

No changes. Your infrastructure matches the configuration.

Terraform has compared your real infrastructure against your configuration
and found no differences, so no changes are needed.

Actual behaviour

│ Error: Failed to write plan file
│ 
│ The plan file could not be written: open
│ /home/runner/work/<path>/terragrunt.tfplan:
│ no such file or directory.
╵

Other notes
The following command works

tg_command: plan -out $(pwd)terragrunt.tfplan

But I would expect one of these commands to work instead

tg_command: plan -out {{ github.workspace }}/terragrunt.tfplan
tg_command: plan -out "{{ github.workspace }}/terragrunt.tfplan"
tg_command: plan -out $(pwd)/terragrunt.tfplan

Nice to have

  • Terminal output
  • Screenshots

Versions

  • Terragrunt Action version: terragrunt-action@v2
  • Environment details (Terragrunt version, Terraform version, etc.):
  TF_VERSION: 1.5.1
  TG_VERSION: 0.55.21

Related
Might be related to #40

@Mornor Mornor added the bug Something isn't working label Apr 8, 2024
@levkohimins levkohimins self-assigned this Apr 10, 2024
@levkohimins
Copy link

Hi @Mornor, the issue is the forward slash, right?

@Mornor
Copy link
Author

Mornor commented Apr 10, 2024

Yes, it should work with a forward slash (so a full path) like so

tg_command: plan -out {{ github.workspace }}/terragrunt.tfplan
tg_command: plan -out "{{ github.workspace }}/terragrunt.tfplan"
tg_command: plan -out $(pwd)/terragrunt.tfplan

But it doesn't (Error: Failed to write plan file ...).

However, this works (without forward slash)

tg_command: plan -out $(pwd)terragrunt.tfplan

IMO, we should be able to give a full path for the plan file as output.

@levkohimins
Copy link

@Mornor, -out is a terraform flag, Terragrunt simply passes this flag to Terraform when running the terraform plan command. You should create this issue in Terraform issues.

@Mornor
Copy link
Author

Mornor commented Apr 11, 2024

The corresponding command (terraform plan -out terraform.tfplan) works fine.
Locally issuing following command works as well, so this make me think the issue is related to the Terragrunt GH Action itself

$> rm -rf $(pwd)/terragrunt.tfplan
$> terragrunt plan -out $(pwd)/terragrunt.tfplan
No changes. Your infrastructure matches the configuration.

$> terragrunt show $(pwd)/terragrunt.tfplan
No changes. Your infrastructure matches the configuration.

However, it seems the terragrunt command itself doesn't work as expected. Locally, this does not produce any plan.

$> terragrunt plan -out terragrunt.tfplan

But this does

$> terragrunt plan -out $(pwd)/terragrunt.tfplan

However, not with Github Action (Error: Failed to write plan file [...] terragrunt.tfplan: no such file or │ directory

This might be related to a core Terragrunt issue.

@denis256
Copy link
Member

denis256 commented Apr 11, 2024

Hi,
AFAIK, *workspace variables in case of runners point to the wrong locations, use /github/workspace path to save/load plan files
In my tests:

github.workspace = /home/runner/work/terragrunt-tests/terragrunt-tests
GITHUB_WORKSPACE = /home/runner/work/terragrunt-tests/terragrunt-tests
runner.workspace = /home/runner/work/terragrunt-tests
RUNNER_WORKSPACE = /home/runner/work/terragrunt-tests

when during execution, working directory is mounted in /github/workspace

actions/runner#2058

@levkohimins levkohimins removed their assignment Apr 12, 2024
@Mornor
Copy link
Author

Mornor commented Apr 12, 2024

Hi @denis256,

Big up to you, as I managed to make it work with a combination of your solution and some mv commands:

    - name: Plan
      uses: gruntwork-io/terragrunt-action@v2
      with:
        tf_version: ${{ inputs.tf_version }}
        tg_version: ${{ inputs.tg_version }}
        tg_dir: ${{ inputs.customer_dir }}/${{ inputs.customer }}/${{ inputs.dir_to_deploy }}
        tg_command: plan -out /github/workspace/terragrunt.tfplan
        
     - name: Move plan file
        working-directory: ${{ github.workspace }}
        run: mv terragrunt.tfplan ${{ inputs.customer_dir }}/${{ inputs.customer }}/${{ inputs.dir_to_deploy }}/terragrunt.tfplan   

I don't really like or understand the combination of {{ github.workspace }} and /github/workspace/ (and I still think there's something not working properly under the hood), but at least it works!

@linear linear bot assigned denis256 Jun 4, 2024
@denis256
Copy link
Member

Closing this issue as it is related to how the GitHub action sets up the workspace directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants