Skip to content

Commit 14dd94f

Browse files
authored
fix: mark spec.destination.namespace as optional on ArgoCD application (#256)
1 parent 7a3e98e commit 14dd94f

File tree

3 files changed

+55
-5
lines changed

3 files changed

+55
-5
lines changed

argocd/resource_argocd_application_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,35 @@ ingress:
251251
})
252252
}
253253

254+
func TestAccArgoCDApplication_OptionalDestinationNamespace(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_OptionalDestinationNamespace(acctest.RandomWithPrefix("test-acc")),
261+
Check: resource.ComposeTestCheckFunc(
262+
resource.TestCheckResourceAttrSet(
263+
"argocd_application.simple",
264+
"metadata.0.uid",
265+
),
266+
resource.TestCheckResourceAttr(
267+
"argocd_application.simple",
268+
"spec.0.destination.0.namespace",
269+
"", // optional strings are maintained in state as blank strings
270+
),
271+
),
272+
},
273+
{
274+
ResourceName: "argocd_application.simple",
275+
ImportState: true,
276+
ImportStateVerify: true,
277+
ImportStateVerifyIgnore: []string{"wait", "cascade"},
278+
},
279+
},
280+
})
281+
}
282+
254283
func TestAccArgoCDApplication_DirectoryJsonnet(t *testing.T) {
255284
resource.ParallelTest(t, resource.TestCase{
256285
PreCheck: func() { testAccPreCheck(t) },
@@ -1409,6 +1438,30 @@ resource "argocd_application" "ignore_differences_jqpe" {
14091438
`, name)
14101439
}
14111440

1441+
func testAccArgoCDApplication_OptionalDestinationNamespace(name string) string {
1442+
return fmt.Sprintf(`
1443+
resource "argocd_application" "simple" {
1444+
metadata {
1445+
name = "%s"
1446+
namespace = "argocd"
1447+
}
1448+
spec {
1449+
source {
1450+
repo_url = "https://raw.githubusercontent.com/bitnami/charts/archive-full-index/bitnami"
1451+
chart = "redis"
1452+
target_revision = "16.9.11"
1453+
helm {
1454+
release_name = "testing"
1455+
}
1456+
}
1457+
destination {
1458+
server = "https://kubernetes.default.svc"
1459+
}
1460+
}
1461+
}
1462+
`, name)
1463+
}
1464+
14121465
func testAccArgoCDApplicationNoSyncPolicy(name string) string {
14131466
return fmt.Sprintf(`
14141467
resource "argocd_application" "simple" {

argocd/schema_application.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1254,7 +1254,7 @@ func applicationSpecSchemaV4() *schema.Schema {
12541254
"namespace": {
12551255
Type: schema.TypeString,
12561256
Description: "Target namespace for the application's resources. The namespace will only be set for namespace-scoped resources that have not set a value for .metadata.namespace.",
1257-
Required: true,
1257+
Optional: true,
12581258
},
12591259
"name": {
12601260
Type: schema.TypeString,

docs/resources/application.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,10 @@ Optional:
187187
<a id="nestedblock--spec--destination"></a>
188188
### Nested Schema for `spec.destination`
189189

190-
Required:
191-
192-
- `namespace` (String) Target namespace for the application's resources. The namespace will only be set for namespace-scoped resources that have not set a value for .metadata.namespace.
193-
194190
Optional:
195191

196192
- `name` (String) Name of the target cluster. Can be used instead of `server`.
193+
- `namespace` (String) Target namespace for the application's resources. The namespace will only be set for namespace-scoped resources that have not set a value for .metadata.namespace.
197194
- `server` (String) URL of the target cluster and must be set to the Kubernetes control plane API.
198195

199196

0 commit comments

Comments
 (0)