Skip to content

using (tftypes.Types).Equal to check for Type change doesn't work as expected. #392

Open
@BBBmau

Description

@BBBmau

This occurs when checking for a Type change between two configs that share have different values but still share the same type. Despite this it still returns the wrong bool.

["test"] -> ["test", "test2"] causes Equal() to return false despite the Type being the same

Using Diff instead results in the expected output of no type being present.

terraform-plugin-go version

v0.20.0

Relevant provider source code

// resulted in type change despite the types staying the same
typeChanged := !(wasCfg.(tftypes.Value).Type().Equal(nowCfg.(tftypes.Value).Type()))

// produced diff == nil since no type change was present (same tfconfig used)
_, diff := wasCfg.(tftypes.Value).Diff(nowCfg.(tftypes.Value))

Terraform Configuration Files

resource "kubernetes_manifest" "raw" {
  field_manager {
    name            = "tf-argo-app"
    # force_conflicts = true
  }


  timeouts {
    create = "10m"
    update = "10m"
    delete = "10m"
  }

  manifest = {
    apiVersion = "argoproj.io/v1alpha1"
    kind       = "Application"

    metadata = {
      name        = "unknown-test"
      namespace   = "argocd"
    }

    spec = {
      project = ""
      destination = {
        server    = "testcluster"
        namespace = "argocd"
      }
      revisionHistoryLimit = 1
//
      sources = [{
        repoURL        = "https://helm.releases.hashicorp.com"
        path           = "hashicorp/terraform"
        chart          = "terraform-helm"
        targetRevision = 10
        helm = {
          releaseName = "test"
          values = "test"
          valuesObject = {
            duration    = 2
            maxDuration = 5
            factor      = "2"
          }
        }
      }
      ,
      {
        repoURL        = "https://helm.releases.hashicorp.com"
        chart          = "terraform-helm"
        targetRevision = 1
        helm = {
          releaseName = "test"
          values = "test"
          valuesObject = {
            "mau": ["test"] // make changes here such as add or removing elements from tuple
            }
        }
      }]
//
      syncPolicy = {
        retry = {
          limit = 10
          backoff = {
            duration    = "2m"
            maxDuration = "5m"
            factor      = 2
          }
        }
      }
    }
  }
}

Expected Behavior

Should have returned that no type change was present

Actual Behavior

Type change was present when adding/removing from the tuple.

Steps to Reproduce

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

  1. terraform init
  2. terraform apply
  3. add or remove from tuple that's commented in config

The change will be reproducible once this PR is merged. hashicorp/terraform-provider-kubernetes#2437

A simpler config can be used, the provided config was the one that was first brought to attention the different behavior of Equal() and Diff()

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions