Skip to content

Commit 6c54e68

Browse files
authored
feat: Use atlantis bot instead of a github user (#151)
1 parent 0447f0a commit 6c54e68

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ allow_github_webhooks = true
203203
| atlantis\_github\_user | GitHub username that is running the Atlantis command | `string` | `""` | no |
204204
| atlantis\_github\_user\_token | GitHub token of the user that is running the Atlantis command | `string` | `""` | no |
205205
| atlantis\_github\_user\_token\_ssm\_parameter\_name | Name of SSM parameter to keep atlantis\_github\_user\_token | `string` | `"/atlantis/github/user/token"` | no |
206+
| atlantis\_github\_webhook\_secret | GitHub webhook secret of an app that is running the Atlantis command | `string` | `""` | no |
206207
| atlantis\_gitlab\_hostname | Gitlab server hostname, defaults to gitlab.com | `string` | `"gitlab.com"` | no |
207208
| atlantis\_gitlab\_user | Gitlab username that is running the Atlantis command | `string` | `""` | no |
208209
| atlantis\_gitlab\_user\_token | Gitlab token of the user that is running the Atlantis command | `string` | `""` | no |

main.tf

+12-9
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ locals {
1717
# Include only one group of secrets - for github, gitlab or bitbucket
1818
has_secrets = var.atlantis_gitlab_user_token != "" || var.atlantis_github_user_token != "" || var.atlantis_bitbucket_user_token != ""
1919

20-
secret_name_key = local.has_secrets ? var.atlantis_gitlab_user_token != "" ? "ATLANTIS_GITLAB_TOKEN" : var.atlantis_github_user_token != "" ? "ATLANTIS_GH_TOKEN" : "ATLANTIS_BITBUCKET_TOKEN" : "unknown_secret_name_key"
20+
# token
21+
secret_name_key = local.has_secrets ? var.atlantis_gitlab_user_token != "" ? "ATLANTIS_GITLAB_TOKEN" : var.atlantis_github_user_token != "" ? "ATLANTIS_GH_TOKEN" : "ATLANTIS_BITBUCKET_TOKEN" : ""
22+
secret_name_value_from = local.has_secrets ? var.atlantis_gitlab_user_token != "" ? var.atlantis_gitlab_user_token_ssm_parameter_name : var.atlantis_github_user_token != "" ? var.atlantis_github_user_token_ssm_parameter_name : var.atlantis_bitbucket_user_token_ssm_parameter_name : ""
2123

22-
secret_name_value_from = local.has_secrets ? var.atlantis_gitlab_user_token != "" ? var.atlantis_gitlab_user_token_ssm_parameter_name : var.atlantis_github_user_token != "" ? var.atlantis_github_user_token_ssm_parameter_name : var.atlantis_bitbucket_user_token_ssm_parameter_name : "unknown_secret_name_value"
23-
24-
secret_webhook_key = local.has_secrets ? var.atlantis_gitlab_user_token != "" ? "ATLANTIS_GITLAB_WEBHOOK_SECRET" : var.atlantis_github_user_token != "" ? "ATLANTIS_GH_WEBHOOK_SECRET" : "ATLANTIS_BITBUCKET_WEBHOOK_SECRET" : "unknown_secret_webhook_key"
24+
# webhook
25+
secret_webhook_key = local.has_secrets || var.atlantis_github_webhook_secret != "" ? var.atlantis_gitlab_user_token != "" ? "ATLANTIS_GITLAB_WEBHOOK_SECRET" : var.atlantis_github_user_token != "" || var.atlantis_github_webhook_secret != "" ? "ATLANTIS_GH_WEBHOOK_SECRET" : "ATLANTIS_BITBUCKET_WEBHOOK_SECRET" : ""
2526

2627
# determine if the alb has authentication enabled, otherwise forward the traffic unauthenticated
2728
alb_authenication_method = length(keys(var.alb_authenticate_oidc)) > 0 ? "authenticate-oidc" : length(keys(var.alb_authenticate_cognito)) > 0 ? "authenticate-cognito" : "forward"
@@ -77,20 +78,20 @@ locals {
7778
]
7879

7980
# Secret access tokens
80-
container_definition_secrets_1 = [
81+
container_definition_secrets_1 = local.secret_name_key != "" && local.secret_name_value_from != "" ? [
8182
{
8283
name = local.secret_name_key
8384
valueFrom = local.secret_name_value_from
8485
},
85-
]
86+
] : []
8687

8788
# Webhook secrets are not supported by BitBucket
88-
container_definition_secrets_2 = [
89+
container_definition_secrets_2 = local.secret_webhook_key != "" ? [
8990
{
9091
name = local.secret_webhook_key
9192
valueFrom = var.webhook_ssm_parameter_name
9293
},
93-
]
94+
] : []
9495

9596
tags = merge(
9697
{
@@ -113,6 +114,8 @@ data "aws_route53_zone" "this" {
113114
# Secret for webhook
114115
###################
115116
resource "random_id" "webhook" {
117+
count = var.atlantis_github_webhook_secret != "" ? 0 : 1
118+
116119
byte_length = "64"
117120
}
118121

@@ -121,7 +124,7 @@ resource "aws_ssm_parameter" "webhook" {
121124

122125
name = var.webhook_ssm_parameter_name
123126
type = "SecureString"
124-
value = random_id.webhook.hex
127+
value = coalesce(var.atlantis_github_webhook_secret, join("", random_id.webhook.*.hex))
125128

126129
tags = local.tags
127130
}

variables.tf

+6
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,12 @@ variable "atlantis_github_user_token" {
452452
default = ""
453453
}
454454

455+
variable "atlantis_github_webhook_secret" {
456+
description = "GitHub webhook secret of an app that is running the Atlantis command"
457+
type = string
458+
default = ""
459+
}
460+
455461
# Gitlab
456462
variable "atlantis_gitlab_user" {
457463
description = "Gitlab username that is running the Atlantis command"

0 commit comments

Comments
 (0)