I have the GCP service account key file in JSON format, which I need to export as GOOGLE_APPLICATION_CREDENTIALS. Is there a way in Terraform to provide the "contents" of this JSON file directly (instead of specifying the path to the file) in a Terraform variable block and then have Terraform interpret is as JSON? I have seen that Terraform has jsonencode and jsondecode functions, but not able to find many examples on it. Is there any other way to do this? Below is the approach I'm looking at:
variable "credentials"{
type = "string"
default="<contents of service account key file in JSON format>"
}
In Bastion start up script:
#!/bin/bash
export GOOGLE_APPLICATION_CREDENTIALS= jsonencode("${file(var.credentials)}")
So ultimately, GOOGLE_APPLICATION_CREDENTIALS should have the contents of the key file in JSON format. Can this be done in any way?