Skip to content

Commit

Permalink
feat(argocd_application_set): Add support for pathParamPrefix (#336)
Browse files Browse the repository at this point in the history
* feat(argocd_application_set): Add support for pathParamPrefix

* Update docs

* fix test

* add path_param_prefix to flatten function

* fix attribute name in test

* fix: no need to check for existence of string

* tests: use matrix generator when testing new parameter

* build(deps): align test versions with latest releases of ArgoCD

* docs: add note regarding use of attribute with matrix generator

Also keep attributes in alphabetic order

* revert: docs: add note regarding use of attribute with matrix generator

This reverts commit f859377.

---------

Co-authored-by: Brian Fox <brian.fox@embark-studios.com>
  • Loading branch information
ahublersos and onematchfox committed Sep 14, 2023
1 parent 5aad18e commit d84d091
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
strategy:
fail-fast: false
matrix:
argocd_version: ["v2.5.18", "v2.6.9", "v2.7.4"]
argocd_version: ["v2.6.15", "v2.7.14", "v2.8.3"]
steps:
- name: Check out code
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
Expand Down
92 changes: 92 additions & 0 deletions argocd/resource_argocd_application_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,40 @@ func TestAccArgoCDApplicationSet_matrix(t *testing.T) {
})
}

func TestAccArgoCDApplicationSet_matrixGitPathParamPrefix(t *testing.T) {
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPreCheckFeatureSupported(t, features.ApplicationSet) },
ProviderFactories: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccArgoCDApplicationSet_matrixGitPathParamPrefix(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(
"argocd_application_set.matrix_git_path_param_prefix",
"metadata.0.uid",
),
resource.TestCheckResourceAttr(
"argocd_application_set.matrix_git_path_param_prefix",
"spec.0.generator.0.matrix.0.generator.0.git.0.path_param_prefix",
"foo",
),
resource.TestCheckResourceAttr(
"argocd_application_set.matrix_git_path_param_prefix",
"spec.0.generator.0.matrix.0.generator.1.git.0.path_param_prefix",
"bar",
),
),
},
{
ResourceName: "argocd_application_set.matrix_git_path_param_prefix",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"metadata.0.resource_version"},
},
},
})
}

func TestAccArgoCDApplicationSet_matrixNested(t *testing.T) {
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPreCheckFeatureSupported(t, features.ApplicationSet) },
Expand Down Expand Up @@ -1170,6 +1204,64 @@ resource "argocd_application_set" "matrix" {
}`
}

func testAccArgoCDApplicationSet_matrixGitPathParamPrefix() string {
return `
resource "argocd_application_set" "matrix_git_path_param_prefix" {
metadata {
name = "matrix-git-path-param-prefix"
}
spec {
generator {
matrix {
generator {
git {
repo_url = "https://github.com/argoproj/argo-cd.git"
revision = "HEAD"
path_param_prefix = "foo"
file {
path = "applicationset/examples/git-generator-files-discovery/cluster-config/**/config.json"
}
}
}
generator {
git {
repo_url = "https://github.com/argoproj/argo-cd.git"
revision = "HEAD"
path_param_prefix = "bar"
file {
path = "applicationset/examples/git-generator-files-discovery/cluster-config/**/config.json"
}
}
}
}
}
template {
metadata {
name = "matrix-git-path-param-prefix"
}
spec {
source {
repo_url = "https://github.com/argoproj/argo-cd.git"
target_revision = "HEAD"
path = "applicationset/examples/git-generator-files-discovery/apps/guestbook"
}
destination {
server = "{{cluster.address}}"
namespace = "guestbook"
}
}
}
}
}`
}

func testAccArgoCDApplicationSet_matrixNested() string {
return `
resource "argocd_application_set" "matrix_nested" {
Expand Down
5 changes: 5 additions & 0 deletions argocd/schema_application_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,11 @@ func applicationSetGitGeneratorSchemaV0() *schema.Schema {
Description: "Revision of the source repository to use.",
Optional: true,
},
"path_param_prefix": {
Type: schema.TypeString,
Description: "Prefix for all path-related parameter names.",
Optional: true,
},
"template": {
Type: schema.TypeList,
Description: "Generator template. Used to override the values of the spec-level template.",
Expand Down
12 changes: 7 additions & 5 deletions argocd/structure_application_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,9 @@ func expandApplicationSetGitGenerator(gg interface{}, featureMultipleApplication

asg := &application.ApplicationSetGenerator{
Git: &application.GitGenerator{
RepoURL: g["repo_url"].(string),
Revision: g["revision"].(string),
PathParamPrefix: g["path_param_prefix"].(string),
RepoURL: g["repo_url"].(string),
Revision: g["revision"].(string),
},
}

Expand Down Expand Up @@ -963,9 +964,10 @@ func flattenApplicationSetClusterDecisionResourceGenerator(c *application.DuckTy

func flattenApplicationSetGitGenerator(gg *application.GitGenerator) []map[string]interface{} {
g := map[string]interface{}{
"repo_url": gg.RepoURL,
"revision": gg.Revision,
"template": flattenApplicationSetTemplate(gg.Template),
"repo_url": gg.RepoURL,
"revision": gg.Revision,
"path_param_prefix": gg.PathParamPrefix,
"template": flattenApplicationSetTemplate(gg.Template),
}

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

- `directory` (Block List) List of directories in the source repository to use when template the Application.. (see [below for nested schema](#nestedblock--spec--generator--git--directory))
- `file` (Block List) List of files in the source repository to use when template the Application. (see [below for nested schema](#nestedblock--spec--generator--git--file))
- `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))

Expand Down Expand Up @@ -2258,6 +2259,7 @@ Optional:

- `directory` (Block List) List of directories in the source repository to use when template the Application.. (see [below for nested schema](#nestedblock--spec--generator--matrix--generator--git--directory))
- `file` (Block List) List of files in the source repository to use when template the Application. (see [below for nested schema](#nestedblock--spec--generator--matrix--generator--git--file))
- `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))

Expand Down Expand Up @@ -3346,6 +3348,7 @@ Optional:

- `directory` (Block List) List of directories in the source repository to use when template the Application.. (see [below for nested schema](#nestedblock--spec--generator--matrix--generator--matrix--generator--git--directory))
- `file` (Block List) List of files in the source repository to use when template the Application. (see [below for nested schema](#nestedblock--spec--generator--matrix--generator--matrix--generator--git--file))
- `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))

Expand Down Expand Up @@ -5477,6 +5480,7 @@ Optional:

- `directory` (Block List) List of directories in the source repository to use when template the Application.. (see [below for nested schema](#nestedblock--spec--generator--matrix--generator--merge--generator--git--directory))
- `file` (Block List) List of files in the source repository to use when template the Application. (see [below for nested schema](#nestedblock--spec--generator--matrix--generator--merge--generator--git--file))
- `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))

Expand Down Expand Up @@ -8652,6 +8656,7 @@ Optional:

- `directory` (Block List) List of directories in the source repository to use when template the Application.. (see [below for nested schema](#nestedblock--spec--generator--merge--generator--git--directory))
- `file` (Block List) List of files in the source repository to use when template the Application. (see [below for nested schema](#nestedblock--spec--generator--merge--generator--git--file))
- `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))

Expand Down Expand Up @@ -9740,6 +9745,7 @@ Optional:

- `directory` (Block List) List of directories in the source repository to use when template the Application.. (see [below for nested schema](#nestedblock--spec--generator--merge--generator--matrix--generator--git--directory))
- `file` (Block List) List of files in the source repository to use when template the Application. (see [below for nested schema](#nestedblock--spec--generator--merge--generator--matrix--generator--git--file))
- `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))

Expand Down Expand Up @@ -11871,6 +11877,7 @@ Optional:

- `directory` (Block List) List of directories in the source repository to use when template the Application.. (see [below for nested schema](#nestedblock--spec--generator--merge--generator--merge--generator--git--directory))
- `file` (Block List) List of files in the source repository to use when template the Application. (see [below for nested schema](#nestedblock--spec--generator--merge--generator--merge--generator--git--file))
- `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))

Expand Down

0 comments on commit d84d091

Please sign in to comment.