rancher / terraform-provider-rancher2

Terraform Rancher2 provider
https://www.terraform.io/docs/providers/rancher2/
Mozilla Public License 2.0
263 stars 228 forks source link

[BUG] Default userdata for `digitalocean_config` is `docker-user` #1120

Closed jakefhyde closed 1 year ago

jakefhyde commented 1 year ago

Describe the bug

For some reason, the default userdata is populated as docker-user, when it should be empty. This prevent users from provisioning DO downstream clusters without specifying an empty userdata.

To Reproduce

Try to provision DO node drive downstream rke2 cluster

Actual Result

machine pods crash loop with following logs:

Trying to access option  which does not exist
2023-05-13T02:12:29.952060480Z THIS ***WILL*** CAUSE UNEXPECTED BEHAVIOR
2023-05-13T02:12:29.952066438Z Type assertion did not go smoothly to string for key 
2023-05-13T02:12:29.952070768Z [cmdCreateInner] could not alter cloud-init file: existing userdata file does not begin with '#!' or '#cloud-config'

Expected Result

No crashlooping machine pods

Screenshots

Additional context

Josh-Diamond commented 1 year ago

Ticket #1120 - Test Results

Reproduced w/ rancher2 TFP v3.0.1:

  1. Using rancher2 provider v3.0.1 and the main.tf file provided below, run terraform apply and observe the default value assigned to digitalocean_config > userdata:
    
    terraform {
    required_providers {
    rancher2 = {
      source  = "rancher/rancher2"
      version = "3.0.1"
    }
    }
    }

provider "rancher2" { api_url = "" token_key = "" insecure = true }

resource "rancher2_cloud_credential" "rancher2_cloud_credential" { name = "tf-do" digitalocean_credential_config { access_token = "" } }

resource "rancher2_machine_config_v2" "rancher2_machine_config_v2" { generate_name = "terratest" digitalocean_config { access_token = "" } }

resource "rancher2_cluster_v2" "rancher2_cluster_v2" { name = "jkeslar3my2" kubernetes_version = "v1.26.5+rke2r1" enable_network_policy = false default_cluster_role_for_project_members = "user" rke_config { machine_pools { name = "pool1" cloud_credential_secret_name = rancher2_cloud_credential.rancher2_cloud_credential.id control_plane_role = false etcd_role = true worker_role = false quantity = 1 machine_config { kind = rancher2_machine_config_v2.rancher2_machine_config_v2.kind name = rancher2_machine_config_v2.rancher2_machine_config_v2.name } } machine_pools { name = "pool2" cloud_credential_secret_name = rancher2_cloud_credential.rancher2_cloud_credential.id control_plane_role = true etcd_role = false worker_role = false quantity = 1 machine_config { kind = rancher2_machine_config_v2.rancher2_machine_config_v2.kind name = rancher2_machine_config_v2.rancher2_machine_config_v2.name } } machine_pools { name = "pool3" cloud_credential_secret_name = rancher2_cloud_credential.rancher2_cloud_credential.id control_plane_role = false etcd_role = false worker_role = true quantity = 1 machine_config { kind = rancher2_machine_config_v2.rancher2_machine_config_v2.kind name = rancher2_machine_config_v2.rancher2_machine_config_v2.name } } } }

2. Reproduced - value defaults to `docker-user`

Screenshot:
![Screenshot 2023-06-14 at 2 41 41 PM](https://github.com/rancher/terraform-provider-rancher2/assets/46494969/9c253e0e-298d-45fa-a94d-1a3e83f41270)

---

Verified (locally) with rancher2 TFP `v3.1.0-rc1`:
1. Using (local) rancher2 provider `v3.1.0-rc1` and the `main.tf` file provided below, run `terraform apply` and observe the default value assigned to `digitalocean_config > userdata`:
```terraform
terraform {
  required_providers {
    rancher2 = {
      source  = "terraform.local/local/rancher2"
      version = "3.1.0-rc1"
    }
  }
}

provider "rancher2" {
  api_url   = "<REDACTED>"
  token_key = "<REDACTED>"
  insecure  = true
}

resource "rancher2_cloud_credential" "rancher2_cloud_credential" {
  name = "tf-do"
  digitalocean_credential_config {
    access_token = "<REDACTED>"
  }
}

resource "rancher2_machine_config_v2" "rancher2_machine_config_v2" {
  generate_name = "terratest"
  digitalocean_config {
    access_token = "<REDACTED>"
  }
}

resource "rancher2_cluster_v2" "rancher2_cluster_v2" {
  name                                     = "jkeslar3my2"
  kubernetes_version                       = "v1.26.5+rke2r1"
  enable_network_policy                    = false
  default_cluster_role_for_project_members = "user"
  rke_config {
    machine_pools {
      name                         = "pool1"
      cloud_credential_secret_name = rancher2_cloud_credential.rancher2_cloud_credential.id
      control_plane_role           = false
      etcd_role                    = true
      worker_role                  = false
      quantity                     = 1
      machine_config {
        kind = rancher2_machine_config_v2.rancher2_machine_config_v2.kind
        name = rancher2_machine_config_v2.rancher2_machine_config_v2.name
      }
    }
    machine_pools {
      name                         = "pool2"
      cloud_credential_secret_name = rancher2_cloud_credential.rancher2_cloud_credential.id
      control_plane_role           = true
      etcd_role                    = false
      worker_role                  = false
      quantity                     = 1
      machine_config {
        kind = rancher2_machine_config_v2.rancher2_machine_config_v2.kind
        name = rancher2_machine_config_v2.rancher2_machine_config_v2.name
      }
    }
    machine_pools {
      name                         = "pool3"
      cloud_credential_secret_name = rancher2_cloud_credential.rancher2_cloud_credential.id
      control_plane_role           = false
      etcd_role                    = false
      worker_role                  = true
      quantity                     = 1
      machine_config {
        kind = rancher2_machine_config_v2.rancher2_machine_config_v2.kind
        name = rancher2_machine_config_v2.rancher2_machine_config_v2.name
      }
    }
  }
}

2 Verified - no value assigned; as expected

Screenshot:

Screenshot 2023-06-14 at 2 56 46 PM