terraform-provider-argocd icon indicating copy to clipboard operation
terraform-provider-argocd copied to clipboard

source.directory not diffing correctly

Open sidewinder12s opened this issue 2 years ago • 4 comments

Terraform Version, ArgoCD Provider Version and ArgoCD Version

Terraform v1.3.6
on linux_amd64
+ provider registry.terraform.io/oboukili/argocd v6.0.3

argocd: 2.7.14

Affected Resource(s)

argocd_application

Terraform Configuration Files

resource "argocd_application" "extras" {
  cascade = false
  wait    = false

  metadata {
    name      = "${local.account_name}-${module.eks.cluster_name}-extras"
    namespace = "argocd"
  }

  spec {
    project                = "${var.argocd_project}-extended"
    revision_history_limit = 0
    destination {
      server    = module.eks.cluster_endpoint
      namespace = "default"
    }

    source {
      repo_url        = "https://github.com/my-repo.git"
      path            = "mypath/"
      target_revision = "master"
      directory {
        include = "*.yaml"
      }
    }
    sync_policy {
      automated {
        prune     = false
        self_heal = false
      }
      sync_options = [
        "ApplyOutOfSyncOnly=true"
      ]
    }
  }
}

Steps to Reproduce

Take a standard directory based argocd application without the directory param set in the terraform HCL or in the app manifest, add directory and includes

Expected Behavior

The provider should have added to the source block:

directory:
  include: '*.yaml'

Actual Behavior

No diff reported

References

By default ArgoCD will infer directory if you just provide a source path in a repo, though we recently hit a bug with configuration mangement plugin resolution that can be avoided if you explicitly put directory, helm, kustomize in the app manifest to avoid the plugin resolution.

https://github.com/argoproj/argo-cd/issues/15763

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

sidewinder12s avatar Oct 18 '23 22:10 sidewinder12s

Just tried to reproduce the bug with v6.1.1 and it's still possible to reproduce it.

I used the following snippet:

terraform {
  required_providers {
    argocd = {
      source = "oboukili/argocd"
    }
  }
}

provider "argocd" {
  server_addr = "localhost:8080"
  username    = "admin"
  password    = "acceptancetesting"
  insecure    = true
}

resource "argocd_application" "extras" {
  cascade = false
  wait    = false

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

  spec {
    project                = "default"
    revision_history_limit = 0
    destination {
      server    = "https://kubernetes.default.svc"
      namespace = "default"
    }

    source {
      repo_url        = "https://github.com/argoproj/argocd-example-apps.git"
      path            = "guestbook/"
      target_revision = "master"
      directory {
        include = "*.yaml"
      }
    }
  }
}

As far as I can see the problem is that https://github.com/oboukili/terraform-provider-argocd/blob/master/argocd/schema_application.go#L165-L171 suppresses a diff when recurse or jsonnet fields aren't populated. Looking back at https://github.com/oboukili/terraform-provider-argocd/pull/254 I think since the implementation of include and exclude this check is obsolete now or has to be extended to check for the presece of include/exclude as well.

I did a simple test by chaning the diff function (see here) and that would fix the issue and properly configure the include key. But still when rerunning Terraform the plan now shows a diff for spec.source.directory.include where I'm not quite sure where this comes from...

the-technat avatar Apr 03 '24 15:04 the-technat