Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Application source paths should not default to "." when explicitly null or absent. #408

Open
samhine opened this issue Jul 14, 2024 · 2 comments
Labels
bug Something isn't working on-hold Issues or Pull Requests with this label will never be considered stale

Comments

@samhine
Copy link

samhine commented Jul 14, 2024

Terraform Version, ArgoCD Provider Version and ArgoCD Version

Terraform version: v1.9.2
ArgoCD provider version: 6.1.1
ArgoCD version: 6.10.0

Affected Resource(s)

  • argocd_application

Terraform Configuration Files

resource "argocd_application" "sample-application" {
  cascade = true
  wait    = false

  metadata {
    name             = "sample-application"
    namespace        = "argocd"
  }

  spec {
    project                = "root"
    revision_history_limit = 10

    destination {
      namespace = "sample-application"
      server    = "https://kubernetes.default.svc"
    }

    source {
      path            = null
      ref             = "values"
      repo_url        = "https://github.com/org/values-repo.git"
      target_revision = "main"
    }
    source {
      path            = "deploy"
      repo_url        = "https://github.com/org/chart-repo.git"
      target_revision = "main"

      helm {
        value_files = [
            "$values/projects/project/clusters/cluster/application-values/sample-application/values.yaml",
          ]
      }
    }
  }
}

Steps to Reproduce

  1. terraform plan or terraform apply

Plan output:

# argocd_application.sample-application will be created
  + resource "argocd_application" "sample-application" {
      + cascade = true
      + id      = (known after apply)
      + status  = (known after apply)
      + wait    = false

      + metadata {
          + generation       = (known after apply)
          + name             = "sample-application"
          + namespace        = "argocd"
          + resource_version = (known after apply)
          + uid              = (known after apply)
        }

      + spec {
          + project                = "root"
          + revision_history_limit = 10

          + destination {
                name      = null
              + namespace = "sample-application"
              + server    = "https://kubernetes.default.svc"
            }

          + source {
              + path            = "."      <------ This should not be the case!! 
              + ref             = "values"
              + repo_url        = "https://github.com/org/values-repo.git"
              + target_revision = "main"
            }
          + source {
              + path            = "deploy"
              + repo_url        = "https://github.com/org/chart-repo.git"
              + target_revision = "main"

              + helm {
                  + value_files = [
                      + "$values/projects/project/clusters/cluster/application-values/sample-application/values.yaml",
                    ]
                }
            }
        }
    }

Expected Behavior

Terraform should not attempt to add a path to the source where it is absent, or explicitly null.

Otherwise, ArgoCD will attempt to deploy any YAML resources found at the source repository. This behaviour is documented in ArgoCD's documentation - https://argo-cd.readthedocs.io/en/stable/user-guide/multiple_sources/#helm-value-files-from-external-git-repository.

If the path field is set in the $values source, Argo CD will attempt to generate resources from the git repository at that URL. If the path field is not set, Argo CD will use the repository solely as a source of value files.

Currently - since path defaults to ".", this provider always instantiates applications which attempt to deploy any resources at this path (in my case, I have a Backstage definition file which uses the CRD format, which ArgoCD attempts to deploy).

Actual Behavior

The path index should be absent within the application source block. I can edit my applications once deployed to remove this - and everything works as expected.

I believe this is due to the default currently set within the application schema here.

Workaround

It's possible to simply specify a path that does not contain a YAML resource, since this is a non-op. For example, setting path to .git means that ArgoCD does not find any YAML resources and continues as normal, however this is not ideal for a few obvious reasons.

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
@samhine samhine added the bug Something isn't working label Jul 14, 2024
Copy link

github-actions bot commented Oct 2, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the Stale label Oct 2, 2024
@mkilchhofer
Copy link
Collaborator

mkilchhofer commented Oct 4, 2024

First I thought you're doing something unsupported:
image

But when I read the docs it seems that this is a new feature of Argo CD called "multi source app".

image

And indeed this change resp. feature was not reflected into the terraform provider:

"path": {
Type: schema.TypeString,
Description: "Directory path within the repository. Only valid for applications sourced from Git.",
Optional: true,
// TODO: add validator to test path is not absolute
Default: ".",
},

@mkilchhofer mkilchhofer added on-hold Issues or Pull Requests with this label will never be considered stale and removed Stale labels Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working on-hold Issues or Pull Requests with this label will never be considered stale
Projects
None yet
Development

No branches or pull requests

2 participants