I have downloaded the GCP service account key to my local system. In Terraform, I have set the GOOGLE_APPLICATION_CREDENTIALS as a path to this file in the startup-script part of my bastion instance. Below is a snippet:
variable “credentials”{
default=“C:/GCP/service-account-key.json”
}
.
.
metadata= {
startup-script=<<SCRIPT
export GOOGLE_APPLICATION_CREDENTIALS="{file("{var.credentials}")}"
SCRIPT
}
.
.
Later I have written a #!/bin/bash script to store this credentials to another file as below:
#!/bin/bash
.
.
.
#creating credentials file
printf “$GOOGLE_APPLICATION_CREDENTIALS” > /home/ubuntu/credentials
.
.
.
But when I open the above credentials file, the file is truncated as below and the entire key is missing:
{
type: service_account,
project_id: acn-devopsgcp,
private_key_id: xxxxx,
private_key: -----BEGIN
Can please someone let me know why the service account key is not getting exported properly to the file or if there is anything that needs to be corrected.
EDIT: the code snippet is attached in the file for further reference. test-file.txt (1000 Bytes)