Skip to content

Commit 7a3e98e

Browse files
authored
Add support for include and exclude on directory apps (#254)
1 parent bfe7924 commit 7a3e98e

File tree

4 files changed

+86
-0
lines changed

4 files changed

+86
-0
lines changed

argocd/resource_argocd_application_test.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,38 @@ func TestAccArgoCDApplication_Recurse(t *testing.T) {
442442
})
443443
}
444444

445+
func TestAccArgoCDApplication__DirectoryIncludeExclude(t *testing.T) {
446+
name := acctest.RandomWithPrefix("test-acc")
447+
448+
resource.ParallelTest(t, resource.TestCase{
449+
PreCheck: func() { testAccPreCheck(t) },
450+
ProviderFactories: testAccProviders,
451+
Steps: []resource.TestStep{
452+
{
453+
Config: testAccArgoCDApplication_DirectoryIncludeExclude(name),
454+
Check: resource.ComposeTestCheckFunc(
455+
resource.TestCheckResourceAttr(
456+
"argocd_application.directory",
457+
"spec.0.source.0.directory.0.include",
458+
"*.yaml",
459+
),
460+
resource.TestCheckResourceAttr(
461+
"argocd_application.directory",
462+
"spec.0.source.0.directory.0.exclude",
463+
"config.yaml",
464+
),
465+
),
466+
},
467+
{
468+
ResourceName: "argocd_application.directory",
469+
ImportState: true,
470+
ImportStateVerify: true,
471+
ImportStateVerifyIgnore: []string{"wait", "cascade", "metadata.0.generation", "metadata.0.resource_version"},
472+
},
473+
},
474+
})
475+
}
476+
445477
func TestAccArgoCDApplication_EmptySyncPolicyBlock(t *testing.T) {
446478
resource.ParallelTest(t, resource.TestCase{
447479
PreCheck: func() { testAccPreCheck(t) },
@@ -1216,6 +1248,38 @@ resource "argocd_application" "directory" {
12161248
`, name, strconv.FormatBool(recurse))
12171249
}
12181250

1251+
func testAccArgoCDApplication_DirectoryIncludeExclude(name string) string {
1252+
return fmt.Sprintf(`
1253+
resource "argocd_application" "directory" {
1254+
metadata {
1255+
name = "%s"
1256+
namespace = "argocd"
1257+
labels = {
1258+
acceptance = "true"
1259+
}
1260+
}
1261+
1262+
spec {
1263+
source {
1264+
repo_url = "https://github.com/argoproj/argocd-example-apps"
1265+
path = "guestbook"
1266+
target_revision = "HEAD"
1267+
directory {
1268+
recurse = true
1269+
exclude = "config.yaml"
1270+
include = "*.yaml"
1271+
}
1272+
}
1273+
1274+
destination {
1275+
server = "https://kubernetes.default.svc"
1276+
namespace = "default"
1277+
}
1278+
}
1279+
}
1280+
`, name)
1281+
}
1282+
12191283
func testAccArgoCDApplicationSyncPolicy(name string) string {
12201284
return fmt.Sprintf(`
12211285
resource "argocd_application" "sync_policy" {

argocd/schema_application.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,6 +1496,16 @@ func applicationSpecSchemaV4() *schema.Schema {
14961496
},
14971497
},
14981498
},
1499+
"exclude": {
1500+
Type: schema.TypeString,
1501+
Description: "Glob pattern to match paths against that should be explicitly excluded from being used during manifest generation. This takes precedence over the `include` field. To match multiple patterns, wrap the patterns in {} and separate them with commas. For example: '{config.yaml,env-use2/*}'",
1502+
Optional: true,
1503+
},
1504+
"include": {
1505+
Type: schema.TypeString,
1506+
Description: "Glob pattern to match paths against that should be explicitly included during manifest generation. If this field is set, only matching manifests will be included. To match multiple patterns, wrap the patterns in {} and separate them with commas. For example: '{*.yml,*.yaml}'",
1507+
Optional: true,
1508+
},
14991509
},
15001510
},
15011511
},

argocd/structure_application.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,14 @@ func expandApplicationSourceDirectory(in []interface{}) *application.Application
141141
result.Recurse = v.(bool)
142142
}
143143

144+
if v, ok := a["exclude"]; ok {
145+
result.Exclude = v.(string)
146+
}
147+
148+
if v, ok := a["include"]; ok {
149+
result.Include = v.(string)
150+
}
151+
144152
if aj, ok := a["jsonnet"].([]interface{}); ok {
145153
jsonnet := application.ApplicationSourceJsonnet{}
146154

@@ -672,6 +680,8 @@ func flattenApplicationSourceDirectory(as []*application.ApplicationSourceDirect
672680

673681
m := make(map[string]interface{})
674682
m["recurse"] = a.Recurse
683+
m["exclude"] = a.Exclude
684+
m["include"] = a.Include
675685

676686
if len(jsonnet) > 0 {
677687
m["jsonnet"] = []map[string][]interface{}{jsonnet}

docs/resources/application.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ Optional:
219219

220220
Optional:
221221

222+
- `exclude` (String) Glob pattern to match paths against that should be explicitly excluded from being used during manifest generation. This takes precedence over the `include` field. To match multiple patterns, wrap the patterns in {} and separate them with commas. For example: '{config.yaml,env-use2/*}'
223+
- `include` (String) Glob pattern to match paths against that should be explicitly included during manifest generation. If this field is set, only matching manifests will be included. To match multiple patterns, wrap the patterns in {} and separate them with commas. For example: '{*.yml,*.yaml}'
222224
- `jsonnet` (Block List, Max: 1) Jsonnet specific options. (see [below for nested schema](#nestedblock--spec--source--directory--jsonnet))
223225
- `recurse` (Boolean) Whether to scan a directory recursively for manifests.
224226

0 commit comments

Comments
 (0)