Skip to content

Commit bfe7924

Browse files
authored
Add support for jsonnet libraries (#255)
1 parent fac513d commit bfe7924

File tree

4 files changed

+109
-67
lines changed

4 files changed

+109
-67
lines changed

argocd/resource_argocd_application_test.go

Lines changed: 90 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -129,72 +129,6 @@ ingress:
129129
ImportStateVerify: true,
130130
ImportStateVerifyIgnore: []string{"wait", "cascade", "metadata.0.generation", "metadata.0.resource_version"},
131131
},
132-
{
133-
Config: testAccArgoCDApplicationDirectory(
134-
acctest.RandomWithPrefix("test-acc")),
135-
Check: resource.ComposeTestCheckFunc(
136-
resource.TestCheckResourceAttrSet(
137-
"argocd_application.directory",
138-
"metadata.0.uid",
139-
),
140-
resource.TestCheckResourceAttr(
141-
"argocd_application.directory",
142-
"spec.0.source.0.directory.0.recurse",
143-
"false",
144-
),
145-
resource.TestCheckResourceAttr(
146-
"argocd_application.directory",
147-
"spec.0.source.0.directory.0.jsonnet.0.ext_var.0.name",
148-
"somename",
149-
),
150-
resource.TestCheckResourceAttr(
151-
"argocd_application.directory",
152-
"spec.0.source.0.directory.0.jsonnet.0.ext_var.0.value",
153-
"somevalue",
154-
),
155-
resource.TestCheckResourceAttr(
156-
"argocd_application.directory",
157-
"spec.0.source.0.directory.0.jsonnet.0.ext_var.0.code",
158-
"false",
159-
),
160-
resource.TestCheckResourceAttr(
161-
"argocd_application.directory",
162-
"spec.0.source.0.directory.0.jsonnet.0.ext_var.1.name",
163-
"anothername",
164-
),
165-
resource.TestCheckResourceAttr(
166-
"argocd_application.directory",
167-
"spec.0.source.0.directory.0.jsonnet.0.ext_var.1.value",
168-
"anothervalue",
169-
),
170-
resource.TestCheckResourceAttr(
171-
"argocd_application.directory",
172-
"spec.0.source.0.directory.0.jsonnet.0.ext_var.1.code",
173-
"true",
174-
),
175-
resource.TestCheckResourceAttr(
176-
"argocd_application.directory",
177-
"spec.0.source.0.directory.0.jsonnet.0.tla.0.name",
178-
"yetanothername",
179-
),
180-
resource.TestCheckResourceAttr(
181-
"argocd_application.directory",
182-
"spec.0.source.0.directory.0.jsonnet.0.tla.0.value",
183-
"yetanothervalue",
184-
),
185-
resource.TestCheckResourceAttr(
186-
"argocd_application.directory",
187-
"spec.0.source.0.directory.0.jsonnet.0.tla.0.code",
188-
"true",
189-
),
190-
),
191-
},
192-
{
193-
ResourceName: "argocd_application.directory",
194-
ImportState: true,
195-
ImportStateVerify: true,
196-
ImportStateVerifyIgnore: []string{"wait", "cascade", "metadata.0.generation", "metadata.0.resource_version"},
197-
},
198132
{
199133
Config: testAccArgoCDApplicationSyncPolicy(
200134
acctest.RandomWithPrefix("test-acc")),
@@ -317,6 +251,91 @@ ingress:
317251
})
318252
}
319253

254+
func TestAccArgoCDApplication_DirectoryJsonnet(t *testing.T) {
255+
resource.ParallelTest(t, resource.TestCase{
256+
PreCheck: func() { testAccPreCheck(t) },
257+
ProviderFactories: testAccProviders,
258+
Steps: []resource.TestStep{
259+
{
260+
Config: testAccArgoCDApplication_DirectoryJsonnet(
261+
acctest.RandomWithPrefix("test-acc")),
262+
Check: resource.ComposeTestCheckFunc(
263+
resource.TestCheckResourceAttrSet(
264+
"argocd_application.directory",
265+
"metadata.0.uid",
266+
),
267+
resource.TestCheckResourceAttr(
268+
"argocd_application.directory",
269+
"spec.0.source.0.directory.0.recurse",
270+
"false",
271+
),
272+
resource.TestCheckResourceAttr(
273+
"argocd_application.directory",
274+
"spec.0.source.0.directory.0.jsonnet.0.ext_var.0.name",
275+
"somename",
276+
),
277+
resource.TestCheckResourceAttr(
278+
"argocd_application.directory",
279+
"spec.0.source.0.directory.0.jsonnet.0.ext_var.0.value",
280+
"somevalue",
281+
),
282+
resource.TestCheckResourceAttr(
283+
"argocd_application.directory",
284+
"spec.0.source.0.directory.0.jsonnet.0.ext_var.0.code",
285+
"false",
286+
),
287+
resource.TestCheckResourceAttr(
288+
"argocd_application.directory",
289+
"spec.0.source.0.directory.0.jsonnet.0.ext_var.1.name",
290+
"anothername",
291+
),
292+
resource.TestCheckResourceAttr(
293+
"argocd_application.directory",
294+
"spec.0.source.0.directory.0.jsonnet.0.ext_var.1.value",
295+
"anothervalue",
296+
),
297+
resource.TestCheckResourceAttr(
298+
"argocd_application.directory",
299+
"spec.0.source.0.directory.0.jsonnet.0.ext_var.1.code",
300+
"true",
301+
),
302+
resource.TestCheckResourceAttr(
303+
"argocd_application.directory",
304+
"spec.0.source.0.directory.0.jsonnet.0.tla.0.name",
305+
"yetanothername",
306+
),
307+
resource.TestCheckResourceAttr(
308+
"argocd_application.directory",
309+
"spec.0.source.0.directory.0.jsonnet.0.tla.0.value",
310+
"yetanothervalue",
311+
),
312+
resource.TestCheckResourceAttr(
313+
"argocd_application.directory",
314+
"spec.0.source.0.directory.0.jsonnet.0.tla.0.code",
315+
"true",
316+
),
317+
resource.TestCheckResourceAttr(
318+
"argocd_application.directory",
319+
"spec.0.source.0.directory.0.jsonnet.0.libs.0",
320+
"vendor",
321+
),
322+
resource.TestCheckResourceAttr(
323+
"argocd_application.directory",
324+
"spec.0.source.0.directory.0.jsonnet.0.libs.1",
325+
"foo",
326+
),
327+
),
328+
},
329+
{
330+
ResourceName: "argocd_application.directory",
331+
ImportState: true,
332+
ImportStateVerify: true,
333+
ImportStateVerifyIgnore: []string{"wait", "cascade", "metadata.0.generation", "metadata.0.resource_version"},
334+
},
335+
},
336+
})
337+
}
338+
320339
func TestAccArgoCDApplication_NoSyncPolicyBlock(t *testing.T) {
321340
resource.ParallelTest(t, resource.TestCase{
322341
PreCheck: func() { testAccPreCheck(t) },
@@ -1070,7 +1089,7 @@ resource "argocd_application" "directory" {
10701089
`, name, path)
10711090
}
10721091

1073-
func testAccArgoCDApplicationDirectory(name string) string {
1092+
func testAccArgoCDApplication_DirectoryJsonnet(name string) string {
10741093
return fmt.Sprintf(`
10751094
resource "argocd_application" "directory" {
10761095
metadata {
@@ -1104,6 +1123,10 @@ resource "argocd_application" "directory" {
11041123
value = "yetanothervalue"
11051124
code = true
11061125
}
1126+
libs = [
1127+
"vendor",
1128+
"foo"
1129+
]
11071130
}
11081131
}
11091132
}

argocd/schema_application.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,6 +1485,14 @@ func applicationSpecSchemaV4() *schema.Schema {
14851485
},
14861486
},
14871487
},
1488+
"libs": {
1489+
Type: schema.TypeList,
1490+
Description: "Additional library search dirs.",
1491+
Optional: true,
1492+
Elem: &schema.Schema{
1493+
Type: schema.TypeString,
1494+
},
1495+
},
14881496
},
14891497
},
14901498
},

argocd/structure_application.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@ func expandApplicationSourceDirectory(in []interface{}) *application.Application
173173
}
174174
}
175175
}
176+
177+
if libs, ok := j["libs"].([]interface{}); ok && len(libs) > 0 {
178+
for _, lib := range libs {
179+
jsonnet.Libs = append(jsonnet.Libs, lib.(string))
180+
}
181+
}
176182
}
177183

178184
result.Jsonnet = jsonnet
@@ -660,6 +666,10 @@ func flattenApplicationSourceDirectory(as []*application.ApplicationSourceDirect
660666
})
661667
}
662668

669+
for _, lib := range a.Jsonnet.Libs {
670+
jsonnet["libs"] = append(jsonnet["libs"], lib)
671+
}
672+
663673
m := make(map[string]interface{})
664674
m["recurse"] = a.Recurse
665675

docs/resources/application.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ Optional:
228228
Optional:
229229

230230
- `ext_var` (Block List) List of Jsonnet External Variables. (see [below for nested schema](#nestedblock--spec--source--directory--jsonnet--ext_var))
231+
- `libs` (List of String) Additional library search dirs.
231232
- `tla` (Block Set) List of Jsonnet Top-level Arguments (see [below for nested schema](#nestedblock--spec--source--directory--jsonnet--tla))
232233

233234
<a id="nestedblock--spec--source--directory--jsonnet--ext_var"></a>

0 commit comments

Comments
 (0)