Skip to content

Commit c675f80

Browse files
fix: add plugin generator to nested generator (#639)
* fix: add plugin generator to nested generator #624 added support for plugin generators, but the support for it was never added to the nested generators. Signed-off-by: Blake Pettersson <[email protected]> * fix: add flatten step This needs to go the other way as well. Added test which verifies this works E2E. Signed-off-by: Blake Pettersson <[email protected]> * chore: please linter Signed-off-by: Blake Pettersson <[email protected]> * fix(test): make sure appset name is unique Signed-off-by: Blake Pettersson <[email protected]> --------- Signed-off-by: Blake Pettersson <[email protected]>
1 parent 0fa993f commit c675f80

File tree

2 files changed

+110
-1
lines changed

2 files changed

+110
-1
lines changed

argocd/resource_argocd_application_set_test.go

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,46 @@ func TestAccArgoCDApplicationSet_matrix(t *testing.T) {
263263
})
264264
}
265265

266+
func TestAccArgoCDApplicationSet_matrixPluginGenerator(t *testing.T) {
267+
resource.ParallelTest(t, resource.TestCase{
268+
PreCheck: func() { testAccPreCheck(t); testAccPreCheckFeatureSupported(t, features.ApplicationSet) },
269+
ProviderFactories: testAccProviders,
270+
Steps: []resource.TestStep{
271+
{
272+
Config: testAccArgoCDApplicationSet_matrixPluginGenerator(),
273+
Check: resource.ComposeTestCheckFunc(
274+
resource.TestCheckResourceAttrSet(
275+
"argocd_application_set.matrix-plugin_generator",
276+
"metadata.0.uid",
277+
),
278+
resource.TestCheckResourceAttrSet(
279+
"argocd_application_set.matrix-plugin_generator",
280+
"spec.0.generator.0.matrix.0.generator.1.clusters.0.selector.0.match_labels.%",
281+
),
282+
resource.TestCheckResourceAttrSet(
283+
"argocd_application_set.matrix-plugin_generator",
284+
"spec.0.generator.0.matrix.0.generator.0.plugin.0.requeue_after_seconds",
285+
),
286+
resource.TestCheckResourceAttrSet(
287+
"argocd_application_set.matrix-plugin_generator",
288+
"spec.0.generator.0.matrix.0.generator.0.plugin.0.config_map_ref",
289+
),
290+
resource.TestCheckResourceAttrSet(
291+
"argocd_application_set.matrix-plugin_generator",
292+
"spec.0.generator.0.matrix.0.generator.0.plugin.0.input.0.parameters.key1",
293+
),
294+
),
295+
},
296+
{
297+
ResourceName: "argocd_application_set.matrix-plugin_generator",
298+
ImportState: true,
299+
ImportStateVerify: true,
300+
ImportStateVerifyIgnore: []string{"metadata.0.resource_version"},
301+
},
302+
},
303+
})
304+
}
305+
266306
func TestAccArgoCDApplicationSet_matrixGitPathParamPrefix(t *testing.T) {
267307
resource.ParallelTest(t, resource.TestCase{
268308
PreCheck: func() { testAccPreCheck(t); testAccPreCheckFeatureSupported(t, features.ApplicationSet) },
@@ -1365,6 +1405,65 @@ resource "argocd_application_set" "matrix" {
13651405
}`
13661406
}
13671407

1408+
func testAccArgoCDApplicationSet_matrixPluginGenerator() string {
1409+
return `
1410+
resource "argocd_application_set" "matrix-plugin_generator" {
1411+
metadata {
1412+
name = "matrix-plugin-generator"
1413+
}
1414+
1415+
spec {
1416+
generator {
1417+
matrix {
1418+
generator {
1419+
plugin {
1420+
config_map_ref = "plugin"
1421+
1422+
input {
1423+
parameters = {
1424+
key1 = "value1"
1425+
}
1426+
}
1427+
1428+
requeue_after_seconds = 30
1429+
}
1430+
}
1431+
generator {
1432+
clusters{
1433+
selector{
1434+
match_labels = {
1435+
"argocd.argoproj.io/secret-type" = "cluster"
1436+
}
1437+
}
1438+
}
1439+
}
1440+
}
1441+
}
1442+
1443+
template {
1444+
metadata {
1445+
name = "{{path.basename}}-{{name}}"
1446+
}
1447+
1448+
spec {
1449+
project = "default"
1450+
1451+
source {
1452+
repo_url = "https://github.com/argoproj/argo-cd.git"
1453+
target_revision = "HEAD"
1454+
path = "{{path}}"
1455+
}
1456+
1457+
destination {
1458+
server = "{{server}}"
1459+
namespace = "{{path.basename}}"
1460+
}
1461+
}
1462+
}
1463+
}
1464+
}`
1465+
}
1466+
13681467
func testAccArgoCDApplicationSet_matrixGitPathParamPrefix() string {
13691468
return `
13701469
resource "argocd_application_set" "matrix_git_path_param_prefix" {

argocd/structure_application_set.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ import (
66
"reflect"
77

88
"github.com/argoproj-labs/terraform-provider-argocd/internal/features"
9-
application "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
109
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1110
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
1211
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
12+
13+
application "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
1314
)
1415

1516
func expandApplicationSet(d *schema.ResourceData, featureMultipleApplicationSourcesSupported bool, featureApplicationSetIgnoreApplicationDifferences bool, featureApplicationSetTemplatePatch bool) (metadata meta.ObjectMeta, spec application.ApplicationSetSpec, err error) {
@@ -285,6 +286,7 @@ func expandApplicationSetMatrixGenerator(mg interface{}, featureMultipleApplicat
285286
Clusters: g.Clusters,
286287
Git: g.Git,
287288
List: g.List,
289+
Plugin: g.Plugin,
288290
PullRequest: g.PullRequest,
289291
SCMProvider: g.SCMProvider,
290292
}
@@ -354,6 +356,7 @@ func expandApplicationSetMergeGenerator(mg interface{}, featureMultipleApplicati
354356
Clusters: g.Clusters,
355357
Git: g.Git,
356358
List: g.List,
359+
Plugin: g.Plugin,
357360
PullRequest: g.PullRequest,
358361
SCMProvider: g.SCMProvider,
359362
}
@@ -1582,6 +1585,13 @@ func flattenNestedGenerator(g application.ApplicationSetNestedGenerator) (map[st
15821585
generator["scm_provider"] = flattenApplicationSetSCMProviderGenerator(g.SCMProvider)
15831586
} else if g.PullRequest != nil {
15841587
generator["pull_request"] = flattenApplicationSetPullRequestGenerator(g.PullRequest)
1588+
} else if g.Plugin != nil {
1589+
plugin, err := flattenApplicationSetPluginGenerator(g.Plugin)
1590+
if err != nil {
1591+
return nil, err
1592+
}
1593+
1594+
generator["plugin"] = plugin
15851595
}
15861596

15871597
if g.Selector != nil {

0 commit comments

Comments
 (0)