Search code examples
google-cloud-platformterraformterraform-provider-gcp

Cloud Storage Insufficient Permission while using Terraform


I am setting up the IaC with Terraform in GCP. When I run the pipeline I am getting below error

Error: Failed to get existing workspaces: querying Cloud Storage failed: googleapi: Error 403: Insufficient Permission, insufficientPermissions

Here is my backend gcs:

data "tf_state" "my_app" {
  backend = "gcs"
  config = {
    bucket = "my_bucket"
    prefix = "envs/${module.variables.environment}/my_app"
  }
}

I am able to access the content in my_bucket on console, but getting an error while running with terraform.

can anyone please let me know how to resolve this?


Solution

  • I have now declared Google application credentials in gitlab CI/CD variables in a json format and then using it in .gitlab.yml file.

    enter image description here

    # Environments definition
    .dev:
      variables:
        PROJECT_ID: <projecct-id>
        DEPLOYED_MODULES: "my-module"
        GOOGLE_CREDENTIALS: ${GOOGLE_APPLICATION_CREDENTIALS}
        TF_LOG: ""
      environment:
        name: dev
      only:
        refs:
        - develop