Skip to content

Commit 6e7334d

Browse files
authored
feat(argocd_application): add support for Helm file parameters (#293)
1 parent 591b7d7 commit 6e7334d

File tree

5 files changed

+596
-1
lines changed

5 files changed

+596
-1
lines changed

argocd/resource_argocd_application_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,20 @@ ingress:
135135
})
136136
}
137137

138+
func TestAccArgoCDApplication_Helm_FileParameters(t *testing.T) {
139+
resource.ParallelTest(t, resource.TestCase{
140+
PreCheck: func() { testAccPreCheck(t) },
141+
ProviderFactories: testAccProviders,
142+
Steps: []resource.TestStep{
143+
{
144+
Config: testAccArgoCDApplicationHelm_FileParameters(acctest.RandomWithPrefix("test-acc")),
145+
// Setting up tests for this is non-trivial so it is easier to test for an expected failure (since file does not exist) than to test for success
146+
ExpectError: regexp.MustCompile(`(?s)Error: failed parsing.*--set-file data`),
147+
},
148+
},
149+
})
150+
}
151+
138152
func TestAccArgoCDApplication_Kustomize(t *testing.T) {
139153
resource.ParallelTest(t, resource.TestCase{
140154
PreCheck: func() { testAccPreCheck(t) },
@@ -1127,6 +1141,41 @@ EOT
11271141
`, name, helmValues)
11281142
}
11291143

1144+
func testAccArgoCDApplicationHelm_FileParameters(name string) string {
1145+
return fmt.Sprintf(`
1146+
resource "argocd_application" "helm_file_parameters" {
1147+
metadata {
1148+
name = "%[1]s"
1149+
namespace = "argocd"
1150+
}
1151+
1152+
spec {
1153+
source {
1154+
repo_url = "https://raw.githubusercontent.com/bitnami/charts/archive-full-index/bitnami"
1155+
chart = "redis"
1156+
target_revision = "16.9.11"
1157+
1158+
helm {
1159+
release_name = "testing"
1160+
file_parameter {
1161+
name = "foo"
1162+
path = "does-not-exist.txt"
1163+
}
1164+
}
1165+
}
1166+
1167+
sync_policy {
1168+
sync_options = ["CreateNamespace=true"]
1169+
}
1170+
1171+
destination {
1172+
server = "https://kubernetes.default.svc"
1173+
namespace = "%[1]s"
1174+
}
1175+
}
1176+
}`, name)
1177+
}
1178+
11301179
func testAccArgoCDApplicationKustomize(name string) string {
11311180
return fmt.Sprintf(`
11321181
resource "argocd_application" "kustomize" {

argocd/schema_application.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,6 +1354,25 @@ func applicationSpecSchemaV4(allOptional bool) *schema.Schema {
13541354
},
13551355
},
13561356
},
1357+
"file_parameter": {
1358+
Type: schema.TypeSet,
1359+
Description: "File parameters for the helm template.",
1360+
Optional: true,
1361+
Elem: &schema.Resource{
1362+
Schema: map[string]*schema.Schema{
1363+
"name": {
1364+
Type: schema.TypeString,
1365+
Description: "Name of the Helm parameter.",
1366+
Required: true,
1367+
},
1368+
"path": {
1369+
Type: schema.TypeString,
1370+
Description: "Path to the file containing the values for the Helm parameter.",
1371+
Required: true,
1372+
},
1373+
},
1374+
},
1375+
},
13571376
"release_name": {
13581377
Type: schema.TypeString,
13591378
Description: "Helm release name. If omitted it will use the application name.",

argocd/structure_application.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,24 @@ func expandApplicationSourceHelm(in []interface{}) *application.ApplicationSourc
289289
}
290290
}
291291

292+
if fileParameters, ok := a["file_parameter"]; ok {
293+
for _, _p := range fileParameters.(*schema.Set).List() {
294+
p := _p.(map[string]interface{})
295+
296+
parameter := application.HelmFileParameter{}
297+
298+
if v, ok := p["name"]; ok {
299+
parameter.Name = v.(string)
300+
}
301+
302+
if v, ok := p["path"]; ok {
303+
parameter.Path = v.(string)
304+
}
305+
306+
result.FileParameters = append(result.FileParameters, parameter)
307+
}
308+
}
309+
292310
if v, ok := a["skip_crds"]; ok {
293311
result.SkipCrds = v.(bool)
294312
}
@@ -726,8 +744,17 @@ func flattenApplicationSourceHelm(as []*application.ApplicationSourceHelm) (resu
726744
})
727745
}
728746

747+
var fileParameters []map[string]interface{}
748+
for _, p := range a.FileParameters {
749+
fileParameters = append(fileParameters, map[string]interface{}{
750+
"name": p.Name,
751+
"path": p.Path,
752+
})
753+
}
754+
729755
result = append(result, map[string]interface{}{
730756
"parameter": parameters,
757+
"file_parameter": fileParameters,
731758
"release_name": a.ReleaseName,
732759
"skip_crds": a.SkipCrds,
733760
"value_files": a.ValueFiles,
@@ -738,7 +765,7 @@ func flattenApplicationSourceHelm(as []*application.ApplicationSourceHelm) (resu
738765
}
739766
}
740767

741-
return
768+
return result
742769
}
743770

744771
func flattenApplicationDestinations(ds []application.ApplicationDestination) (result []map[string]string) {

docs/resources/application.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ Optional:
290290

291291
Optional:
292292

293+
- `file_parameter` (Block Set) File parameters for the helm template. (see [below for nested schema](#nestedblock--spec--source--helm--file_parameter))
293294
- `ignore_missing_value_files` (Boolean) Prevents 'helm template' from failing when `value_files` do not exist locally by not appending them to 'helm template --values'.
294295
- `parameter` (Block Set) Helm parameters which are passed to the helm template command upon manifest generation. (see [below for nested schema](#nestedblock--spec--source--helm--parameter))
295296
- `pass_credentials` (Boolean) If true then adds '--pass-credentials' to Helm commands to pass credentials to all domains.
@@ -298,6 +299,15 @@ Optional:
298299
- `value_files` (List of String) List of Helm value files to use when generating a template.
299300
- `values` (String) Helm values to be passed to 'helm template', typically defined as a block.
300301

302+
<a id="nestedblock--spec--source--helm--file_parameter"></a>
303+
### Nested Schema for `spec.source.helm.file_parameter`
304+
305+
Required:
306+
307+
- `name` (String) Name of the Helm parameter.
308+
- `path` (String) Path to the file containing the values for the Helm parameter.
309+
310+
301311
<a id="nestedblock--spec--source--helm--parameter"></a>
302312
### Nested Schema for `spec.source.helm.parameter`
303313

0 commit comments

Comments
 (0)