Skip to content

Commit

Permalink
Add support for "Helm value files from external Git repository" (#280)
Browse files Browse the repository at this point in the history
* tests: run `TestAccArgoCDProjectToken_RenewAfter` in serial

Since this test is time sensitive we don't want steps/checks running in parallel since this causes flakiness as the token may need to be renewed by the time Terraform checks that the apply results in a subsequent non-empty plan.

* feat: add `ref` to `argocd_application.spec.source`
  • Loading branch information
onematchfox authored May 24, 2023
1 parent ac65e67 commit 38a00f8
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 0 deletions.
72 changes: 72 additions & 0 deletions argocd/resource_argocd_application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,44 @@ func TestAccArgoCDApplication_MultipleSources(t *testing.T) {
})
}

func TestAccArgoCDApplication_HelmValuesFromExternalGitRepo(t *testing.T) {
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPreCheckFeatureSupported(t, featureMultipleApplicationSources) },
ProviderFactories: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccArgoCDApplicationHelmValuesFromExternalGitRepo(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(
"argocd_application.helm_values_external",
"metadata.0.uid",
),
resource.TestCheckResourceAttr(
"argocd_application.helm_values_external",
"spec.0.source.0.chart",
"wordpress",
),
resource.TestCheckResourceAttrSet(
"argocd_application.helm_values_external",
"spec.0.source.0.helm.0.value_files.#",
),
resource.TestCheckResourceAttr(
"argocd_application.helm_values_external",
"spec.0.source.1.ref",
"values",
),
),
},
{
ResourceName: "argocd_application.helm_values_external",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"wait", "cascade", "metadata.0.generation", "metadata.0.resource_version"},
},
},
})
}

func TestAccArgoCDApplication_Wait(t *testing.T) {
chartRevision := "9.4.1"
name := acctest.RandomWithPrefix("test-acc")
Expand Down Expand Up @@ -2050,6 +2088,40 @@ resource "argocd_application" "multiple_sources" {
}`
}

func testAccArgoCDApplicationHelmValuesFromExternalGitRepo() string {
return `
resource "argocd_application" "helm_values_external" {
metadata {
name = "helm-values-external"
namespace = "argocd"
}
spec {
project = "default"
source {
repo_url = "https://charts.helm.sh/stable"
chart = "wordpress"
target_revision = "9.0.3"
helm {
value_files = ["$values/helm-dependency/values.yaml"]
}
}
source {
repo_url = "https://github.com/argoproj/argocd-example-apps.git"
target_revision = "HEAD"
ref = "values"
}
destination {
server = "https://kubernetes.default.svc"
namespace = "default"
}
}
}`
}

func testAccSkipFeatureIgnoreDiffJQPathExpressions() (bool, error) {
ctx := context.Background()

Expand Down
5 changes: 5 additions & 0 deletions argocd/schema_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,11 @@ func applicationSpecSchemaV4() *schema.Schema {
Description: "Revision of the source to sync the application to. In case of Git, this can be commit, tag, or branch. If omitted, will equal to HEAD. In case of Helm, this is a semver tag for the Chart's version.",
Optional: true,
},
"ref": {
Type: schema.TypeString,
Description: "Reference to another `source` within defined sources. See associated documentation on [Helm value files from external Git repository](https://argo-cd.readthedocs.io/en/stable/user-guide/multiple_sources/#helm-value-files-from-external-git-repository) regarding combining `ref` with `path` and/or `chart`.",
Optional: true,
},
"chart": {
Type: schema.TypeString,
Description: "Helm chart name. Must be specified for applications sourced from a Helm repo.",
Expand Down
5 changes: 5 additions & 0 deletions argocd/structure_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ func expandApplicationSource(_ass []interface{}) []application.ApplicationSource
s.Path = v.(string)
}

if v, ok := as["ref"]; ok {
s.Ref = v.(string)
}

if v, ok := as["target_revision"]; ok {
s.TargetRevision = v.(string)
}
Expand Down Expand Up @@ -639,6 +643,7 @@ func flattenApplicationSource(source []application.ApplicationSource) (
"plugin": flattenApplicationSourcePlugin(
[]*application.ApplicationSourcePlugin{s.Plugin},
),
"ref": s.Ref,
"repo_url": s.RepoURL,
"target_revision": s.TargetRevision,
})
Expand Down
33 changes: 33 additions & 0 deletions docs/resources/application.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,38 @@ resource "argocd_application" "helm" {
}
}
}
# Multiple Application Sources with Helm value files from external Git repository
resource "argocd_application" "multiple_sources" {
metadata {
name = "helm-app-with-external-values"
namespace = "argocd"
}
spec {
project = "default"
source {
repo_url = "https://charts.helm.sh/stable"
chart = "wordpress"
target_revision = "9.0.3"
helm {
value_files = ["$values/helm-dependency/values.yaml"]
}
}
source {
repo_url = "https://github.com/argoproj/argocd-example-apps.git"
target_revision = "HEAD"
ref = "values"
}
destination {
server = "https://kubernetes.default.svc"
namespace = "default"
}
}
}
```

<!-- schema generated by tfplugindocs -->
Expand Down Expand Up @@ -209,6 +241,7 @@ Optional:
- `kustomize` (Block List, Max: 1) Kustomize specific options. (see [below for nested schema](#nestedblock--spec--source--kustomize))
- `path` (String) Directory path within the repository. Only valid for applications sourced from Git.
- `plugin` (Block List, Max: 1) Config management plugin specific options. (see [below for nested schema](#nestedblock--spec--source--plugin))
- `ref` (String) Reference to another `source` within defined sources. See associated documentation on [Helm value files from external Git repository](https://argo-cd.readthedocs.io/en/stable/user-guide/multiple_sources/#helm-value-files-from-external-git-repository) regarding combining `ref` with `path` and/or `chart`.
- `target_revision` (String) Revision of the source to sync the application to. In case of Git, this can be commit, tag, or branch. If omitted, will equal to HEAD. In case of Helm, this is a semver tag for the Chart's version.

<a id="nestedblock--spec--source--directory"></a>
Expand Down
32 changes: 32 additions & 0 deletions examples/resources/argocd_application/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,35 @@ resource "argocd_application" "helm" {
}
}
}

# Multiple Application Sources with Helm value files from external Git repository
resource "argocd_application" "multiple_sources" {
metadata {
name = "helm-app-with-external-values"
namespace = "argocd"
}

spec {
project = "default"

source {
repo_url = "https://charts.helm.sh/stable"
chart = "wordpress"
target_revision = "9.0.3"
helm {
value_files = ["$values/helm-dependency/values.yaml"]
}
}

source {
repo_url = "https://github.com/argoproj/argocd-example-apps.git"
target_revision = "HEAD"
ref = "values"
}

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

0 comments on commit 38a00f8

Please sign in to comment.