Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,4 @@ github/
*.ovpn

*.zip
account-map/
1 change: 0 additions & 1 deletion src/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/applicationset.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ resource "github_repository_file" "application_set" {
ignore-differences = each.value.ignore-differences
name = module.this.namespace
namespace = local.manifest_kubernetes_namespace
ssh_url = local.github_repository.ssh_clone_url
url = local.deploy_keys_enabled ? local.github_repository.ssh_clone_url : local.github_repository.http_clone_url
notifications = local.github_notifications
slack_notifications_channel = var.slack_notifications_channel
})
Expand Down
7 changes: 4 additions & 3 deletions src/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
locals {
enabled = module.this.enabled
enabled = module.this.enabled
deploy_keys_enabled = local.enabled && var.deploy_keys_enabled

environments = local.enabled ? {
for env in var.environments :
Expand Down Expand Up @@ -118,14 +119,14 @@ resource "github_team_repository" "default" {
}

resource "tls_private_key" "default" {
for_each = local.environments
for_each = local.deploy_keys_enabled ? local.environments : {}

algorithm = "RSA"
rsa_bits = "2048"
}

resource "github_repository_deploy_key" "default" {
for_each = local.environments
for_each = local.deploy_keys_enabled ? local.environments : {}

title = "Deploy key for ArgoCD environment: ${each.key} (${local.github_repository.default_branch} branch)"
repository = local.github_repository.name
Expand Down
7 changes: 6 additions & 1 deletion src/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
output "deploy_keys_ssm_paths" {
description = "SSM Parameter Store paths for the repository's deploy keys"
value = module.store_write.names
value = local.deploy_keys_enabled ? module.store_write.names : []
}

output "deploy_keys_ssm_path_format" {
Expand Down Expand Up @@ -37,3 +37,8 @@ output "repository_ssh_clone_url" {
description = "Repository SSH clone URL"
value = local.enabled ? local.github_repository.ssh_clone_url : null
}

output "repository_http_clone_url" {
description = "Repository HTTP clone URL"
value = local.enabled ? local.github_repository.http_clone_url : null
}
4 changes: 2 additions & 2 deletions src/provider-github.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ module "store_write" {
source = "cloudposse/ssm-parameter-store/aws"
version = "0.13.0"

parameter_write = [for k, v in local.environments :
parameter_write = local.deploy_keys_enabled ? [for k, v in local.environments :
{
name = format(var.ssm_github_deploy_key_format, k)
value = tls_private_key.default[k].private_key_pem
type = "SecureString"
overwrite = true
description = github_repository_deploy_key.default[k].title
}
]
] : []

context = module.this.context
}
Expand Down
4 changes: 2 additions & 2 deletions src/templates/applicationset.yaml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ metadata:
spec:
generators:
- git:
repoURL: ${ssh_url}
repoURL: ${url}
revision: HEAD
files:
- path: ${environment}/apps/*/*/config.yaml
Expand All @@ -63,7 +63,7 @@ spec:
spec:
project: ${name}
source:
repoURL: ${ssh_url}
repoURL: ${url}
targetRevision: HEAD
path: '{{manifests}}'
destination:
Expand Down
6 changes: 6 additions & 0 deletions src/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,9 @@ variable "use_local_github_credentials" {
description = "Use local GitHub credentials from environment variables instead of SSM"
default = false
}

variable "deploy_keys_enabled" {
type = bool
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."
default = true
}
Loading