Skip to content

Commit 5dc7a8c

Browse files
authored
argocd_application: support for kustomize.common_annotations and sync_policy.automated.allow_empty (#48)
* argocd_application: support for kustomize.common_annotations and sync_policy.automated.allow_empty * added application destination name attribute to both application and project
1 parent 3c8ab5c commit 5dc7a8c

File tree

6 files changed

+69
-14
lines changed

6 files changed

+69
-14
lines changed

argocd/resource_argocd_application_test.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ ingress:
133133
"spec.0.sync_policy.0.automated.self_heal",
134134
"true",
135135
),
136+
resource.TestCheckResourceAttr(
137+
"argocd_application.sync_policy",
138+
"spec.0.sync_policy.0.automated.allow_empty",
139+
"true",
140+
),
136141
resource.TestCheckResourceAttr(
137142
"argocd_application.sync_policy",
138143
"spec.0.sync_policy.0.retry.0.backoff.duration",
@@ -287,6 +292,10 @@ resource "argocd_application" "kustomize" {
287292
"this.is.a.common" = "la-bel"
288293
"another.io/one" = "true"
289294
}
295+
common_annotations = {
296+
"this.is.a.common" = "anno-tation"
297+
"another.io/one" = "false"
298+
}
290299
}
291300
}
292301
@@ -371,8 +380,9 @@ resource "argocd_application" "sync_policy" {
371380
372381
sync_policy {
373382
automated = {
374-
prune = true
375-
self_heal = true
383+
prune = true
384+
self_heal = true
385+
allow_empty = true
376386
}
377387
retry {
378388
limit = "5"

argocd/schema_application.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,17 @@ func applicationSpecSchema() *schema.Schema {
2222
Schema: map[string]*schema.Schema{
2323
"server": {
2424
Type: schema.TypeString,
25-
Required: true,
25+
Optional: true,
2626
},
2727
"namespace": {
2828
Type: schema.TypeString,
2929
Required: true,
3030
},
31+
"name": {
32+
Type: schema.TypeString,
33+
Optional: true,
34+
Description: "Name of the destination cluster which can be used instead of server.",
35+
},
3136
},
3237
},
3338
},
@@ -134,6 +139,12 @@ func applicationSpecSchema() *schema.Schema {
134139
Elem: &schema.Schema{Type: schema.TypeString},
135140
ValidateFunc: validateMetadataLabels,
136141
},
142+
"common_annotations": {
143+
Type: schema.TypeMap,
144+
Optional: true,
145+
Elem: &schema.Schema{Type: schema.TypeString},
146+
ValidateFunc: validateMetadataAnnotations,
147+
},
137148
},
138149
},
139150
},

argocd/schema_project.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,17 @@ func projectSpecSchema() *schema.Schema {
3939
Schema: map[string]*schema.Schema{
4040
"server": {
4141
Type: schema.TypeString,
42-
Required: true,
42+
Optional: true,
4343
},
4444
"namespace": {
4545
Type: schema.TypeString,
4646
Required: true,
4747
},
48+
"name": {
49+
Type: schema.TypeString,
50+
Optional: true,
51+
Description: "Name of the destination cluster which can be used instead of server.",
52+
},
4853
},
4954
},
5055
},

argocd/structure_application.go

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,12 @@ func expandApplicationSourceKustomize(in []interface{}) *application.Application
205205
result.CommonLabels[k] = v.(string)
206206
}
207207
}
208+
if cas, ok := a["common_annotations"]; ok {
209+
result.CommonAnnotations = make(map[string]string, 0)
210+
for k, v := range cas.(map[string]interface{}) {
211+
result.CommonAnnotations[k] = v.(string)
212+
}
213+
}
208214
return result
209215
}
210216

@@ -262,6 +268,9 @@ func expandApplicationSyncPolicy(_sp []interface{}) (*application.SyncPolicy, er
262268
if k == "self_heal" {
263269
automated.SelfHeal = v.(bool)
264270
}
271+
if k == "allow_empty" {
272+
automated.AllowEmpty = v.(bool)
273+
}
265274
}
266275
}
267276
if v, ok := sp.(map[string]interface{})["sync_options"]; ok {
@@ -357,6 +366,7 @@ func expandApplicationDestination(dest interface{}) (
357366
return application.ApplicationDestination{
358367
Server: d["server"].(string),
359368
Namespace: d["namespace"].(string),
369+
Name: d["name"].(string),
360370
}
361371
}
362372

@@ -408,8 +418,9 @@ func flattenApplicationSyncPolicy(sp *application.SyncPolicy) []map[string]inter
408418
backoff := make(map[string]string, 0)
409419
if sp.Automated != nil {
410420
result["automated"] = map[string]bool{
411-
"prune": sp.Automated.Prune,
412-
"self_heal": sp.Automated.SelfHeal,
421+
"prune": sp.Automated.Prune,
422+
"self_heal": sp.Automated.SelfHeal,
423+
"allow_empty": sp.Automated.AllowEmpty,
413424
}
414425
}
415426
result["sync_options"] = []string(sp.SyncOptions)
@@ -567,11 +578,12 @@ func flattenApplicationSourceKustomize(as []*application.ApplicationSourceKustom
567578
images = append(images, string(i))
568579
}
569580
result = append(result, map[string]interface{}{
570-
"common_labels": a.CommonLabels,
571-
"images": images,
572-
"name_prefix": a.NamePrefix,
573-
"name_suffix": a.NameSuffix,
574-
"version": a.Version,
581+
"common_annotations": a.CommonAnnotations,
582+
"common_labels": a.CommonLabels,
583+
"images": images,
584+
"name_prefix": a.NamePrefix,
585+
"name_suffix": a.NameSuffix,
586+
"version": a.Version,
575587
})
576588
}
577589
}
@@ -607,6 +619,7 @@ func flattenApplicationDestinations(ds []application.ApplicationDestination) (
607619
result = append(result, map[string]string{
608620
"namespace": d.Namespace,
609621
"server": d.Server,
622+
"name": d.Name,
610623
})
611624
}
612625
return

docs/resources/application.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,20 @@ resource "argocd_application" "kustomize" {
3939
4040
sync_policy {
4141
automated = {
42-
prune = true
43-
self_heal = true
42+
prune = true
43+
self_heal = true
44+
allow_empty = true
4445
}
4546
# Only available from ArgoCD 1.5.0 onwards
4647
sync_options = ["Validate=false"]
48+
retry {
49+
limit = "5"
50+
backoff = {
51+
duration = "30s"
52+
max_duration = "2m"
53+
factor = "2"
54+
}
55+
}
4756
}
4857
4958
ignore_difference {
@@ -133,8 +142,9 @@ Each `info` block can have the following attributes:
133142
* `value` - (Optional).
134143

135144
The `destination` block has the following attributes:
136-
* `server` - (Required) The cluster URL to deploy the application to.
145+
* `server` - (Optional) The cluster URL to deploy the application to. At most one of `server` or `name` is required.
137146
* `namespace` - (Required) The namespace to deploy the application to.
147+
* `name` - (Optional) Name of the destination cluster which can be used instead of server (url) field. At most one of `server` or `name` is required.
138148

139149
The `sync_policy` block has the following attributes:
140150
* `automated` - (Optional) map(string) of strings, will keep an application synced to the target revision. Structure is documented below
@@ -144,6 +154,7 @@ The `sync_policy` block has the following attributes:
144154
The `sync_policy/automated` map has the following attributes:
145155
* `prune` - (Optional), boolean, will prune resources automatically as part of automated sync. Defaults to `false`.
146156
* `self_heal` - (Optional), boolean, enables auto-syncing if the live resources differ from the targeted revision manifests. Defaults to `false`.
157+
* `allow_empty` - (Optional), boolean, allows apps to have zero live resources. Defaults to `false`.
147158

148159
The `sync_policy/retry` block has the following attributes:
149160
* `limit` - (Optional), max number of allowed sync retries, as a string.
@@ -190,6 +201,7 @@ The `kustomize` block has the following attributes:
190201
* `version` - (Optional) string, contains optional Kustomize version.
191202
* `images` - (Optional) set of strings, kustomize image overrides.
192203
* `common_labels` - (Optional) map(string) of strings, adds additional kustomize commonLabels.
204+
* `common_annotations` - (Optional) map(string) of strings, adds additional kustomize commonAnnotations.
193205

194206
The `ksonnet` block has the following attributes:
195207
* `environment` - (Optional) string, Ksonnet application environment name.

docs/resources/project.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ resource "argocd_project" "myproject" {
2929
server = "https://kubernetes.default.svc"
3030
namespace = "foo"
3131
}
32+
destination {
33+
name = "anothercluster"
34+
namespace = "bar"
35+
}
3236
cluster_resource_whitelist {
3337
group = "rbac.authorization.k8s.io"
3438
kind = "ClusterRoleBinding"

0 commit comments

Comments
 (0)