Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(argocd_application_set): Add support for pathParamPrefix #336

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 @@ -276,6 +276,11 @@ func applicationSetGitGeneratorSchemaV0() *schema.Schema {
},
},
},
"path_param_prefix": {
Type: schema.TypeString,
Description: "Prefix for all path-related parameter names. Only applicable when using the `matrix` generator. See https://argo-cd.readthedocs.io/en/stable/operator-manual/applicationset/Generators-Matrix/#example-two-git-generators-using-pathparamprefix",
ahublersos marked this conversation as resolved.
Show resolved Hide resolved
Optional: true,
},
"repo_url": {
Type: schema.TypeString,
Description: "URL to the repository to use.",
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. Only applicable when using the `matrix` generator. See https://argo-cd.readthedocs.io/en/stable/operator-manual/applicationset/Generators-Matrix/#example-two-git-generators-using-pathparamprefix
- `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. Only applicable when using the `matrix` generator. See https://argo-cd.readthedocs.io/en/stable/operator-manual/applicationset/Generators-Matrix/#example-two-git-generators-using-pathparamprefix
- `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. Only applicable when using the `matrix` generator. See https://argo-cd.readthedocs.io/en/stable/operator-manual/applicationset/Generators-Matrix/#example-two-git-generators-using-pathparamprefix
- `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. Only applicable when using the `matrix` generator. See https://argo-cd.readthedocs.io/en/stable/operator-manual/applicationset/Generators-Matrix/#example-two-git-generators-using-pathparamprefix
- `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. Only applicable when using the `matrix` generator. See https://argo-cd.readthedocs.io/en/stable/operator-manual/applicationset/Generators-Matrix/#example-two-git-generators-using-pathparamprefix
- `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. Only applicable when using the `matrix` generator. See https://argo-cd.readthedocs.io/en/stable/operator-manual/applicationset/Generators-Matrix/#example-two-git-generators-using-pathparamprefix
- `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. Only applicable when using the `matrix` generator. See https://argo-cd.readthedocs.io/en/stable/operator-manual/applicationset/Generators-Matrix/#example-two-git-generators-using-pathparamprefix
- `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