Kong / terraform-provider-konnect

Terraform Provider for Kong Konnect
https://registry.terraform.io/providers/kong/konnect/latest
21 stars 3 forks source link

Non Deterministic Terraform Plan when applying the same config #69

Closed rastogiji closed 2 days ago

rastogiji commented 3 weeks ago

When trying to create a child module to create CGW Dataplane nodes, I'm using the following resource block with appropriate variable defintions

resource "konnect_cloud_gateway_configuration" "cgw-nodes" {
  version           = var.dp_version
  api_access        = var.api_access
  control_plane_geo = var.cp_geo
  control_plane_id  = konnect_gateway_control_plane.cgw-cp.id

  dataplane_groups = [for dp in var.dataplane_groups : {
    provider = dp.provider
    region = dp.region
    cloud_gateway_network_id = konnect_cloud_gateway_network.cgw-ns[dp.ns_name].id
    autoscale = var.dp_kind == "autopilot" ? {
        configuration_data_plane_group_autoscale_autopilot = {
            kind = var.dp_kind
            base_rps = dp.autopilot.base_rps
            max_rps = dp.autopilot.max_rps
        }} : {
            configuration_data_plane_group_autoscale_static = {
                kind = var.dp_kind
                instance_type = dp.static.instance_type
                requested_instances = dp.static.requested_instances
            }
    }
  }]
}

And I'm declaring it in the root module like below:

dataplane_groups = [{
        provider = "aws",
        region = "us-east-2",
        ns_name = "aws-ns",
        static = {
            instance_type = "medium",
            requested_instances = 1
        }
    },{
        provider = "aws",
        region = "us-west-2",
        ns_name = "aws-ns-2",
        static = {
            instance_type = "large",
            requested_instances = 1
        }
    }]

However, once I do the first tf apply, the plan becomes non deterministic on the order of the individual dataplane group. Sometimes it complains that the configuration has changed and tries to do an update operation against the API which returns with an error of provided and current configuration is the same. The video below showcases the problem:

https://github.com/user-attachments/assets/29cf53ec-e1cb-4c47-84f6-b1634c3e3076

mheap commented 2 weeks ago

This is something that we need to fix in the generator.

Prior art:

https://github.com/hashicorp/terraform-provider-aws/issues/22274 https://github.com/Azure/terraform-provider-azapi/pull/455

mheap commented 2 weeks ago

Using format: set in the spec makes this a SetNestedAttribute rather than a ListNestedAttribute. Should be resolved once https://github.com/Kong/terraform-provider-konnect/commit/87a08d4656d1e38f2925d62c06f4cb62bcf1b649 is released