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

'terraform import digitalocean_kubernetes_cluster' imports wrong node pool #850

Open
mstyne opened this issue Jul 21, 2022 · 0 comments
Open

Comments

@mstyne
Copy link

mstyne commented Jul 21, 2022

Bug Report


Describe the bug

When importing an existing Kubernetes cluster using terraform import digitalocean_kubernetes_cluster, the incorrect node pool ID is imported.

Affected Resource(s)

  • digitalocean_kubernetes_cluster
  • digitalocean_kubernetes_node_pool

Expected Behavior

With the following configuration:

% doctl kubernetes cluster node-pool list 80654840-... --format ID,Tags
ID                                      Tags
6f41bd3b-...    k8s,k8s:80654840-...,k8s:worker,terraform:default-node-pool
152b6618-...    k8s,k8s:80654840-...,k8s:worker

I expect node pool 6f41bd3b-..., tagged as terraform:default-node-pool to be imported when executing

terraform import digitalocean_kubernetes_cluster.doks_hosted_cluster 80654840-...

Actual Behavior

When executing terraform import, the other, non-tagged node pool is imported.

digitalocean_kubernetes_cluster.doks_hosted_cluster: Importing from ID "80654840-..."...
digitalocean_kubernetes_cluster.doks_hosted_cluster: Import prepared!
  Prepared digitalocean_kubernetes_cluster for import
  Prepared digitalocean_kubernetes_node_pool for import
digitalocean_kubernetes_node_pool.doks_hosted_cluster: Refreshing state... [id=152b6618-...]
digitalocean_kubernetes_cluster.doks_hosted_cluster: Refreshing state... [id=80654840-...]

Import successful!

The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.

Steps to Reproduce

See "Actual Behavior".
Terraform Configuration Files
main.tf:

terraform {
  required_providers {
    digitalocean = {
      source = "digitalocean/digitalocean"
      version = "~> 2.0"
    }
  }
}

variable "do_token" {}
variable "doks_cluster_name" {}
variable "doks_cluster_region" {}
variable "doks_cluster_version" {}
variable "doks_cluster_tags" {}

variable "doks_primary_node_pool_name" {}
variable "doks_primary_node_pool_size" {}
variable "doks_primary_node_pool_min" {}
variable "doks_primary_node_pool_max" {}
variable "doks_primary_node_pool_count" {}

variable "doks_secondary_node_pool_name" {}
variable "doks_secondary_node_pool_size" {}
variable "doks_secondary_node_pool_min" {}
variable "doks_secondary_node_pool_max" {}
variable "doks_secondary_node_pool_count" {}

provider "digitalocean" {
  token = var.do_token
}

resource "digitalocean_kubernetes_cluster" "doks_hosted_cluster" {
  name   = var.doks_cluster_name
  region = var.doks_cluster_region
  version = "1.21.14-do.0"
  auto_upgrade = true
  tags = [ "development" ]

  node_pool {
    name       = var.doks_primary_node_pool_name
    size       = var.doks_primary_node_pool_size
    max_nodes  = var.doks_primary_node_pool_max
    min_nodes  = var.doks_primary_node_pool_min
    node_count = var.doks_primary_node_pool_count
  }

}

resource "digitalocean_kubernetes_node_pool" "doks_secondary_node_pool" {
  cluster_id = digitalocean_kubernetes_cluster.doks_hosted_cluster.id

  name       = var.doks_secondary_node_pool_name
  size       = var.doks_secondary_node_pool_size
  node_count = var.doks_secondary_node_pool_count

}

Expected behavior

% terraform -v       
Terraform v1.2.5
on darwin_amd64
+ provider registry.terraform.io/digitalocean/digitalocean v2.21.0

The node pool tagged as terraform:default-node-pool should be imported when executing terraform import digitalocean_kubernetes_cluster.

Debug Output
I'm concerned about the level of detail in the debug output; I have the gist and can email the link if necessary.

Panic Output
None

Additional context

Changing the terraform:default-node-pool tag to the secondary node pool results in the "correct" node pool being imported along with the cluster.

Important Factoids
None

References
None

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

No branches or pull requests

2 participants