I have a module cluster
that spins up a GKE cluster and associated GCS buckets.
The backend for this is a GCS bucket called cluster_tf_state_bucket
I have defined an output in this module
output "vault_storage_bucket_name" {
value = "${google_storage_bucket.vault_storage.name}"
}
Once I run the code, I get the output
✗ terraform output
vault_storage_bucket_name = vault-storage
Now I have a another module vault
and in that module I need to invoke the value of vault_storage_bucket_name
from the other module that is using a different GCS backend bucket.
So in the main.tf of my vault
module, Im doing something like
terraform {
required_version = ">= 0.12.2"
}
terraform {
backend "gcs" {
bucket = "app_tf_state_bucket"
prefix = "vault"
}
}
data "terraform_remote_state" "cluster_vault" {
backend = "gcs"
config = {
bucket = "cluster_tf_state_bucket"
}
}
module "vault" {
source = "../../../modules/vault"
env = "test"
region = "europe-west5"
storage_bucket_name = "${data.terraform_remote_state.cluster_vault.vault_storage_bucket_name}"
But when I run this code, I get
Error: Unsupported argument
on main.tf line 24, in module "vault":
24: storage_bucket_name = "${data.terraform_remote_state.cluster_vault.vault_storage_bucket_name}"
An argument named "storage_bucket_name" is not expected here.
I resolved the above issue by adding the below to the `variables.tf file
variable "storage_bucket_name"{
type = "string"
}
And now I run into the error
Error: Unsupported attribute
on main.tf line 24, in module "vault":
24: storage_bucket_name = "${data.terraform_remote_state.cluster_vault.vault_storage_bucket_name}"
This object has no argument, nested block, or exported attribute named
"vault_storage_bucket_name".
What am I missing here ?
This object has no argument, nested block, or exported attribute named "vault_storage_bucket_name".
Would you know why ? – Jason Stanley