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

How to output attributes of instances from terraform.tfstate? #3754

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

How to output attributes of instances from terraform.tfstate? #3754

ameyaptk opened this issue May 31, 2019 · 4 comments

Comments

@ameyaptk
Copy link

I'm executing a GCP module to create a service-account.

main.tf


   resource "google_service_account" "gsvc_account" {
     account_id   = "xxx"
     display_name = ""
     project = "proj-yyy"
   }
   output "account_id" {
     value = "${google_service_account.gsvc_account.account_id}"
   }

Once the account is created, a terraform.tfstate file is created containing all details of the account.

terraform.tfstate


    {
      "version": 4,
      "terraform_version": "0.12.0",
      "serial": 3,
      "lineage": "aaaa-bbbb-cccc",
      "outputs": {
        "xxx": {
          "value": "xxx",
          "type": "string"
        }
      },
      "resources": [
        {
          "module": "module.gsvc_tf",
          "mode": "managed",
          "type": "google_service_account",
          "name": "gsvc_account",
          "provider": "provider.google",
          "instances": [
            {
              "schema_version": 0,
              "attributes": {
                "account_id": "xxx",
                "display_name": "",
                "email": "[email protected]",
                "id": "projects/proj-yyy/serviceAccounts/[email protected]",
                "name": "projects/proj-yyy/serviceAccounts/[email protected]",
                "policy_data": null,
                "project": "proj-xxx",
                "unique_id": "10891885"
              }
            }
          ]
        }
      ]
    }


As you can see above, in the module, I'm outputing the account_id input variable. Is there a way to output the attributes viz. id, name etc. so that they can be accessed by another module? The attributes are computed after the resource is created.

@rileykarson
Copy link
Collaborator

name can be outputted by the module, similar to any other field. This would need to be done in the module, and isn't something that can be resolved from the provider.

@ameyaptk
Copy link
Author

Perfect! That worked. Thanks! Is there a way to see which attributes can be 'outputed' and which can't?

@ameyaptk
Copy link
Author

Nvm. Found it in provider documentation- https://www.terraform.io/docs/providers/google/r/google_service_account.html

@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