ovh / terraform-provider-ovh

Terraform OVH provider
https://registry.terraform.io/providers/ovh/ovh/latest/docs
Mozilla Public License 2.0
182 stars 133 forks source link

[BUG] `ovh_cloud_project_kube` requires `load_balancers_subnet_id` but doesn't properly update it on the resource #683

Closed david-jointech closed 1 month ago

david-jointech commented 1 month ago

Describe the bug

After upgrading the provider from 0.43.1 to 0.46.1, a plan on our ovh_cloud_project_kube resource resulted in the following error:

│ Error: Missing required argument
│
│   with ovh_cloud_project_kube.main,
│   on ovh-cluster.tf line 6, in resource "ovh_cloud_project_kube" "main":
│    6:   private_network_id = tolist(ovh_cloud_project_network_private.net.regions_attributes[*].openstackid)[0]
│
│ "private_network_id": all of `load_balancers_subnet_id,private_network_id` must be specified

The used configuration looked like this:

resource "ovh_cloud_project_kube" "main" {
  service_name             = local.service_name
  name                     = "${var.stage}-k8s"
  region                   = local.stage_config[var.stage].location
  version                  = local.stage_config[var.stage].version
  private_network_id       = tolist(ovh_cloud_project_network_private.net.regions_attributes[*].openstackid)[0]
  depends_on = [
    ovh_cloud_project_network_private.net
  ]
}

I modified the resource, to include the load_balancers_subnet_id as follows:

resource "ovh_cloud_project_kube" "main" {
  service_name             = local.service_name
  name                     = "${var.stage}-k8s"
  region                   = local.stage_config[var.stage].location
  version                  = local.stage_config[var.stage].version
  load_balancers_subnet_id = ovh_cloud_project_network_private_subnet.subnet.id
  private_network_id       = tolist(ovh_cloud_project_network_private.net.regions_attributes[*].openstackid)[0]
  depends_on = [
    ovh_cloud_project_network_private.net
  ]
}

Then running plan and apply successfully finishes. But when running a plan afterwards, the resource wants to update again:

OpenTofu will perform the following actions:

  # ovh_cloud_project_kube.main will be updated in-place
  ~ resource "ovh_cloud_project_kube" "main" {
        id                          = "f1b8dd51-f77c-4c48-8c34-15ee13fc576a"
      + load_balancers_subnet_id    = "9045d2ab-f5b5-4792-9771-fa8c1f12ed99"
        name                        = "dev-k8s"
        # (15 unchanged attributes hidden)

        # (1 unchanged block hidden)
    }

Here I'd expect no changes to be planned.

First of all, from the documentation it's unclear to me, that load_balancers_subnet_id is required, when private_network_id is set, the last example in the documentation even uses the private_network_id without the load_balancers_subnet_id. It's also slightly unclear to me, which effect the load_balancers_subnet_id will have, though I assume it's not about the external IP of the loadbalancer. Though then I'd assume the nodes_subnet_id should be used here?

Secondly, applying the change to load_balancers_subnet_id doesn't actually seem to have an effect.

Terraform Version

OpenTofu v1.7.0-alpha1

OVH Terraform Provider Version

v0.46.1

Affected Resource(s)

Terraform Configuration Files

relevant part is:

resource "ovh_cloud_project_kube" "main" {
  service_name             = local.service_name
  name                     = "${var.stage}-k8s"
  region                   = local.stage_config[var.stage].location
  version                  = local.stage_config[var.stage].version
  load_balancers_subnet_id = ovh_cloud_project_network_private_subnet.subnet.id
  private_network_id       = tolist(ovh_cloud_project_network_private.net.regions_attributes[*].openstackid)[0]
  depends_on = [
    ovh_cloud_project_network_private.net
  ]
}

Expected Behavior

  1. I'm unsure if load_balancers_subnet_id should actually be required when using private_network_id. Documentation should reflect this requirement.
  2. The resource should be actually updated when setting load_balancers_subnet_id and not produce planned changes on every run.

Actual Behavior

Regarding 1 using private_network_id without load_balancers_subnet_id produces an error. Regarding 2, the resource is unchanged after applying.

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform plan -out planfile on the first configuration. Error should appear
  2. add load_balancers_subnet_id to configuration
  3. terraform plan -out planfile should work without errors
  4. terraform apply planfile should run succesfully
  5. terraform plan -out planfile will plan the change on the resource again
mwacker-sms commented 1 month ago

ran into the same issue here...