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

Confusing error message when missing 'location' and 'project' #82

Open
antspy opened this issue Dec 17, 2024 · 2 comments
Open

Confusing error message when missing 'location' and 'project' #82

antspy opened this issue Dec 17, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@antspy
Copy link

antspy commented Dec 17, 2024

Hi,

When I run terragrunt locally, this works:

terragrunt plan --terragrunt-working-dir=src/dir/terraform/prod/cloud

I want to make it work with Github Actions, but I am getting the following error: "ERROR Missing required GCS remote state configuration project".

The setup is as follows:

steps:
      - uses: actions/checkout@v4

      - uses: hashicorp/setup-terraform@v3

      - uses: "google-github-actions/auth@v2"
        id: auth
        with:
          project_id: "XXX"
          service_account: "YYY"
          workload_identity_provider: "ZZZ"
          token_format: access_token

      - name: Set up Cloud SDK
        uses: "google-github-actions/setup-gcloud@v2"
        with:
          version: ">= 363.0.0"

      - name: Call terragrunt apply
        uses: gruntwork-io/terragrunt-action@v2
        env:
          GOOGLE_OAUTH_ACCESS_TOKEN: ${{ steps.auth.outputs.access_token }}
        with:
          tf_version: "1.10.0"
          tg_version: "0.69.13"
          tg_dir: 'src/dir/terraform/prod/cloud'
          tg_command: 'apply'

Could you help me understand what I am doing wrong?

  1. I tried also without passing the GOOGLE_OAUTH_ACCESS_TOKEN, but with the same result.
  2. Before terragrunt, I was using terraform directly with the exact same setup and it worked fine - so github actions can authenticate successfully to gcloud.

My remote state configuration is

remote_state {
  backend = "gcs"
  config = {
    bucket = "XXX"
    prefix = "${path_relative_to_include()}-${local.env}"
  }

  generate = {
    path      = "backend.tf"
    if_exists = "overwrite_terragrunt"
  }
}

Again, this works fine locally, but keeps crashing on github actions. Any suggestion is welcome ! :) For example, is there a way to collect better error messages? This is very terse and I don't know how to debug further


EDIT:
It turns out that the issue was that I didn't set the project and location keys inside the config tuple of the gcs remote_state. The error messages are confusing and it would be great to make this easier to debug! :)

@antspy antspy added the bug Something isn't working label Dec 17, 2024
@yhakbar
Copy link

yhakbar commented Dec 20, 2024

Hey @antspy , check out our debugging docs.

Setting --terragrunt-log-level debug should get you the information you're looking for.

For this issue in particular, it seems like the specific issue is the fact that the project isn't specified in your remote_state config:

For this to work correctly you must also specify project and location keys in remote_state.config

See the docs here.

This is a bad error message, so if this resolves your issue, I would appreciate if you could update the issue to report the bad error message as the bug, along with bad documentation at the bottom here. It should be easier for users to understand that this is the problem when they run into this error.

@antspy antspy changed the title Unable to connect to GCS using actions, works fine locally Confusing error message when missing 'location' and 'project' Dec 27, 2024
@antspy
Copy link
Author

antspy commented Dec 27, 2024

Indeed, this was the bug! Setting the project and location worked fine :)

I have updated the issue - thank you for your help!! :)

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

2 participants