Skip to content

Commit 591b7d7

Browse files
B3ns44donematchfox
andauthored
Add support for ignoreMissingValueFiles helm application parameter (#292)
Co-authored-by: OneMatchFox <[email protected]>
1 parent 97892c3 commit 591b7d7

File tree

5 files changed

+224
-193
lines changed

5 files changed

+224
-193
lines changed

argocd/resource_argocd_application_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,16 @@ ingress:
113113
"spec.0.source.0.helm.0.value_files.0",
114114
"values.yaml",
115115
),
116+
resource.TestCheckResourceAttr(
117+
"argocd_application.helm",
118+
"spec.0.source.0.helm.0.pass_credentials",
119+
"true",
120+
),
121+
resource.TestCheckResourceAttr(
122+
"argocd_application.helm",
123+
"spec.0.source.0.helm.0.ignore_missing_value_files",
124+
"true",
125+
),
116126
),
117127
},
118128
{
@@ -1094,6 +1104,7 @@ resource "argocd_application" "helm" {
10941104
}
10951105
10961106
pass_credentials = true
1107+
ignore_missing_value_files = true
10971108
10981109
value_files = ["values.yaml"]
10991110

argocd/schema_application.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,7 +1322,12 @@ func applicationSpecSchemaV4(allOptional bool) *schema.Schema {
13221322
},
13231323
"values": {
13241324
Type: schema.TypeString,
1325-
Description: "Helm values to be passed to helm template, typically defined as a block.",
1325+
Description: "Helm values to be passed to 'helm template', typically defined as a block.",
1326+
Optional: true,
1327+
},
1328+
"ignore_missing_value_files": {
1329+
Type: schema.TypeBool,
1330+
Description: "Prevents 'helm template' from failing when `value_files` do not exist locally by not appending them to 'helm template --values'.",
13261331
Optional: true,
13271332
},
13281333
"parameter": {
@@ -1361,7 +1366,7 @@ func applicationSpecSchemaV4(allOptional bool) *schema.Schema {
13611366
},
13621367
"pass_credentials": {
13631368
Type: schema.TypeBool,
1364-
Description: "If true then adds --pass-credentials to Helm commands to pass credentials to all domains",
1369+
Description: "If true then adds '--pass-credentials' to Helm commands to pass credentials to all domains.",
13651370
Optional: true,
13661371
},
13671372
},

argocd/structure_application.go

Lines changed: 56 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,14 @@ import (
1111

1212
// Expand
1313

14-
func expandApplication(d *schema.ResourceData) (
15-
metadata meta.ObjectMeta,
16-
spec application.ApplicationSpec,
17-
err error) {
14+
func expandApplication(d *schema.ResourceData) (metadata meta.ObjectMeta, spec application.ApplicationSpec, err error) {
1815
metadata = expandMetadata(d)
1916
spec, err = expandApplicationSpec(d.Get("spec.0").(map[string]interface{}))
2017

2118
return
2219
}
2320

24-
func expandApplicationSpec(s map[string]interface{}) (
25-
spec application.ApplicationSpec,
26-
err error) {
21+
func expandApplicationSpec(s map[string]interface{}) (spec application.ApplicationSpec, err error) {
2722
if v, ok := s["project"]; ok {
2823
spec.Project = v.(string)
2924
}
@@ -125,12 +120,10 @@ func expandApplicationSourcePlugin(in []interface{}) *application.ApplicationSou
125120

126121
if env, ok := a["env"]; ok {
127122
for _, v := range env.(*schema.Set).List() {
128-
result.Env = append(result.Env,
129-
&application.EnvEntry{
130-
Name: v.(map[string]interface{})["name"].(string),
131-
Value: v.(map[string]interface{})["value"].(string),
132-
},
133-
)
123+
result.Env = append(result.Env, &application.EnvEntry{
124+
Name: v.(map[string]interface{})["name"].(string),
125+
Value: v.(map[string]interface{})["value"].(string),
126+
})
134127
}
135128
}
136129

@@ -165,27 +158,23 @@ func expandApplicationSourceDirectory(in interface{}) *application.ApplicationSo
165158
if evs, ok := j["ext_var"].([]interface{}); ok && len(evs) > 0 {
166159
for _, v := range evs {
167160
if vv, ok := v.(map[string]interface{}); ok {
168-
jsonnet.ExtVars = append(jsonnet.ExtVars,
169-
application.JsonnetVar{
170-
Name: vv["name"].(string),
171-
Value: vv["value"].(string),
172-
Code: vv["code"].(bool),
173-
},
174-
)
161+
jsonnet.ExtVars = append(jsonnet.ExtVars, application.JsonnetVar{
162+
Name: vv["name"].(string),
163+
Value: vv["value"].(string),
164+
Code: vv["code"].(bool),
165+
})
175166
}
176167
}
177168
}
178169

179170
if tlas, ok := j["tla"].(*schema.Set); ok && len(tlas.List()) > 0 {
180171
for _, v := range tlas.List() {
181172
if vv, ok := v.(map[string]interface{}); ok {
182-
jsonnet.TLAs = append(jsonnet.TLAs,
183-
application.JsonnetVar{
184-
Name: vv["name"].(string),
185-
Value: vv["value"].(string),
186-
Code: vv["code"].(bool),
187-
},
188-
)
173+
jsonnet.TLAs = append(jsonnet.TLAs, application.JsonnetVar{
174+
Name: vv["name"].(string),
175+
Value: vv["value"].(string),
176+
Code: vv["code"].(bool),
177+
})
189178
}
190179
}
191180
}
@@ -225,10 +214,7 @@ func expandApplicationSourceKustomize(in []interface{}) *application.Application
225214

226215
if v, ok := a["images"]; ok {
227216
for _, i := range v.(*schema.Set).List() {
228-
result.Images = append(
229-
result.Images,
230-
application.KustomizeImage(i.(string)),
231-
)
217+
result.Images = append(result.Images, application.KustomizeImage(i.(string)))
232218
}
233219
}
234220

@@ -277,6 +263,10 @@ func expandApplicationSourceHelm(in []interface{}) *application.ApplicationSourc
277263
result.PassCredentials = v.(bool)
278264
}
279265

266+
if v, ok := a["ignore_missing_value_files"]; ok {
267+
result.IgnoreMissingValueFiles = v.(bool)
268+
}
269+
280270
if parameters, ok := a["parameter"]; ok {
281271
for _, _p := range parameters.(*schema.Set).List() {
282272
p := _p.(map[string]interface{})
@@ -397,8 +387,7 @@ func expandApplicationSyncPolicy(sp interface{}) (*application.SyncPolicy, error
397387
return syncPolicy, nil
398388
}
399389

400-
func expandApplicationIgnoreDifferences(ids []interface{}) (
401-
result []application.ResourceIgnoreDifferences) {
390+
func expandApplicationIgnoreDifferences(ids []interface{}) (result []application.ResourceIgnoreDifferences) {
402391
for _, _id := range ids {
403392
id := _id.(map[string]interface{})
404393

@@ -440,8 +429,7 @@ func expandApplicationIgnoreDifferences(ids []interface{}) (
440429
return //nolint:nakedret // overriding as function follows pattern in rest of file
441430
}
442431

443-
func expandApplicationInfo(infos *schema.Set) (
444-
result []application.Info, err error) {
432+
func expandApplicationInfo(infos *schema.Set) (result []application.Info, err error) {
445433
for _, i := range infos.List() {
446434
item := i.(map[string]interface{})
447435
info := application.Info{}
@@ -475,8 +463,7 @@ func expandApplicationDestinations(ds *schema.Set) (result []application.Applica
475463
return
476464
}
477465

478-
func expandApplicationDestination(dest interface{}) (
479-
result application.ApplicationDestination) {
466+
func expandApplicationDestination(dest interface{}) (result application.ApplicationDestination) {
480467
d, ok := dest.(map[string]interface{})
481468
if !ok {
482469
panic(fmt.Errorf("could not expand application destination"))
@@ -493,18 +480,15 @@ func expandSyncWindows(sws []interface{}) (result []*application.SyncWindow) {
493480
for _, _sw := range sws {
494481
sw := _sw.(map[string]interface{})
495482

496-
result = append(
497-
result,
498-
&application.SyncWindow{
499-
Applications: expandStringList(sw["applications"].([]interface{})),
500-
Clusters: expandStringList(sw["clusters"].([]interface{})),
501-
Duration: sw["duration"].(string),
502-
Kind: sw["kind"].(string),
503-
ManualSync: sw["manual_sync"].(bool),
504-
Namespaces: expandStringList(sw["namespaces"].([]interface{})),
505-
Schedule: sw["schedule"].(string),
506-
},
507-
)
483+
result = append(result, &application.SyncWindow{
484+
Applications: expandStringList(sw["applications"].([]interface{})),
485+
Clusters: expandStringList(sw["clusters"].([]interface{})),
486+
Duration: sw["duration"].(string),
487+
Kind: sw["kind"].(string),
488+
ManualSync: sw["manual_sync"].(bool),
489+
Namespaces: expandStringList(sw["namespaces"].([]interface{})),
490+
Schedule: sw["schedule"].(string),
491+
})
508492
}
509493

510494
return
@@ -531,19 +515,15 @@ func flattenApplication(app *application.Application, d *schema.ResourceData) er
531515

532516
func flattenApplicationSpec(s application.ApplicationSpec) []map[string]interface{} {
533517
spec := map[string]interface{}{
534-
"destination": flattenApplicationDestinations(
535-
[]application.ApplicationDestination{s.Destination},
536-
),
518+
"destination": flattenApplicationDestinations([]application.ApplicationDestination{s.Destination}),
537519
"ignore_difference": flattenApplicationIgnoreDifferences(s.IgnoreDifferences),
538520
"info": flattenApplicationInfo(s.Info),
539521
"project": s.Project,
540522
"sync_policy": flattenApplicationSyncPolicy(s.SyncPolicy),
541523
}
542524

543525
if s.Source != nil {
544-
spec["source"] = flattenApplicationSource(
545-
[]application.ApplicationSource{*s.Source},
546-
)
526+
spec["source"] = flattenApplicationSource([]application.ApplicationSource{*s.Source})
547527
} else {
548528
spec["source"] = flattenApplicationSource(s.Sources)
549529
}
@@ -599,8 +579,7 @@ func flattenApplicationSyncPolicy(sp *application.SyncPolicy) []map[string]inter
599579
return []map[string]interface{}{result}
600580
}
601581

602-
func flattenApplicationInfo(infos []application.Info) (
603-
result []map[string]string) {
582+
func flattenApplicationInfo(infos []application.Info) (result []map[string]string) {
604583
for _, i := range infos {
605584
info := map[string]string{}
606585

@@ -618,8 +597,7 @@ func flattenApplicationInfo(infos []application.Info) (
618597
return
619598
}
620599

621-
func flattenApplicationIgnoreDifferences(ids []application.ResourceIgnoreDifferences) (
622-
result []map[string]interface{}) {
600+
func flattenApplicationIgnoreDifferences(ids []application.ResourceIgnoreDifferences) (result []map[string]interface{}) {
623601
for _, id := range ids {
624602
result = append(result, map[string]interface{}{
625603
"group": id.Group,
@@ -634,24 +612,15 @@ func flattenApplicationIgnoreDifferences(ids []application.ResourceIgnoreDiffere
634612
return
635613
}
636614

637-
func flattenApplicationSource(source []application.ApplicationSource) (
638-
result []map[string]interface{}) {
615+
func flattenApplicationSource(source []application.ApplicationSource) (result []map[string]interface{}) {
639616
for _, s := range source {
640617
result = append(result, map[string]interface{}{
641-
"chart": s.Chart,
642-
"directory": flattenApplicationSourceDirectory(
643-
[]*application.ApplicationSourceDirectory{s.Directory},
644-
),
645-
"helm": flattenApplicationSourceHelm(
646-
[]*application.ApplicationSourceHelm{s.Helm},
647-
),
648-
"kustomize": flattenApplicationSourceKustomize(
649-
[]*application.ApplicationSourceKustomize{s.Kustomize},
650-
),
651-
"path": s.Path,
652-
"plugin": flattenApplicationSourcePlugin(
653-
[]*application.ApplicationSourcePlugin{s.Plugin},
654-
),
618+
"chart": s.Chart,
619+
"directory": flattenApplicationSourceDirectory([]*application.ApplicationSourceDirectory{s.Directory}),
620+
"helm": flattenApplicationSourceHelm([]*application.ApplicationSourceHelm{s.Helm}),
621+
"kustomize": flattenApplicationSourceKustomize([]*application.ApplicationSourceKustomize{s.Kustomize}),
622+
"path": s.Path,
623+
"plugin": flattenApplicationSourcePlugin([]*application.ApplicationSourcePlugin{s.Plugin}),
655624
"ref": s.Ref,
656625
"repo_url": s.RepoURL,
657626
"target_revision": s.TargetRevision,
@@ -661,8 +630,7 @@ func flattenApplicationSource(source []application.ApplicationSource) (
661630
return
662631
}
663632

664-
func flattenApplicationSourcePlugin(as []*application.ApplicationSourcePlugin) (
665-
result []map[string]interface{}) {
633+
func flattenApplicationSourcePlugin(as []*application.ApplicationSourcePlugin) (result []map[string]interface{}) {
666634
for _, a := range as {
667635
if a != nil {
668636
var env []map[string]string
@@ -683,8 +651,7 @@ func flattenApplicationSourcePlugin(as []*application.ApplicationSourcePlugin) (
683651
return
684652
}
685653

686-
func flattenApplicationSourceDirectory(as []*application.ApplicationSourceDirectory) (
687-
result []map[string]interface{}) {
654+
func flattenApplicationSourceDirectory(as []*application.ApplicationSourceDirectory) (result []map[string]interface{}) {
688655
for _, a := range as {
689656
if a != nil && !a.IsZero() {
690657
jsonnet := make(map[string][]interface{}, 0)
@@ -725,8 +692,7 @@ func flattenApplicationSourceDirectory(as []*application.ApplicationSourceDirect
725692
return //nolint:nakedret // only just breaching - function follows pattern in rest of file
726693
}
727694

728-
func flattenApplicationSourceKustomize(as []*application.ApplicationSourceKustomize) (
729-
result []map[string]interface{}) {
695+
func flattenApplicationSourceKustomize(as []*application.ApplicationSourceKustomize) (result []map[string]interface{}) {
730696
for _, a := range as {
731697
if a != nil {
732698
var images []string
@@ -748,8 +714,7 @@ func flattenApplicationSourceKustomize(as []*application.ApplicationSourceKustom
748714
return
749715
}
750716

751-
func flattenApplicationSourceHelm(as []*application.ApplicationSourceHelm) (
752-
result []map[string]interface{}) {
717+
func flattenApplicationSourceHelm(as []*application.ApplicationSourceHelm) (result []map[string]interface{}) {
753718
for _, a := range as {
754719
if a != nil {
755720
var parameters []map[string]interface{}
@@ -762,21 +727,21 @@ func flattenApplicationSourceHelm(as []*application.ApplicationSourceHelm) (
762727
}
763728

764729
result = append(result, map[string]interface{}{
765-
"parameter": parameters,
766-
"release_name": a.ReleaseName,
767-
"skip_crds": a.SkipCrds,
768-
"value_files": a.ValueFiles,
769-
"values": a.Values,
770-
"pass_credentials": a.PassCredentials,
730+
"parameter": parameters,
731+
"release_name": a.ReleaseName,
732+
"skip_crds": a.SkipCrds,
733+
"value_files": a.ValueFiles,
734+
"values": a.Values,
735+
"pass_credentials": a.PassCredentials,
736+
"ignore_missing_value_files": a.IgnoreMissingValueFiles,
771737
})
772738
}
773739
}
774740

775741
return
776742
}
777743

778-
func flattenApplicationDestinations(ds []application.ApplicationDestination) (
779-
result []map[string]string) {
744+
func flattenApplicationDestinations(ds []application.ApplicationDestination) (result []map[string]string) {
780745
for _, d := range ds {
781746
result = append(result, map[string]string{
782747
"namespace": d.Namespace,

docs/resources/application.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,12 +290,13 @@ Optional:
290290

291291
Optional:
292292

293+
- `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'.
293294
- `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))
294-
- `pass_credentials` (Boolean) If true then adds --pass-credentials to Helm commands to pass credentials to all domains
295+
- `pass_credentials` (Boolean) If true then adds '--pass-credentials' to Helm commands to pass credentials to all domains.
295296
- `release_name` (String) Helm release name. If omitted it will use the application name.
296297
- `skip_crds` (Boolean) Whether to skip custom resource definition installation step (Helm's [--skip-crds](https://helm.sh/docs/chart_best_practices/custom_resource_definitions/)).
297298
- `value_files` (List of String) List of Helm value files to use when generating a template.
298-
- `values` (String) Helm values to be passed to helm template, typically defined as a block.
299+
- `values` (String) Helm values to be passed to 'helm template', typically defined as a block.
299300

300301
<a id="nestedblock--spec--source--helm--parameter"></a>
301302
### Nested Schema for `spec.source.helm.parameter`

0 commit comments

Comments
 (0)