Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to access output attributes #3759

Closed
ameyaptk opened this issue May 31, 2019 · 4 comments
Closed

Unable to access output attributes #3759

ameyaptk opened this issue May 31, 2019 · 4 comments

Comments

@ameyaptk
Copy link

I'm unable to access attributes from terraform.tfstate for a service account resource I created. The attribute exists and has a value.

module1/main.tf

resource "google_service_account" "gsvc_account" {
  account_id   = "${var.account_id}"
  display_name = "${var.display_name}"
  project = "${var.project}"
}

output "account_id" {
  value = "${google_service_account.gsvc_account.account_id}"
}

output "name" {
  value = "${google_service_account.gsvc_account.name}"
}

After the module is run, a terraform.tfstate is created

root/main.tf

module "gsvc_tf_billing" {
  source = "<path>"

  account_id = "gsvc-tf-billing"
  project = "${var.project_id}"
}

output "gsvc_tf_billing_id" {
  value = "${module.gsvc_tf_billing.account_id}"
}

output "gsvc_tf_billing_name" {
 value = "${module.gsvc_tf_billing.name}"
 }

terraform.tfstate

{
  "version": 4,
  "terraform_version": "0.12.0",
  "serial": 4,
  "lineage": "aaa-bbb-ccc",
  "outputs": {
    "gsvc_tf_billing": {
      "value": "gsvc-tf-billing",
      "type": "string"
    },
    "gsvc_tf_billing_id": {
      "value": "gsvc-tf-billing",
      "type": "string"
    },
    "gsvc_tf_billing_name": {
      "value": "projects/proj-xxx/serviceAccounts/[email protected]",
      "type": "string"
    }
  },

<ouput redacted>

As you can see, there is an output field gsvc_tf_billing_name. When I try to access this attribute via another module, it giving me an error

module2/main.tf

data "terraform_remote_state" "gsvc_accounts" {
  backend = "local"
  config = {
    path = "<path>/terraform.tfstate"             // path to the above terraform.tfstate. confirmed correct
   }
}

module "iam_member_01" {
  source  = "<path>/module"

  project = "${var.project_id}"
  role = "billing.admin"
  member = "${data.terraform_remote_state.gsvc_accounts.gsvc_tf_billing_name}"
}

Error:

Error: Unsupported attribute

  on main.tf line 21, in module "iam_member_01":
  21:   member = "${data.terraform_remote_state.gsvc_accounts.gsvc_tf_billing_name}"

This object has no argument, nested block, or exported attribute named
"gsvc_tf_billing_name".

@ameyaptk
Copy link
Author

I don't see path:root in terraform.tfstate above. Not sure why.

@rileykarson
Copy link
Collaborator

I can't see anything obviously wrong. This appears to be an issue with the remote state, and not something specific to the Google provider. Do you mind filing at https://github.com/hashicorp/terraform?

@ameyaptk
Copy link
Author

Figured this out. Turns out in module2/main.tf, I had to access the attribute as

member = "${data.terraform_remote_state.gsvc_accounts.outputs.gsvc_tf_billing_name}"

@ghost
Copy link

ghost commented Jul 1, 2019

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

@ghost ghost locked and limited conversation to collaborators Jul 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants