Problem
When you run a Terraform plan using the Google provider, you may encounter the following error, even when the credentials are set correctly in the HCP Terraform workspace.
Error: unable to parse credentials unexpected end of JSON input
Cause
This error occurs due to a change in how the Google provider handles empty credential strings.
-
Google Provider v4.60 and newer: Correctly reports that an empty string (
"") is not a parsable set of credentials. - Google Provider v4.59 and older: Incorrectly treated an empty string as valid, allowing Terraform to fall back to environment variables.
The following configuration will cause the error with provider versions v4.60 and newer.
provider "google" {
credentials = ""
}Solutions
Choose the solution that corresponds to your Google provider version.
Solution 1: For Google Provider v4.60 and Newer
Remove the credentials = "" line from your provider configuration. This allows the provider to correctly use the GOOGLE_CREDENTIALS environment variable set in your HCP Terraform workspace.
Update your configuration to the following.
provider "google" {
# credentials = ""
}Solution 2: For Google Provider v4.59 and Older
With these older provider versions, an empty string is a valid value. Terraform will ignore the empty string and acquire the GOOGLE_CREDENTIALS from the HCP Terraform workspace environment variables. No change is required if you intend to continue using these provider versions.
provider "google" {
credentials = ""
}Additional Information
For more details on this behavior change, refer to the related GitHub Issue in the terraform-provider-google repository.