Skip to content

terraform: Avoid reference to digitalocean k8s resource in k8s provider

Dduvall requested to merge review/refactor-terraform into main

According to Terraform documentation, it is bad practice to set kubernetes provider (or any provider?) attributes using resource attributes.

See https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs#stacking-with-managed-kubernetes-cluster-resources And https://itnext.io/terraform-dont-use-kubernetes-provider-with-your-cluster-resource-d8ec5319d14a

Failure to do this can result in strange errors like the following:

Error: Get "http://localhost/api/v1/namespaces/gitlab-runner": dial tcp [::1]:80: connect: connection refused with kubernetes_namespace.gitlab_runner, on cluster.tf line 100, in resource "kubernetes_namespace" "gitlab_runner": 100: resource "kubernetes_namespace" "gitlab_runner" {

Using a data source to retrieve k8s cluster attributes from DO solves this problem.

See https://registry.terraform.io/providers/digitalocean/digitalocean/latest/docs/data-sources/kubernetes_cluster

Merge request reports