Skip to content

Commit

Permalink
argocd_application: support for kustomize.common_annotations and sync…
Browse files Browse the repository at this point in the history
…_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
  • Loading branch information
oboukili committed Jan 23, 2021
1 parent 3c8ab5c commit 5dc7a8c
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 14 deletions.
14 changes: 12 additions & 2 deletions argocd/resource_argocd_application_test.go
Expand Up @@ -133,6 +133,11 @@ ingress:
"spec.0.sync_policy.0.automated.self_heal",
"true",
),
resource.TestCheckResourceAttr(
"argocd_application.sync_policy",
"spec.0.sync_policy.0.automated.allow_empty",
"true",
),
resource.TestCheckResourceAttr(
"argocd_application.sync_policy",
"spec.0.sync_policy.0.retry.0.backoff.duration",
Expand Down Expand Up @@ -287,6 +292,10 @@ resource "argocd_application" "kustomize" {
"this.is.a.common" = "la-bel"
"another.io/one" = "true"
}
common_annotations = {
"this.is.a.common" = "anno-tation"
"another.io/one" = "false"
}
}
}
Expand Down Expand Up @@ -371,8 +380,9 @@ resource "argocd_application" "sync_policy" {
sync_policy {
automated = {
prune = true
self_heal = true
prune = true
self_heal = true
allow_empty = true
}
retry {
limit = "5"
Expand Down
13 changes: 12 additions & 1 deletion argocd/schema_application.go
Expand Up @@ -22,12 +22,17 @@ func applicationSpecSchema() *schema.Schema {
Schema: map[string]*schema.Schema{
"server": {
Type: schema.TypeString,
Required: true,
Optional: true,
},
"namespace": {
Type: schema.TypeString,
Required: true,
},
"name": {
Type: schema.TypeString,
Optional: true,
Description: "Name of the destination cluster which can be used instead of server.",
},
},
},
},
Expand Down Expand Up @@ -134,6 +139,12 @@ func applicationSpecSchema() *schema.Schema {
Elem: &schema.Schema{Type: schema.TypeString},
ValidateFunc: validateMetadataLabels,
},
"common_annotations": {
Type: schema.TypeMap,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
ValidateFunc: validateMetadataAnnotations,
},
},
},
},
Expand Down
7 changes: 6 additions & 1 deletion argocd/schema_project.go
Expand Up @@ -39,12 +39,17 @@ func projectSpecSchema() *schema.Schema {
Schema: map[string]*schema.Schema{
"server": {
Type: schema.TypeString,
Required: true,
Optional: true,
},
"namespace": {
Type: schema.TypeString,
Required: true,
},
"name": {
Type: schema.TypeString,
Optional: true,
Description: "Name of the destination cluster which can be used instead of server.",
},
},
},
},
Expand Down
27 changes: 20 additions & 7 deletions argocd/structure_application.go
Expand Up @@ -205,6 +205,12 @@ func expandApplicationSourceKustomize(in []interface{}) *application.Application
result.CommonLabels[k] = v.(string)
}
}
if cas, ok := a["common_annotations"]; ok {
result.CommonAnnotations = make(map[string]string, 0)
for k, v := range cas.(map[string]interface{}) {
result.CommonAnnotations[k] = v.(string)
}
}
return result
}

Expand Down Expand Up @@ -262,6 +268,9 @@ func expandApplicationSyncPolicy(_sp []interface{}) (*application.SyncPolicy, er
if k == "self_heal" {
automated.SelfHeal = v.(bool)
}
if k == "allow_empty" {
automated.AllowEmpty = v.(bool)
}
}
}
if v, ok := sp.(map[string]interface{})["sync_options"]; ok {
Expand Down Expand Up @@ -357,6 +366,7 @@ func expandApplicationDestination(dest interface{}) (
return application.ApplicationDestination{
Server: d["server"].(string),
Namespace: d["namespace"].(string),
Name: d["name"].(string),
}
}

Expand Down Expand Up @@ -408,8 +418,9 @@ func flattenApplicationSyncPolicy(sp *application.SyncPolicy) []map[string]inter
backoff := make(map[string]string, 0)
if sp.Automated != nil {
result["automated"] = map[string]bool{
"prune": sp.Automated.Prune,
"self_heal": sp.Automated.SelfHeal,
"prune": sp.Automated.Prune,
"self_heal": sp.Automated.SelfHeal,
"allow_empty": sp.Automated.AllowEmpty,
}
}
result["sync_options"] = []string(sp.SyncOptions)
Expand Down Expand Up @@ -567,11 +578,12 @@ func flattenApplicationSourceKustomize(as []*application.ApplicationSourceKustom
images = append(images, string(i))
}
result = append(result, map[string]interface{}{
"common_labels": a.CommonLabels,
"images": images,
"name_prefix": a.NamePrefix,
"name_suffix": a.NameSuffix,
"version": a.Version,
"common_annotations": a.CommonAnnotations,
"common_labels": a.CommonLabels,
"images": images,
"name_prefix": a.NamePrefix,
"name_suffix": a.NameSuffix,
"version": a.Version,
})
}
}
Expand Down Expand Up @@ -607,6 +619,7 @@ func flattenApplicationDestinations(ds []application.ApplicationDestination) (
result = append(result, map[string]string{
"namespace": d.Namespace,
"server": d.Server,
"name": d.Name,
})
}
return
Expand Down
18 changes: 15 additions & 3 deletions docs/resources/application.md
Expand Up @@ -39,11 +39,20 @@ resource "argocd_application" "kustomize" {
sync_policy {
automated = {
prune = true
self_heal = true
prune = true
self_heal = true
allow_empty = true
}
# Only available from ArgoCD 1.5.0 onwards
sync_options = ["Validate=false"]
retry {
limit = "5"
backoff = {
duration = "30s"
max_duration = "2m"
factor = "2"
}
}
}
ignore_difference {
Expand Down Expand Up @@ -133,8 +142,9 @@ Each `info` block can have the following attributes:
* `value` - (Optional).

The `destination` block has the following attributes:
* `server` - (Required) The cluster URL to deploy the application to.
* `server` - (Optional) The cluster URL to deploy the application to. At most one of `server` or `name` is required.
* `namespace` - (Required) The namespace to deploy the application to.
* `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.

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

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

The `ksonnet` block has the following attributes:
* `environment` - (Optional) string, Ksonnet application environment name.
Expand Down
4 changes: 4 additions & 0 deletions docs/resources/project.md
Expand Up @@ -29,6 +29,10 @@ resource "argocd_project" "myproject" {
server = "https://kubernetes.default.svc"
namespace = "foo"
}
destination {
name = "anothercluster"
namespace = "bar"
}
cluster_resource_whitelist {
group = "rbac.authorization.k8s.io"
kind = "ClusterRoleBinding"
Expand Down

0 comments on commit 5dc7a8c

Please sign in to comment.