Reputation: 4907
I'm trying to understand why my data
from my gcs backend
is saying it does not have any outputs.
I have a module called DB which creates a postgres database.
I have a file called outputs.tf, where I have
terraform {
backend "gcs" {
bucket = "projectgun-terraform-state"
prefix = "db-workspaces"
}
}
I am using a workspace i called a1
I run terraform apply and viola, it worked, I created a DB.
Furthermore, when i go into GCS, I can find my bucket, and find my key. MY workspace name is a1, I have the prefix "db-workspaces", so my remote state is saved in #{my-bucket}/db-workspaces/a1.tfstate.
When I go to that key in my bucket I see a bunch of JSON that looks like this
If i go into my db
module, and do terraform state pull
it looks just like that also. Everything checks out.
But when I go to my other module, I try to access the outputs from GCS, and I can't.
I am using module a1.
data "terraform_remote_state" "db" {
backend = "gcs"
config = {
bucket = "projectgun-terraform-state"
prefix = "db-workspaces"
}
}
When i try to access this data via outputs, I see
79: db_user = data.terraform_remote_state.db.outputs.user
│ ├────────────────
│ │ data.terraform_remote_state.db.outputs is object with no attributes
│
│ This object does not have an attribute named "user".
What am I doing wrong? Is there a better way to debug my issue? How could I be sure what key terraform is looking at when it's attempting to pull the data?
Specifically
data.terraform_remote_state.db.outputs is object with no attributes
Can i debug data.terraform_remote_state
? How can i inspect what's going on here? There are very clearly outputs when i look at the remote state, so I feel like it's grabbing the wrong key, but don't know where to look.
Upvotes: 2
Views: 846
Reputation: 4907
I found a github issue that summarizes the issue I was having and a solution.
https://github.com/hashicorp/terraform/issues/24935
data "terraform_remote_state" "network" {
backend = "gcs"
workspace = terraform.workspace
config = {
bucket = "tf-state"
prefix = "base-layer/network/"
}
}
This does not seem to be a documented fix. Thank you to @HebertCL for the answer!
Upvotes: 1