Skip to content

Commit cc3c35e

Browse files
committed
Add ability to target different organization names
Add ability for repo and gitops repo to be hosted in different organizations. This should allow for quite a few use cases, including having a client own a repository but Airnauts owning the gitops repositories
1 parent 223d5cd commit cc3c35e

File tree

4 files changed

+26
-13
lines changed

4 files changed

+26
-13
lines changed

deployment_pipeline/main.tf

+7-7
Original file line numberDiff line numberDiff line change
@@ -484,11 +484,6 @@ resource "aws_codebuild_project" "deployment_gitops_push" {
484484
type = "PLAINTEXT"
485485
value = var.github_user
486486
}
487-
environment_variable {
488-
name = "GITHUB_ORG"
489-
type = "PLAINTEXT"
490-
value = var.github_organization_name
491-
}
492487
environment_variable {
493488
name = "DEVOPS_WEBHOOK_URL"
494489
type = "PLAINTEXT"
@@ -509,6 +504,11 @@ resource "aws_codebuild_project" "deployment_gitops_push" {
509504
type = "PLAINTEXT"
510505
value = var.target_gitops_repository
511506
}
507+
environment_variable {
508+
name = "GITOPS_REPOSITORY_ORGANIZATION"
509+
type = "PLAINTEXT"
510+
value = coalesce(var.target_gitops_organization_name, var.github_organization_name)
511+
}
512512
}
513513
source {
514514
type = "CODEPIPELINE"
@@ -533,7 +533,7 @@ phases:
533533
- git config --global user.email '<>'
534534
- git config --global user.name $GITHUB_USER
535535
- echo "https://$GITHUB_USER:[email protected]" > ~/.git-credentials
536-
- hub clone $GITHUB_ORG/$TARGET_GITOPS_REPOSITORY
536+
- hub clone $GITOPS_REPOSITORY_ORGANIZATION/$TARGET_GITOPS_REPOSITORY
537537
- cd $TARGET_GITOPS_REPOSITORY
538538
- |
539539
export IMAGE_NAME=$(cat $CODEBUILD_SRC_DIR/build.json | jq .RepositoryUri | tr -d '"')
@@ -554,7 +554,7 @@ phases:
554554
git push origin master
555555
556556
COMMIT_HASH=$(git log -n 1 --pretty=format:"%H")
557-
COMMIT_URL=https://github.com/$GITHUB_ORG/$TARGET_GITOPS_REPOSITORY/commit/$COMMIT_HASH
557+
COMMIT_URL=https://github.com/$GITOPS_REPOSITORY_ORGANIZATION/$TARGET_GITOPS_REPOSITORY/commit/$COMMIT_HASH
558558
559559
curl -k -X POST -H "Content-type: application/json" --data "{\"text\":\"### Repository: *$TARGET_GITOPS_REPOSITORY* \n\n New image commited to kustomization/kustomization.yaml: *$IMAGE_NAME:$IMAGE_TAG* \n\n See commit: $COMMIT_URL\"}" $DEVOPS_WEBHOOK_URL
560560
else

deployment_pipeline/variables.tf

+6
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ variable "enable_test_stage" {
8787
default = false
8888
}
8989

90+
variable "target_gitops_organization_name" {
91+
type = string
92+
description = "Gitops organization hosting the target gitops repository. If not provided, defaults to github_organization_name"
93+
default = ""
94+
}
95+
9096
variable "target_gitops_repository" {
9197
type = string
9298
description = "Target gitops repository where the image tag update will be pushed (assumes existence of directory kustomization/kustomization.yaml"

main.tf

+7-6
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@ module "deployment_pipeline" {
3131
environment_variables = var.pipelines[each.key].environment_variables
3232
secret_arns = var.pipelines[each.key].secret_arns
3333

34-
github_repository_name = var.github_repository_name
35-
github_user = var.github_user
36-
github_organization_name = var.github_repository_organization
37-
github_repository_branch = var.github_repository_branch
38-
github_access_token = var.github_access_token
34+
github_repository_name = var.github_repository_name
35+
github_user = var.github_user
36+
github_organization_name = var.github_repository_organization
37+
github_repository_branch = var.github_repository_branch
38+
github_access_token = var.github_access_token
3939
github_access_token_secret_name = var.github_access_token_secret_name
40-
target_gitops_repository = var.target_gitops_repository
40+
target_gitops_repository = var.target_gitops_repository
41+
target_gitops_organization_name = var.target_gitops_organization_name
4142

4243
devops_slack_webhook = var.devops_slack_webhook
4344
devops_slack_channel_name = var.devops_slack_channel_name

variables.tf

+6
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ variable "cloudwatch_log_retention_in_days" {
8787
description = "CloudWatch log retention for /aws/lambda/* and cosmos-*-webhook-proxy-api-gateway"
8888
}
8989

90+
variable "target_gitops_organization_name" {
91+
type = string
92+
description = "Gitops organization hosting the target gitops repository. If not provided, defaults to github_organization_name"
93+
default = ""
94+
}
95+
9096
variable "target_gitops_repository" {
9197
type = string
9298
description = "Target gitops repository where the image tag update will be pushed (assumes existence of directory kustomization/kustomization.yaml"

0 commit comments

Comments
 (0)