If I run terraform plan inside k8s dir I get the following errors:
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".
$ 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:
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:
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:
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.
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.