Skip to content

Commit 38a00f8

Browse files
authored
Add support for "Helm value files from external Git repository" (#280)
* 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`
1 parent ac65e67 commit 38a00f8

File tree

5 files changed

+147
-0
lines changed

5 files changed

+147
-0
lines changed

argocd/resource_argocd_application_test.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,6 +1026,44 @@ func TestAccArgoCDApplication_MultipleSources(t *testing.T) {
10261026
})
10271027
}
10281028

1029+
func TestAccArgoCDApplication_HelmValuesFromExternalGitRepo(t *testing.T) {
1030+
resource.ParallelTest(t, resource.TestCase{
1031+
PreCheck: func() { testAccPreCheck(t); testAccPreCheckFeatureSupported(t, featureMultipleApplicationSources) },
1032+
ProviderFactories: testAccProviders,
1033+
Steps: []resource.TestStep{
1034+
{
1035+
Config: testAccArgoCDApplicationHelmValuesFromExternalGitRepo(),
1036+
Check: resource.ComposeTestCheckFunc(
1037+
resource.TestCheckResourceAttrSet(
1038+
"argocd_application.helm_values_external",
1039+
"metadata.0.uid",
1040+
),
1041+
resource.TestCheckResourceAttr(
1042+
"argocd_application.helm_values_external",
1043+
"spec.0.source.0.chart",
1044+
"wordpress",
1045+
),
1046+
resource.TestCheckResourceAttrSet(
1047+
"argocd_application.helm_values_external",
1048+
"spec.0.source.0.helm.0.value_files.#",
1049+
),
1050+
resource.TestCheckResourceAttr(
1051+
"argocd_application.helm_values_external",
1052+
"spec.0.source.1.ref",
1053+
"values",
1054+
),
1055+
),
1056+
},
1057+
{
1058+
ResourceName: "argocd_application.helm_values_external",
1059+
ImportState: true,
1060+
ImportStateVerify: true,
1061+
ImportStateVerifyIgnore: []string{"wait", "cascade", "metadata.0.generation", "metadata.0.resource_version"},
1062+
},
1063+
},
1064+
})
1065+
}
1066+
10291067
func TestAccArgoCDApplication_Wait(t *testing.T) {
10301068
chartRevision := "9.4.1"
10311069
name := acctest.RandomWithPrefix("test-acc")
@@ -2050,6 +2088,40 @@ resource "argocd_application" "multiple_sources" {
20502088
}`
20512089
}
20522090

2091+
func testAccArgoCDApplicationHelmValuesFromExternalGitRepo() string {
2092+
return `
2093+
resource "argocd_application" "helm_values_external" {
2094+
metadata {
2095+
name = "helm-values-external"
2096+
namespace = "argocd"
2097+
}
2098+
2099+
spec {
2100+
project = "default"
2101+
2102+
source {
2103+
repo_url = "https://charts.helm.sh/stable"
2104+
chart = "wordpress"
2105+
target_revision = "9.0.3"
2106+
helm {
2107+
value_files = ["$values/helm-dependency/values.yaml"]
2108+
}
2109+
}
2110+
2111+
source {
2112+
repo_url = "https://github.com/argoproj/argocd-example-apps.git"
2113+
target_revision = "HEAD"
2114+
ref = "values"
2115+
}
2116+
2117+
destination {
2118+
server = "https://kubernetes.default.svc"
2119+
namespace = "default"
2120+
}
2121+
}
2122+
}`
2123+
}
2124+
20532125
func testAccSkipFeatureIgnoreDiffJQPathExpressions() (bool, error) {
20542126
ctx := context.Background()
20552127

argocd/schema_application.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,11 @@ func applicationSpecSchemaV4() *schema.Schema {
12901290
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.",
12911291
Optional: true,
12921292
},
1293+
"ref": {
1294+
Type: schema.TypeString,
1295+
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`.",
1296+
Optional: true,
1297+
},
12931298
"chart": {
12941299
Type: schema.TypeString,
12951300
Description: "Helm chart name. Must be specified for applications sourced from a Helm repo.",

argocd/structure_application.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ func expandApplicationSource(_ass []interface{}) []application.ApplicationSource
8080
s.Path = v.(string)
8181
}
8282

83+
if v, ok := as["ref"]; ok {
84+
s.Ref = v.(string)
85+
}
86+
8387
if v, ok := as["target_revision"]; ok {
8488
s.TargetRevision = v.(string)
8589
}
@@ -639,6 +643,7 @@ func flattenApplicationSource(source []application.ApplicationSource) (
639643
"plugin": flattenApplicationSourcePlugin(
640644
[]*application.ApplicationSourcePlugin{s.Plugin},
641645
),
646+
"ref": s.Ref,
642647
"repo_url": s.RepoURL,
643648
"target_revision": s.TargetRevision,
644649
})

docs/resources/application.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,38 @@ resource "argocd_application" "helm" {
131131
}
132132
}
133133
}
134+
135+
# Multiple Application Sources with Helm value files from external Git repository
136+
resource "argocd_application" "multiple_sources" {
137+
metadata {
138+
name = "helm-app-with-external-values"
139+
namespace = "argocd"
140+
}
141+
142+
spec {
143+
project = "default"
144+
145+
source {
146+
repo_url = "https://charts.helm.sh/stable"
147+
chart = "wordpress"
148+
target_revision = "9.0.3"
149+
helm {
150+
value_files = ["$values/helm-dependency/values.yaml"]
151+
}
152+
}
153+
154+
source {
155+
repo_url = "https://github.com/argoproj/argocd-example-apps.git"
156+
target_revision = "HEAD"
157+
ref = "values"
158+
}
159+
160+
destination {
161+
server = "https://kubernetes.default.svc"
162+
namespace = "default"
163+
}
164+
}
165+
}
134166
```
135167

136168
<!-- schema generated by tfplugindocs -->
@@ -209,6 +241,7 @@ Optional:
209241
- `kustomize` (Block List, Max: 1) Kustomize specific options. (see [below for nested schema](#nestedblock--spec--source--kustomize))
210242
- `path` (String) Directory path within the repository. Only valid for applications sourced from Git.
211243
- `plugin` (Block List, Max: 1) Config management plugin specific options. (see [below for nested schema](#nestedblock--spec--source--plugin))
244+
- `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`.
212245
- `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.
213246

214247
<a id="nestedblock--spec--source--directory"></a>

examples/resources/argocd_application/resource.tf

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,35 @@ resource "argocd_application" "helm" {
116116
}
117117
}
118118
}
119+
120+
# Multiple Application Sources with Helm value files from external Git repository
121+
resource "argocd_application" "multiple_sources" {
122+
metadata {
123+
name = "helm-app-with-external-values"
124+
namespace = "argocd"
125+
}
126+
127+
spec {
128+
project = "default"
129+
130+
source {
131+
repo_url = "https://charts.helm.sh/stable"
132+
chart = "wordpress"
133+
target_revision = "9.0.3"
134+
helm {
135+
value_files = ["$values/helm-dependency/values.yaml"]
136+
}
137+
}
138+
139+
source {
140+
repo_url = "https://github.com/argoproj/argocd-example-apps.git"
141+
target_revision = "HEAD"
142+
ref = "values"
143+
}
144+
145+
destination {
146+
server = "https://kubernetes.default.svc"
147+
namespace = "default"
148+
}
149+
}
150+
}

0 commit comments

Comments
 (0)