I am working on this small terraform project that uses gcp (google cloud platform) token.json which contains secure credentials to create resources.
Terraform files are executed by the Gitlab CI/CD.
My concern is, this token.json is used by the one of the terraform files (main.tf) as below.
# Configure the backend
terraform {
backend "gcs" {
bucket = "tf_backend_gcp_banuka_jana_jayarathna_k8s"
prefix = "terraform/gcp/boilerplate"
credentials = "./token.json" ----> file I need to keep securely
}
}
This token.json is in the root folder with the main.tf file above.
This file is needed for that file and I can't think of any other way how I can store this. This token cannot even put to gitlab variables as there is no way to pass the values of the token to this main.tf file when the pipeline runs.
I don't want to expose the token.json to public too. Is there a way I can achieve this in Gitlab?
Can't even use a tool like git-crypt because then how can I decrypt this token.json and feed it to the main.tf...
Is there a way to inject variables to terraform files ?
Thank you