# Terraform remote state data source unsupported attribute

**URL:** <https://discuss.hashicorp.com/t/terraform-remote-state-data-source-unsupported-attribute/21948>\
**Category:** Terraform\
**Created:** [March 11, 2021, 6:40pm UTC](https://discuss.hashicorp.com/t/terraform-remote-state-data-source-unsupported-attribute/21948 "2021-03-11T18:40:19Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![igpix](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/igpix/32/17919_2.png) [@igpix](https://discuss.hashicorp.com/u/igpix)\
**Post date:** [March 11, 2021, 6:40pm UTC](https://discuss.hashicorp.com/t/terraform-remote-state-data-source-unsupported-attribute/21948/1 "2021-03-11T18:40:19Z")

</div>

I’ve setup a project with the following structure

```auto
├── gke
│ ├── main.tf
│ ├── outputs.tf
│ ├── provider.tf
│ └── terraform.tfstate
├── k8s
│ ├── main.tf
│ ├── provider.tf
│ ├── terraform.tfvars
│ └── variables.tf
└── modules
    └── kubernetes
        └── namespace
            └── namespace.tf

```

In gke dir I’m using only google provider to manage a gke cluster

Using console I can query the endpoint value of gke cluster

```auto
 $ terraform console
> google_container_cluster.primary.endpoint
"1.2.3.4"

```

I put this value into root module outputs

```auto
$ cat outputs.tf
output "endpoint" {
  value = google_container_cluster.primary.endpoint
}

```

In k8s dir I’m using only kubernetes provider but I want authenticate using informations available in gke tfstate (endpoint ip and ca certificate)

Below the configuration of provider.tf in k8s dir

```auto
data "google_client_config" "default" {}

data "terraform_remote_state" "gke" {
  backend = "local"
  config = {
    path = "../gke/terraform.tfstate"
  }
}

provider "kubernetes" {
  host = "https://${data.terraform_remote_state.gke.google_container_cluster.primary.endpoint}"
  token = data.google_client_config.default.access_token
  cluster_ca_certificate = base64decode(data.terraform_remote_state.gke.google_container_cluster.primary.master_auth.0.cluster_ca_certificate)
}

```

If I run terraform plan inside k8s dir I get the following errors:

```auto
Error: Unsupported attribute

  on provider.tf line 19, in provider "kubernetes":
  19: host = "https://${data.terraform_remote_state.gke.google_container_cluster.primary.endpoint}"

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

Error: Unsupported attribute

  on provider.tf line 21, in provider "kubernetes":
  21: cluster_ca_certificate = base64decode(data.terraform_remote_state.gke.google_container_cluster.primary.master_auth.0.cluster_ca_certificate)

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

```

What I’m doing wrong?  
Thanks for your help

---

<div class="post-metadata">

**Author:** ![ohmer](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/ohmer/32/17491_2.png) [@ohmer](https://discuss.hashicorp.com/u/ohmer)\
**Post date:** [March 11, 2021, 8:44pm UTC](https://discuss.hashicorp.com/t/terraform-remote-state-data-source-unsupported-attribute/21948/2 "2021-03-11T20:44:52Z")

</div>

try replacing

```auto
data.terraform_remote_state.gke.google_container_cluster.primary.master_auth.0.cluster_ca_certificate

```

with

```auto
data.terraform_remote_state.gke.outputs.google_container_cluster.primary.master_auth.0.cluster_ca_certificate

```

Reference: [https://registry.terraform.io/providers/hashicorp/terraform/latest/docs/data-sources/remote\_state#attributes-reference](https://registry.terraform.io/providers/hashicorp/terraform/latest/docs/data-sources/remote_state#attributes-reference)

---

<div class="post-metadata">

**Author:** ![igpix](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/igpix/32/17919_2.png) [@igpix](https://discuss.hashicorp.com/u/igpix)\
**Post date:** [March 11, 2021, 10:07pm UTC](https://discuss.hashicorp.com/t/terraform-remote-state-data-source-unsupported-attribute/21948/3 "2021-03-11T22:07:33Z")

</div>

Yes, I’ve already tried adding outputs but the issue persist

```auto
provider "kubernetes" {
  host = "https://${data.terraform_remote_state.gke.outputs.google_container_cluster.primary.endpoint}"
  token = data.google_client_config.default.access_token
  cluster_ca_certificate = base64decode(data.terraform_remote_state.gke.outputs.google_container_cluster.primary.master_auth.0.cluster_ca_certificate)
}

```

```auto
$ terraform plan
Error: Unsupported attribute

  on provider.tf line 19, in provider "kubernetes":
  19: host = "https://${data.terraform_remote_state.gke.outputs.google_container_cluster.primary.endpoint}"
    |----------------
    | data.terraform_remote_state.gke.outputs is object with 1 attribute "endpoint"

This object does not have an attribute named "google_container_cluster".

Error: Unsupported attribute

  on provider.tf line 21, in provider "kubernetes":
  21: cluster_ca_certificate = base64decode(data.terraform_remote_state.gke.outputs.google_container_cluster.primary.master_auth.0.cluster_ca_certificate)
    |----------------
    | data.terraform_remote_state.gke.outputs is object with 1 attribute "endpoint"

This object does not have an attribute named "google_container_cluster".

```

I’m unsure, but is it correct that output below doesn’t show the value of the variable?  
From inside gke dir:

```auto
$ terraform output
endpoint = "google_container_cluster.primary.endpoint"

```

---

<div class="post-metadata">

**Author:** ![apparentlymart](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/apparentlymart/32/702_2.png) [@apparentlymart](https://discuss.hashicorp.com/u/apparentlymart)\
**Post date:** [March 11, 2021, 11:01pm UTC](https://discuss.hashicorp.com/t/terraform-remote-state-data-source-unsupported-attribute/21948/4 "2021-03-11T23:01:45Z")

</div>

I think you might have two separate problems here, because that output value you showed doesn’t look right (it seems to be a string literally containing a Terraform expression rather than the _result_ of a Terraform expression), but focusing on the error message you shared it seems like the problem is that Terraform can only see one output value called `endpoint`, and there isn’t an output value declared called `google_container_cluster`.

If you want to export that entire object as an output then you’d need to declare an output value in the module like this:

```auto
output "google_container_cluster" {
  value = {
    primary = google_container_cluster.primary
  }
}

```

It’s more typical, though, to export only a particular subset of the data from resource objects, so that the module’s interface is smaller and focused only on the problem at hand. If you wanted to do that, you could declare an output value called `cluster_ca_certificate` like this:

```auto
output "cluster_ca_certificate" {
  value = google_container_cluster.primary.master_auth.0.cluster_ca_certificate
}

```

…and then access it from the remote state data resource as `data.terraform_remote_state.gke.outputs.cluster_ca_certificate`.

---

<div class="post-metadata">

**Author:** ![igpix](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/igpix/32/17919_2.png) [@igpix](https://discuss.hashicorp.com/u/igpix)\
**Post date:** [March 15, 2021, 5:11am UTC](https://discuss.hashicorp.com/t/terraform-remote-state-data-source-unsupported-attribute/21948/5 "2021-03-15T05:11:58Z")

</div>

Thanks all, I made it working.

In gke/outputs

```auto
output "endpoint" {
  value = google_container_cluster.primary.endpoint
}
output "ca" {
  value = google_container_cluster.primary.master_auth.0.cluster_ca_certificate
}

```

Then I access from within k8s dir with:

```auto
provider "kubernetes" {
  host = "https://${data.terraform_remote_state.gke.outputs.endpoint}"
  token = data.google_client_config.default.access_token
  cluster_ca_certificate = base64encode(data.terraform_remote_state.gke.outputs.ca)
}

```

What I’ve fixed also is the output section of terraform.tfstate file  
Because actually I have imported the gke resource and never did “terraform apply”

```auto
  "outputs": {
    "endpoint": {
      "value": "google_container_cluster.primary.endpoint",
      "type": "string"
    },
    "ca": {
      "value": "google_container_cluster.primary.master_auth.0.cluster_ca_certificate",
      "type": "string"
     }
  },

```

Last thing to investigate is the access of output variables inside gke dir.  
Why I can’t access the value ?

```auto
$ terraform output
ca = "google_container_cluster.primary.master_auth.0.cluster_ca_certificate"
endpoint = "google_container_cluster.primary.endpoint"

```

---

<div class="post-metadata">

**Author:** ![igpix](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/igpix/32/17919_2.png) [@igpix](https://discuss.hashicorp.com/u/igpix)\
**Post date:** [March 15, 2021, 5:54am UTC](https://discuss.hashicorp.com/t/terraform-remote-state-data-source-unsupported-attribute/21948/6 "2021-03-15T05:54:59Z")

</div>

Ok I’ve figured out what’s the problem with the output.  
Output section within terraform.tfstate file should contains the value of the parameter, non the string.

```auto
  "outputs": {
    "endpoint": {
      "value": "1.2.3.4",
      "type": "string"
    },
...

```

Is there a way to fill these value automatically using terraform import?

---

<div class="post-metadata">

**Author:** ![igpix](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/igpix/32/17919_2.png) [@igpix](https://discuss.hashicorp.com/u/igpix)\
**Post date:** [March 18, 2021, 6:21pm UTC](https://discuss.hashicorp.com/t/terraform-remote-state-data-source-unsupported-attribute/21948/7 "2021-03-18T18:21:03Z")

</div>

Thanks all for your contributes, I’ve solved all the issues.
