Skip to content

Commit

Permalink
feat: add applicationset git values (#386)
Browse files Browse the repository at this point in the history
* feat: add applicationset git values

Signed-off-by: Mikkel Kristensen <mkkr@dr.dk>

clean up

clean up

run make generate

Signed-off-by: Mikkel Kristensen <mkkr@dr.dk>

* Apply suggestions from code review

Co-authored-by: Brian Fox <878612+onematchfox@users.noreply.github.com>
Signed-off-by: Mikkel Kristensen <mkkr@dr.dk>

* Rerun make generate and fix typo

Signed-off-by: Mikkel Kristensen <mkkr@dr.dk>

Apply suggestions from code review

Co-authored-by: Brian Fox <878612+onematchfox@users.noreply.github.com>

re-run make generate

Signed-off-by: Mikkel Kristensen <mkkr@dr.dk>

---------

Signed-off-by: Mikkel Kristensen <mkkr@dr.dk>
Co-authored-by: Brian Fox <878612+onematchfox@users.noreply.github.com>
  • Loading branch information
drdkmkkr and onematchfox authored Jul 29, 2024
1 parent d2f42b8 commit 8b48c7c
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
16 changes: 16 additions & 0 deletions argocd/resource_argocd_application_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ func TestAccArgoCDApplicationSet_gitFiles(t *testing.T) {
"argocd_application_set.git_files",
"spec.0.generator.0.git.0.file.0.path",
),
resource.TestCheckResourceAttr(
"argocd_application_set.git_files",
"spec.0.generator.0.git.0.values.foo",
"bar",
),
),
},
{
Expand Down Expand Up @@ -820,6 +825,11 @@ func TestAccArgoCDApplicationSet_goTemplate(t *testing.T) {
"spec.0.go_template",
"true",
),
resource.TestCheckResourceAttr(
"argocd_application_set.go_template",
"spec.0.go_template_options.0",
"missingkey=error",
),
),
},
{
Expand Down Expand Up @@ -1116,6 +1126,9 @@ resource "argocd_application_set" "git_files" {
file {
path = "applicationset/examples/git-generator-files-discovery/cluster-config/**/config.json"
}
values = {
foo = "bar"
}
}
}
Expand Down Expand Up @@ -2721,6 +2734,9 @@ resource "argocd_application_set" "go_template" {
}
go_template = true
go_template_options = [
"missingkey=error"
]
template {
metadata {
Expand Down
12 changes: 12 additions & 0 deletions argocd/schema_application_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ func applicationSetSpecSchemaV0() *schema.Schema {
Description: "Enable use of [Go Text Template](https://pkg.go.dev/text/template).",
Optional: true,
},
"go_template_options": {
Type: schema.TypeSet,
Description: "Optional list of [Go Templating Options](https://pkg.go.dev/text/template#Template.Option). Only relevant if `go_template` is true.",
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"strategy": {
Type: schema.TypeList,
Description: "[Progressive Sync](https://argo-cd.readthedocs.io/en/stable/operator-manual/applicationset/Progressive-Syncs/) strategy",
Expand Down Expand Up @@ -333,6 +339,12 @@ func applicationSetGitGeneratorSchemaV0() *schema.Schema {
MaxItems: 1,
Elem: applicationSetTemplateResource(true),
},
"values": {
Type: schema.TypeMap,
Description: "Arbitrary string key-value pairs to pass to the template via the values field of the git generator.",
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
},
}
Expand Down
19 changes: 16 additions & 3 deletions argocd/structure_application_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ func expandApplicationSetSpec(d *schema.ResourceData, featureMultipleApplication

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

if v, ok := s["go_template_options"]; ok {
opts := v.(*schema.Set).List()
for _, opt := range opts {
spec.GoTemplateOptions = append(spec.GoTemplateOptions, opt.(string))
}
}

if v, ok := s["strategy"].([]interface{}); ok && len(v) > 0 {
spec.Strategy, err = expandApplicationSetStrategy(v[0].(map[string]interface{}))
if err != nil {
Expand Down Expand Up @@ -213,6 +220,10 @@ func expandApplicationSetGitGenerator(gg interface{}, featureMultipleApplication
asg.Git.Template = temp
}

if v, ok := g["values"]; ok {
asg.Git.Values = expandStringMap(v.(map[string]interface{}))
}

return asg, nil
}

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

spec := map[string]interface{}{
"generator": generators,
"go_template": s.GoTemplate,
"template": flattenApplicationSetTemplate(s.Template),
"generator": generators,
"go_template": s.GoTemplate,
"go_template_options": s.GoTemplateOptions,
"template": flattenApplicationSetTemplate(s.Template),
}

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

if len(gg.Directories) > 0 {
Expand Down
8 changes: 8 additions & 0 deletions docs/resources/application_set.md
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,7 @@ Required:
Optional:

- `go_template` (Boolean) Enable use of [Go Text Template](https://pkg.go.dev/text/template).
- `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.
- `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))
- `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))
- `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))
Expand Down Expand Up @@ -1172,6 +1173,7 @@ Optional:
- `path_param_prefix` (String) Prefix for all path-related parameter names.
- `revision` (String) Revision of the source repository to use.
- `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))
- `values` (Map of String) Arbitrary string key-value pairs to pass to the template via the values field of the git generator.

<a id="nestedblock--spec--generator--git--directory"></a>
### Nested Schema for `spec.generator.git.directory`
Expand Down Expand Up @@ -2263,6 +2265,7 @@ Optional:
- `path_param_prefix` (String) Prefix for all path-related parameter names.
- `revision` (String) Revision of the source repository to use.
- `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))
- `values` (Map of String) Arbitrary string key-value pairs to pass to the template via the values field of the git generator.

<a id="nestedblock--spec--generator--matrix--generator--git--directory"></a>
### Nested Schema for `spec.generator.matrix.generator.git.directory`
Expand Down Expand Up @@ -3352,6 +3355,7 @@ Optional:
- `path_param_prefix` (String) Prefix for all path-related parameter names.
- `revision` (String) Revision of the source repository to use.
- `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))
- `values` (Map of String) Arbitrary string key-value pairs to pass to the template via the values field of the git generator.

<a id="nestedblock--spec--generator--matrix--generator--matrix--generator--git--directory"></a>
### Nested Schema for `spec.generator.matrix.generator.matrix.generator.git.directory`
Expand Down Expand Up @@ -5484,6 +5488,7 @@ Optional:
- `path_param_prefix` (String) Prefix for all path-related parameter names.
- `revision` (String) Revision of the source repository to use.
- `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))
- `values` (Map of String) Arbitrary string key-value pairs to pass to the template via the values field of the git generator.

<a id="nestedblock--spec--generator--matrix--generator--merge--generator--git--directory"></a>
### Nested Schema for `spec.generator.matrix.generator.merge.generator.git.directory`
Expand Down Expand Up @@ -8660,6 +8665,7 @@ Optional:
- `path_param_prefix` (String) Prefix for all path-related parameter names.
- `revision` (String) Revision of the source repository to use.
- `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))
- `values` (Map of String) Arbitrary string key-value pairs to pass to the template via the values field of the git generator.

<a id="nestedblock--spec--generator--merge--generator--git--directory"></a>
### Nested Schema for `spec.generator.merge.generator.git.directory`
Expand Down Expand Up @@ -9749,6 +9755,7 @@ Optional:
- `path_param_prefix` (String) Prefix for all path-related parameter names.
- `revision` (String) Revision of the source repository to use.
- `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))
- `values` (Map of String) Arbitrary string key-value pairs to pass to the template via the values field of the git generator.

<a id="nestedblock--spec--generator--merge--generator--matrix--generator--git--directory"></a>
### Nested Schema for `spec.generator.merge.generator.matrix.generator.git.directory`
Expand Down Expand Up @@ -11881,6 +11888,7 @@ Optional:
- `path_param_prefix` (String) Prefix for all path-related parameter names.
- `revision` (String) Revision of the source repository to use.
- `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))
- `values` (Map of String) Arbitrary string key-value pairs to pass to the template via the values field of the git generator.

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

0 comments on commit 8b48c7c

Please sign in to comment.