Skip to content

Commit f4bbf86

Browse files
authored
feat: Deploy Keys as Optional (#43)
* Deploy keys optional * Deploy keys optional * fixed enabled flag
1 parent 606f12c commit f4bbf86

File tree

8 files changed

+22
-10
lines changed

8 files changed

+22
-10
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,4 @@ github/
7676
*.ovpn
7777

7878
*.zip
79+
account-map/

src/README.md

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/applicationset.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ resource "github_repository_file" "application_set" {
1515
ignore-differences = each.value.ignore-differences
1616
name = module.this.namespace
1717
namespace = local.manifest_kubernetes_namespace
18-
ssh_url = local.github_repository.ssh_clone_url
18+
url = local.deploy_keys_enabled ? local.github_repository.ssh_clone_url : local.github_repository.http_clone_url
1919
notifications = local.github_notifications
2020
slack_notifications_channel = var.slack_notifications_channel
2121
})

src/main.tf

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
locals {
2-
enabled = module.this.enabled
2+
enabled = module.this.enabled
3+
deploy_keys_enabled = local.enabled && var.deploy_keys_enabled
34

45
environments = local.enabled ? {
56
for env in var.environments :
@@ -118,14 +119,14 @@ resource "github_team_repository" "default" {
118119
}
119120

120121
resource "tls_private_key" "default" {
121-
for_each = local.environments
122+
for_each = local.deploy_keys_enabled ? local.environments : {}
122123

123124
algorithm = "RSA"
124125
rsa_bits = "2048"
125126
}
126127

127128
resource "github_repository_deploy_key" "default" {
128-
for_each = local.environments
129+
for_each = local.deploy_keys_enabled ? local.environments : {}
129130

130131
title = "Deploy key for ArgoCD environment: ${each.key} (${local.github_repository.default_branch} branch)"
131132
repository = local.github_repository.name

src/outputs.tf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
output "deploy_keys_ssm_paths" {
22
description = "SSM Parameter Store paths for the repository's deploy keys"
3-
value = module.store_write.names
3+
value = local.deploy_keys_enabled ? module.store_write.names : []
44
}
55

66
output "deploy_keys_ssm_path_format" {
@@ -37,3 +37,8 @@ output "repository_ssh_clone_url" {
3737
description = "Repository SSH clone URL"
3838
value = local.enabled ? local.github_repository.ssh_clone_url : null
3939
}
40+
41+
output "repository_http_clone_url" {
42+
description = "Repository HTTP clone URL"
43+
value = local.enabled ? local.github_repository.http_clone_url : null
44+
}

src/provider-github.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ module "store_write" {
1414
source = "cloudposse/ssm-parameter-store/aws"
1515
version = "0.13.0"
1616

17-
parameter_write = [for k, v in local.environments :
17+
parameter_write = local.deploy_keys_enabled ? [for k, v in local.environments :
1818
{
1919
name = format(var.ssm_github_deploy_key_format, k)
2020
value = tls_private_key.default[k].private_key_pem
2121
type = "SecureString"
2222
overwrite = true
2323
description = github_repository_deploy_key.default[k].title
2424
}
25-
]
25+
] : []
2626

2727
context = module.this.context
2828
}

src/templates/applicationset.yaml.tpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ metadata:
3737
spec:
3838
generators:
3939
- git:
40-
repoURL: ${ssh_url}
40+
repoURL: ${url}
4141
revision: HEAD
4242
files:
4343
- path: ${environment}/apps/*/*/config.yaml
@@ -63,7 +63,7 @@ spec:
6363
spec:
6464
project: ${name}
6565
source:
66-
repoURL: ${ssh_url}
66+
repoURL: ${url}
6767
targetRevision: HEAD
6868
path: '{{manifests}}'
6969
destination:

src/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,9 @@ variable "use_local_github_credentials" {
209209
description = "Use local GitHub credentials from environment variables instead of SSM"
210210
default = false
211211
}
212+
213+
variable "deploy_keys_enabled" {
214+
type = bool
215+
description = "Enable GitHub deploy keys for the repository. These are used for Argo CD application syncing. Alternatively, you can use a GitHub App to access this desired state repository."
216+
default = true
217+
}

0 commit comments

Comments
 (0)