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

examples/kubernetes can't be modified to use a static cluster name #693

Open
kriswuollett opened this issue Sep 14, 2021 Discussed in #690 · 0 comments
Open

examples/kubernetes can't be modified to use a static cluster name #693

kriswuollett opened this issue Sep 14, 2021 Discussed in #690 · 0 comments

Comments

@kriswuollett
Copy link
Contributor

To avoid the data lookup, should the example be modified to use the dependency inversion as described in the Terraform docs? For example, just have the main module pass a basic primary_cluster value between the submodules and remove the data "digitalocean_kubernetes_cluster" "primary" from the kubernetes-config submodule:

examples/kubernetes/doks-cluster/outputs.tf:

output "primary_cluster" {
  value = {
    id                     = digitalocean_kubernetes_cluster.primary.id
    name                   = digitalocean_kubernetes_cluster.primary.name
    endpoint               = digitalocean_kubernetes_cluster.primary.endpoint
    token                  = digitalocean_kubernetes_cluster.primary.kube_config[0].token
    cluster_ca_certificate = digitalocean_kubernetes_cluster.primary.kube_config[0].cluster_ca_certificate
    raw_config             = digitalocean_kubernetes_cluster.primary.kube_config[0].raw_config
  }
}

examples/kubernetes/kubernetes-config/variables.tf:

variable "primary_cluster" {
  type = object({
    id                     = string
    name                   = string
    endpoint               = string
    token                  = string
    cluster_ca_certificate = string
    raw_config             = string
  })
}

Discussed in #690

Originally posted by kriswuollett September 13, 2021
Is there a particular reason why cluster_name being tf-k8s-${random_id.cluster_name.hex} was needed in #564? When I remove the random_id resource and just set cluster_name to my_cluster, the output of terraform plan has the error:

│ Error: Unable to find cluster with name: my-cluster
│ 
│   with module.kubernetes-config.data.digitalocean_kubernetes_cluster.primary,
│   on kubernetes-config/main.tf line 18, in data "digitalocean_kubernetes_cluster" "primary":
│   18: data "digitalocean_kubernetes_cluster" "primary" {

I'm new to Terraform so would like to learn more about this issue if it is not technically a bug. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants