Looks like a permissions issue when you are trying to create a BigQuery table with external data source (spreadsheets) from Terraform. Terraform seems to use the application-default-credentials (ADCs) when no service account is supplied.
If you have other BQ tables that are connected with spreadsheets and changing/adding those works out-of-the-box. Only for this specific resource after executing the below command to set ADCs with the needed scopes (The scopes are copied from the tf file):
gcloud auth application-default login --scopes=https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/drive.readonly,https://www.googleapis.com/auth/drive,https://www.googleapis.com/auth/bigquery
Also create an external table where you require bigquery.tables.create
permission. Refer to Required roles, additionally, you can create an external table in BigQuery for a Drive data source (files in Drive) . The access token requires both "drive"
and "bigquery"
scope, otherwise the query will fail with a permission error.
EDIT1 :
Refer to Using Terraform Cloud :
Place your credentials in a Terraform Cloud environment variable:
- Create an environment variable called
GOOGLE_CREDENTIALS
in your
Terraform Cloud workspace.
- Remove the newline characters from your
JSON key file and then paste the credentials into the environment
variable value field. You can use the tr command to strip newline
characters.
cat key.json | tr -s '\n' ' '
- Mark the variable as
Sensitive and click the Save variable.
All runs within the workspace will use the GOOGLE_CREDENTIALS
variable to authenticate with Google Cloud
Platform.
EDIT2:
scopes - (Optional) The list of OAuth 2.0 scopes requested when generating an access token using the service account key specified in credentials. Ensure that the scope of the VM/Cluster is set to or includes googleapis.com/auth/cloud-platform
, By default, the following scopes are configured: googleapis.com/auth/cloud-platform
and googleapis.com/auth/userinfo.email
. Refer to Authentication Configuration.
References:
- 3nigm4's and vitorc.radi's answers on How to authenticate to gcp when using terraform cloud.
- Yaroslav Markovski's, HashiCorp Help Center article on How-to set up Google Cloud (GCP) credentials in Terraform Cloud