Skip to content

Commit b267972

Browse files
[argocd] Added github commit status notifications (cloudposse/terraform-aws-components#631)
Co-authored-by: cloudpossebot <[email protected]>
1 parent 7cc3eb7 commit b267972

File tree

3 files changed

+60
-16
lines changed

3 files changed

+60
-16
lines changed

src/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ components:
150150
| <a name="input_name"></a> [name](#input\_name) | ID element. Usually the component or solution name, e.g. 'app' or 'jenkins'.<br>This is the only ID element not also included as a `tag`.<br>The "name" tag is set to the full `id` string. There is no tag with the value of the `name` input. | `string` | `null` | no |
151151
| <a name="input_namespace"></a> [namespace](#input\_namespace) | ID element. Usually an abbreviation of your organization name, e.g. 'eg' or 'cp', to help ensure generated IDs are globally unique | `string` | `null` | no |
152152
| <a name="input_notifications_default_triggers"></a> [notifications\_default\_triggers](#input\_notifications\_default\_triggers) | Default notification Triggers to configure.<br><br>See: https://argo-cd.readthedocs.io/en/stable/operator-manual/notifications/triggers/#default-triggers<br>See: [Example value in argocd-notifications Helm Chart](https://github.com/argoproj/argo-helm/blob/790438efebf423c2d56cb4b93471f4adb3fcd448/charts/argo-cd/values.yaml#L2841) | `map(list(string))` | `{}` | no |
153-
| <a name="input_notifications_notifiers"></a> [notifications\_notifiers](#input\_notifications\_notifiers) | Notification Triggers to configure.<br><br>See: https://argocd-notifications.readthedocs.io/en/stable/triggers/<br>See: [Example value in argocd-notifications Helm Chart](https://github.com/argoproj/argo-helm/blob/a0a74fb43d147073e41aadc3d88660b312d6d638/charts/argocd-notifications/values.yaml#L352) | <pre>object({<br> ssm_path_prefix = optional(string, "/argocd/notifications/notifiers")<br> service_github = optional(object({<br> appID = optional(number)<br> installationID = optional(number)<br> privateKey = optional(string)<br> }))<br> })</pre> | `{}` | no |
154-
| <a name="input_notifications_templates"></a> [notifications\_templates](#input\_notifications\_templates) | Notification Templates to configure.<br><br>See: https://argocd-notifications.readthedocs.io/en/stable/templates/<br>See: [Example value in argocd-notifications Helm Chart](https://github.com/argoproj/argo-helm/blob/a0a74fb43d147073e41aadc3d88660b312d6d638/charts/argocd-notifications/values.yaml#L158) | <pre>map(object({<br> message = string<br> alertmanager = optional(object({<br> labels = map(string)<br> annotations = map(string)<br> generatorURL = string<br> }))<br> github = optional(object({<br> status = object({<br> state = string<br> label = string<br> targetURL = string<br> })<br> }))<br> }))</pre> | `{}` | no |
153+
| <a name="input_notifications_notifiers"></a> [notifications\_notifiers](#input\_notifications\_notifiers) | Notification Triggers to configure.<br><br>See: https://argocd-notifications.readthedocs.io/en/stable/triggers/<br>See: [Example value in argocd-notifications Helm Chart](https://github.com/argoproj/argo-helm/blob/a0a74fb43d147073e41aadc3d88660b312d6d638/charts/argocd-notifications/values.yaml#L352) | <pre>object({<br> ssm_path_prefix = optional(string, "/argocd/notifications/notifiers")<br> service_github = optional(object({<br> appID = number<br> installationID = number<br> privateKey = optional(string)<br> }))<br> # service.webhook.<webhook-name>:<br> service_webhook = optional(map(<br> object({<br> url = string<br> headers = optional(list(<br> object({<br> name = string<br> value = string<br> })<br> ), [])<br> basicAuth = optional(object({<br> username = string<br> password = string<br> }))<br> insecureSkipVerify = optional(bool, false)<br> })<br> ))<br> })</pre> | `{}` | no |
154+
| <a name="input_notifications_templates"></a> [notifications\_templates](#input\_notifications\_templates) | Notification Templates to configure.<br><br>See: https://argocd-notifications.readthedocs.io/en/stable/templates/<br>See: [Example value in argocd-notifications Helm Chart](https://github.com/argoproj/argo-helm/blob/a0a74fb43d147073e41aadc3d88660b312d6d638/charts/argocd-notifications/values.yaml#L158) | <pre>map(object({<br> message = string<br> alertmanager = optional(object({<br> labels = map(string)<br> annotations = map(string)<br> generatorURL = string<br> }))<br> github = optional(object({<br> status = object({<br> state = string<br> label = string<br> targetURL = string<br> })<br> }))<br> webhook = optional(map(<br> object({<br> method = optional(string)<br> path = optional(string)<br> body = optional(string)<br> })<br> ))<br> }))</pre> | `{}` | no |
155155
| <a name="input_notifications_triggers"></a> [notifications\_triggers](#input\_notifications\_triggers) | Notification Triggers to configure.<br><br>See: https://argocd-notifications.readthedocs.io/en/stable/triggers/<br>See: [Example value in argocd-notifications Helm Chart](https://github.com/argoproj/argo-helm/blob/a0a74fb43d147073e41aadc3d88660b312d6d638/charts/argocd-notifications/values.yaml#L352) | <pre>map(list(<br> object({<br> oncePer = optional(string)<br> send = list(string)<br> when = string<br> })<br> ))</pre> | `{}` | no |
156156
| <a name="input_oidc_enabled"></a> [oidc\_enabled](#input\_oidc\_enabled) | Toggles OIDC integration in the deployed chart | `bool` | `false` | no |
157157
| <a name="input_oidc_issuer"></a> [oidc\_issuer](#input\_oidc\_issuer) | OIDC issuer URL | `string` | `""` | no |

src/main.tf

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ locals {
1111
github_deploy_key = data.aws_ssm_parameter.github_deploy_key[k].value
1212
}
1313
} : {}
14-
credential_templates = flatten([
14+
credential_templates = flatten(concat([
1515
for k, v in local.argocd_repositories : [
1616
{
1717
name = "configs.credentialTemplates.${k}.url"
@@ -20,11 +20,22 @@ locals {
2020
},
2121
{
2222
name = "configs.credentialTemplates.${k}.sshPrivateKey"
23-
value = v.github_deploy_key
23+
value = nonsensitive(v.github_deploy_key)
2424
type = "string"
2525
},
2626
]
27-
])
27+
],
28+
[
29+
for s, v in local.notifications_notifiers_ssm_configs : [
30+
for k, i in v : [
31+
{
32+
name = "notifications.secret.items.${s}_${k}"
33+
value = i
34+
type = "string"
35+
}
36+
]
37+
]
38+
]))
2839
regional_service_discovery_domain = "${module.this.environment}.${module.dns_gbl_delegated.outputs.default_domain_name}"
2940
host = var.host != "" ? var.host : format("%s.%s", coalesce(var.alb_name, var.name), local.regional_service_discovery_domain)
3041
enable_argo_workflows_auth = local.saml_enabled && var.argo_enable_workflows_auth
@@ -94,26 +105,35 @@ data "aws_ssm_parameters_by_path" "argocd_notifications" {
94105
}
95106

96107
locals {
97-
notifications_notifiers_ssm_path = { for key, value in var.notifications_notifiers :
108+
notifications_notifiers_ssm_path = { for key, value in local.notifications_notifiers_variables :
98109
key => format("%s/%s/", var.notifications_notifiers.ssm_path_prefix, key)
99110
}
100111

101112
notifications_notifiers_ssm_configs = { for key, value in data.aws_ssm_parameters_by_path.argocd_notifications :
102-
key => nonsensitive(zipmap(
113+
key => zipmap(
103114
[for name in value.names : trimprefix(name, local.notifications_notifiers_ssm_path[key])],
104115
value.values
105-
))
116+
)
106117
}
107118

108-
notifications_notifiers_variables = {
109-
for key, value in var.notifications_notifiers :
110-
key => { for param_name, param_value in value : param_name => param_value if param_value != null }
111-
if key != "ssm_path_prefix"
119+
notifications_notifiers_ssm_configs_keys = { for key, value in data.aws_ssm_parameters_by_path.argocd_notifications :
120+
key => zipmap(
121+
[for name in value.names : trimprefix(name, local.notifications_notifiers_ssm_path[key])],
122+
[for name in value.names : format("$%s_%s", key, trimprefix(name, local.notifications_notifiers_ssm_path[key]))]
123+
)
112124
}
113125

126+
notifications_notifiers_variables = merge({ for key, value in var.notifications_notifiers :
127+
key => { for param_name, param_value in value : param_name => param_value if param_value != null }
128+
if key != "ssm_path_prefix" && key != "service_webhook"
129+
},
130+
{ for key, value in coalesce(var.notifications_notifiers.service_webhook, {}) :
131+
format("service_webhook_%s", key) => { for param_name, param_value in value : param_name => param_value if param_value != null }
132+
})
133+
114134
notifications_notifiers = {
115135
for key, value in local.notifications_notifiers_variables :
116-
replace(key, "_", ".") => yamlencode(merge(local.notifications_notifiers_ssm_configs[key], value))
136+
replace(key, "_", ".") => yamlencode(merge(local.notifications_notifiers_ssm_configs_keys[key], value))
117137
}
118138
}
119139

@@ -139,7 +159,7 @@ module "argocd" {
139159
service_account_name = module.this.name
140160
service_account_namespace = var.kubernetes_namespace
141161

142-
set_sensitive = local.credential_templates
162+
set_sensitive = nonsensitive(local.credential_templates)
143163

144164
values = compact([
145165
# standard k8s object settings

src/variables-argocd-notifications.tf

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ variable "notifications_templates" {
1313
targetURL = string
1414
})
1515
}))
16+
webhook = optional(map(
17+
object({
18+
method = optional(string)
19+
path = optional(string)
20+
body = optional(string)
21+
})
22+
))
1623
}))
1724
default = {}
1825
description = <<-EOT
@@ -44,10 +51,27 @@ variable "notifications_notifiers" {
4451
type = object({
4552
ssm_path_prefix = optional(string, "/argocd/notifications/notifiers")
4653
service_github = optional(object({
47-
appID = optional(number)
48-
installationID = optional(number)
54+
appID = number
55+
installationID = number
4956
privateKey = optional(string)
5057
}))
58+
# service.webhook.<webhook-name>:
59+
service_webhook = optional(map(
60+
object({
61+
url = string
62+
headers = optional(list(
63+
object({
64+
name = string
65+
value = string
66+
})
67+
), [])
68+
basicAuth = optional(object({
69+
username = string
70+
password = string
71+
}))
72+
insecureSkipVerify = optional(bool, false)
73+
})
74+
))
5175
})
5276
default = {}
5377
description = <<-EOT

0 commit comments

Comments
 (0)