Skip to content

Commit 8b48c7c

Browse files
feat: add applicationset git values (#386)
* feat: add applicationset git values Signed-off-by: Mikkel Kristensen <[email protected]> clean up clean up run make generate Signed-off-by: Mikkel Kristensen <[email protected]> * Apply suggestions from code review Co-authored-by: Brian Fox <[email protected]> Signed-off-by: Mikkel Kristensen <[email protected]> * Rerun make generate and fix typo Signed-off-by: Mikkel Kristensen <[email protected]> Apply suggestions from code review Co-authored-by: Brian Fox <[email protected]> re-run make generate Signed-off-by: Mikkel Kristensen <[email protected]> --------- Signed-off-by: Mikkel Kristensen <[email protected]> Co-authored-by: Brian Fox <[email protected]>
1 parent d2f42b8 commit 8b48c7c

File tree

4 files changed

+52
-3
lines changed

4 files changed

+52
-3
lines changed

argocd/resource_argocd_application_set_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ func TestAccArgoCDApplicationSet_gitFiles(t *testing.T) {
146146
"argocd_application_set.git_files",
147147
"spec.0.generator.0.git.0.file.0.path",
148148
),
149+
resource.TestCheckResourceAttr(
150+
"argocd_application_set.git_files",
151+
"spec.0.generator.0.git.0.values.foo",
152+
"bar",
153+
),
149154
),
150155
},
151156
{
@@ -820,6 +825,11 @@ func TestAccArgoCDApplicationSet_goTemplate(t *testing.T) {
820825
"spec.0.go_template",
821826
"true",
822827
),
828+
resource.TestCheckResourceAttr(
829+
"argocd_application_set.go_template",
830+
"spec.0.go_template_options.0",
831+
"missingkey=error",
832+
),
823833
),
824834
},
825835
{
@@ -1116,6 +1126,9 @@ resource "argocd_application_set" "git_files" {
11161126
file {
11171127
path = "applicationset/examples/git-generator-files-discovery/cluster-config/**/config.json"
11181128
}
1129+
values = {
1130+
foo = "bar"
1131+
}
11191132
}
11201133
}
11211134
@@ -2721,6 +2734,9 @@ resource "argocd_application_set" "go_template" {
27212734
}
27222735
27232736
go_template = true
2737+
go_template_options = [
2738+
"missingkey=error"
2739+
]
27242740
27252741
template {
27262742
metadata {

argocd/schema_application_set.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ func applicationSetSpecSchemaV0() *schema.Schema {
5151
Description: "Enable use of [Go Text Template](https://pkg.go.dev/text/template).",
5252
Optional: true,
5353
},
54+
"go_template_options": {
55+
Type: schema.TypeSet,
56+
Description: "Optional list of [Go Templating Options](https://pkg.go.dev/text/template#Template.Option). Only relevant if `go_template` is true.",
57+
Optional: true,
58+
Elem: &schema.Schema{Type: schema.TypeString},
59+
},
5460
"strategy": {
5561
Type: schema.TypeList,
5662
Description: "[Progressive Sync](https://argo-cd.readthedocs.io/en/stable/operator-manual/applicationset/Progressive-Syncs/) strategy",
@@ -333,6 +339,12 @@ func applicationSetGitGeneratorSchemaV0() *schema.Schema {
333339
MaxItems: 1,
334340
Elem: applicationSetTemplateResource(true),
335341
},
342+
"values": {
343+
Type: schema.TypeMap,
344+
Description: "Arbitrary string key-value pairs to pass to the template via the values field of the git generator.",
345+
Optional: true,
346+
Elem: &schema.Schema{Type: schema.TypeString},
347+
},
336348
},
337349
},
338350
}

argocd/structure_application_set.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ func expandApplicationSetSpec(d *schema.ResourceData, featureMultipleApplication
3131

3232
spec.GoTemplate = s["go_template"].(bool)
3333

34+
if v, ok := s["go_template_options"]; ok {
35+
opts := v.(*schema.Set).List()
36+
for _, opt := range opts {
37+
spec.GoTemplateOptions = append(spec.GoTemplateOptions, opt.(string))
38+
}
39+
}
40+
3441
if v, ok := s["strategy"].([]interface{}); ok && len(v) > 0 {
3542
spec.Strategy, err = expandApplicationSetStrategy(v[0].(map[string]interface{}))
3643
if err != nil {
@@ -213,6 +220,10 @@ func expandApplicationSetGitGenerator(gg interface{}, featureMultipleApplication
213220
asg.Git.Template = temp
214221
}
215222

223+
if v, ok := g["values"]; ok {
224+
asg.Git.Values = expandStringMap(v.(map[string]interface{}))
225+
}
226+
216227
return asg, nil
217228
}
218229

@@ -937,9 +948,10 @@ func flattenApplicationSetSpec(s application.ApplicationSetSpec) ([]map[string]i
937948
}
938949

939950
spec := map[string]interface{}{
940-
"generator": generators,
941-
"go_template": s.GoTemplate,
942-
"template": flattenApplicationSetTemplate(s.Template),
951+
"generator": generators,
952+
"go_template": s.GoTemplate,
953+
"go_template_options": s.GoTemplateOptions,
954+
"template": flattenApplicationSetTemplate(s.Template),
943955
}
944956

945957
if s.Strategy != nil {
@@ -1044,6 +1056,7 @@ func flattenApplicationSetGitGenerator(gg *application.GitGenerator) []map[strin
10441056
"revision": gg.Revision,
10451057
"path_param_prefix": gg.PathParamPrefix,
10461058
"template": flattenApplicationSetTemplate(gg.Template),
1059+
"values": gg.Values,
10471060
}
10481061

10491062
if len(gg.Directories) > 0 {

docs/resources/application_set.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,7 @@ Required:
598598
Optional:
599599

600600
- `go_template` (Boolean) Enable use of [Go Text Template](https://pkg.go.dev/text/template).
601+
- `go_template_options` (Set of String) Optional list of [Go Templating Options](https://pkg.go.dev/text/template#Template.Option). Only relevant if `go_template` is true.
601602
- `ignore_application_differences` (Block List) Application Set [ignoreApplicationDifferences](https://argo-cd.readthedocs.io/en/stable/operator-manual/applicationset/Controlling-Resource-Modification/#ignore-certain-changes-to-applications). (see [below for nested schema](#nestedblock--spec--ignore_application_differences))
602603
- `strategy` (Block List, Max: 1) [Progressive Sync](https://argo-cd.readthedocs.io/en/stable/operator-manual/applicationset/Progressive-Syncs/) strategy (see [below for nested schema](#nestedblock--spec--strategy))
603604
- `sync_policy` (Block List, Max: 1) Application Set [sync policy](https://argo-cd.readthedocs.io/en/stable/operator-manual/applicationset/Controlling-Resource-Modification/). (see [below for nested schema](#nestedblock--spec--sync_policy))
@@ -1172,6 +1173,7 @@ Optional:
11721173
- `path_param_prefix` (String) Prefix for all path-related parameter names.
11731174
- `revision` (String) Revision of the source repository to use.
11741175
- `template` (Block List, Max: 1) Generator template. Used to override the values of the spec-level template. (see [below for nested schema](#nestedblock--spec--generator--git--template))
1176+
- `values` (Map of String) Arbitrary string key-value pairs to pass to the template via the values field of the git generator.
11751177

11761178
<a id="nestedblock--spec--generator--git--directory"></a>
11771179
### Nested Schema for `spec.generator.git.directory`
@@ -2263,6 +2265,7 @@ Optional:
22632265
- `path_param_prefix` (String) Prefix for all path-related parameter names.
22642266
- `revision` (String) Revision of the source repository to use.
22652267
- `template` (Block List, Max: 1) Generator template. Used to override the values of the spec-level template. (see [below for nested schema](#nestedblock--spec--generator--matrix--generator--git--template))
2268+
- `values` (Map of String) Arbitrary string key-value pairs to pass to the template via the values field of the git generator.
22662269

22672270
<a id="nestedblock--spec--generator--matrix--generator--git--directory"></a>
22682271
### Nested Schema for `spec.generator.matrix.generator.git.directory`
@@ -3352,6 +3355,7 @@ Optional:
33523355
- `path_param_prefix` (String) Prefix for all path-related parameter names.
33533356
- `revision` (String) Revision of the source repository to use.
33543357
- `template` (Block List, Max: 1) Generator template. Used to override the values of the spec-level template. (see [below for nested schema](#nestedblock--spec--generator--matrix--generator--matrix--generator--git--template))
3358+
- `values` (Map of String) Arbitrary string key-value pairs to pass to the template via the values field of the git generator.
33553359

33563360
<a id="nestedblock--spec--generator--matrix--generator--matrix--generator--git--directory"></a>
33573361
### Nested Schema for `spec.generator.matrix.generator.matrix.generator.git.directory`
@@ -5484,6 +5488,7 @@ Optional:
54845488
- `path_param_prefix` (String) Prefix for all path-related parameter names.
54855489
- `revision` (String) Revision of the source repository to use.
54865490
- `template` (Block List, Max: 1) Generator template. Used to override the values of the spec-level template. (see [below for nested schema](#nestedblock--spec--generator--matrix--generator--merge--generator--git--template))
5491+
- `values` (Map of String) Arbitrary string key-value pairs to pass to the template via the values field of the git generator.
54875492

54885493
<a id="nestedblock--spec--generator--matrix--generator--merge--generator--git--directory"></a>
54895494
### Nested Schema for `spec.generator.matrix.generator.merge.generator.git.directory`
@@ -8660,6 +8665,7 @@ Optional:
86608665
- `path_param_prefix` (String) Prefix for all path-related parameter names.
86618666
- `revision` (String) Revision of the source repository to use.
86628667
- `template` (Block List, Max: 1) Generator template. Used to override the values of the spec-level template. (see [below for nested schema](#nestedblock--spec--generator--merge--generator--git--template))
8668+
- `values` (Map of String) Arbitrary string key-value pairs to pass to the template via the values field of the git generator.
86638669

86648670
<a id="nestedblock--spec--generator--merge--generator--git--directory"></a>
86658671
### Nested Schema for `spec.generator.merge.generator.git.directory`
@@ -9749,6 +9755,7 @@ Optional:
97499755
- `path_param_prefix` (String) Prefix for all path-related parameter names.
97509756
- `revision` (String) Revision of the source repository to use.
97519757
- `template` (Block List, Max: 1) Generator template. Used to override the values of the spec-level template. (see [below for nested schema](#nestedblock--spec--generator--merge--generator--matrix--generator--git--template))
9758+
- `values` (Map of String) Arbitrary string key-value pairs to pass to the template via the values field of the git generator.
97529759

97539760
<a id="nestedblock--spec--generator--merge--generator--matrix--generator--git--directory"></a>
97549761
### Nested Schema for `spec.generator.merge.generator.matrix.generator.git.directory`
@@ -11881,6 +11888,7 @@ Optional:
1188111888
- `path_param_prefix` (String) Prefix for all path-related parameter names.
1188211889
- `revision` (String) Revision of the source repository to use.
1188311890
- `template` (Block List, Max: 1) Generator template. Used to override the values of the spec-level template. (see [below for nested schema](#nestedblock--spec--generator--merge--generator--merge--generator--git--template))
11891+
- `values` (Map of String) Arbitrary string key-value pairs to pass to the template via the values field of the git generator.
1188411892

1188511893
<a id="nestedblock--spec--generator--merge--generator--merge--generator--git--directory"></a>
1188611894
### Nested Schema for `spec.generator.merge.generator.merge.generator.git.directory`

0 commit comments

Comments
 (0)