Skip to content

Commit

Permalink
feat!: New config file and support for multiple pipelines (#159)
Browse files Browse the repository at this point in the history
Co-authored-by: Will Gibson <[email protected]>
  • Loading branch information
antroy-madetech and WillGibson authored Jun 21, 2024
1 parent 5a742be commit 4399fc9
Show file tree
Hide file tree
Showing 9 changed files with 200 additions and 170 deletions.
15 changes: 10 additions & 5 deletions environment-pipelines/buildspec-apply.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,18 @@ phases:
build:
commands:
- set -e
- echo "Terraform Apply Phase"
- echo -e "\nTerraform Apply Phase"
- platform-helper notify add-comment "${SLACK_CHANNEL_ID}" "${SLACK_TOKEN}" "${SLACK_REF}" "Starting terraform apply phase for the ${ENVIRONMENT} environment."
- echo "Working on environment ${ENVIRONMENT}"
- cd terraform/environments/${ENVIRONMENT}
- echo -e "\nWorking on environment ${ENVIRONMENT}"
- cd "terraform/environments/${ENVIRONMENT}"
- terraform init
- terraform apply $PLAN_TF_DIR/terraform/environments/${ENVIRONMENT}/plan.tfplan
- copilot env deploy --name ${ENVIRONMENT}
- terraform apply "${PLAN_TF_DIR}/terraform/environments/${ENVIRONMENT}/plan.tfplan"
- echo -e "\nGenerating manifests and deploying AWS Copilot environment resources"
- cd "${CODEBUILD_SRC_DIR}"
- platform-helper environment generate --name "${ENVIRONMENT}"
- copilot env init --name "${ENVIRONMENT}" --profile "${COPILOT_PROFILE}" --default-config
- platform-helper copilot make-addons
- copilot env deploy --name "${ENVIRONMENT}"
post_build:
commands:
- |
Expand Down
5 changes: 2 additions & 3 deletions environment-pipelines/buildspec-plan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ phases:
- echo "Terraform Plan Phase"
- platform-helper notify add-comment "${SLACK_CHANNEL_ID}" "${SLACK_TOKEN}" "${SLACK_REF}" "Starting terraform plan phase for the ${ENVIRONMENT} environment."
- echo "Working on environment ${ENVIRONMENT}"
- echo "Generating manifests"
- copilot env init --name ${ENVIRONMENT} --profile ${COPILOT_PROFILE} --default-config
- platform-helper copilot make-addons
- platform-helper environment generate-terraform --name "${ENVIRONMENT}"
- cd terraform/environments/${ENVIRONMENT}
- terraform init
- terraform plan -out=plan.tfplan
Expand All @@ -40,3 +38,4 @@ phases:
artifacts:
files:
- terraform/environments/${ENVIRONMENT}/plan.tfplan
- copilot/environments/${ENVIRONMENT}/manifest.yml
12 changes: 6 additions & 6 deletions environment-pipelines/codebuild.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
resource "aws_codebuild_project" "environment_pipeline_build" {
name = "${var.application}-environment-pipeline-build"
name = "${var.application}-${var.pipeline_name}-environment-pipeline-build"
description = "Provisions the ${var.application} application's extensions."
build_timeout = 5
service_role = aws_iam_role.environment_pipeline_codebuild.arn
Expand Down Expand Up @@ -37,19 +37,19 @@ resource "aws_codebuild_project" "environment_pipeline_build" {
}

resource "aws_cloudwatch_log_group" "environment_pipeline_codebuild" {
name = "codebuild/${var.application}-environment-terraform/log-group"
name = "codebuild/${var.application}-${var.pipeline_name}-environment-terraform/log-group"
# checkov:skip=CKV_AWS_338:Retains logs for 3 months instead of 1 year
retention_in_days = 90
}

resource "aws_cloudwatch_log_stream" "environment_pipeline_codebuild" {
name = "codebuild/${var.application}-environment-terraform/log-stream"
name = "codebuild/${var.application}-${var.pipeline_name}-environment-terraform/log-stream"
log_group_name = aws_cloudwatch_log_group.environment_pipeline_codebuild.name
}

# Terraform plan
resource "aws_codebuild_project" "environment_pipeline_plan" {
name = "${var.application}-environment-pipeline-plan"
name = "${var.application}-${var.pipeline_name}-environment-pipeline-plan"
description = "Provisions the ${var.application} application's extensions."
build_timeout = 5
service_role = aws_iam_role.environment_pipeline_codebuild.arn
Expand Down Expand Up @@ -88,9 +88,9 @@ resource "aws_codebuild_project" "environment_pipeline_plan" {

# Terraform apply
resource "aws_codebuild_project" "environment_pipeline_apply" {
name = "${var.application}-environment-pipeline-apply"
name = "${var.application}-${var.pipeline_name}-environment-pipeline-apply"
description = "Provisions the ${var.application} application's extensions."
build_timeout = 60
build_timeout = 120
service_role = aws_iam_role.environment_pipeline_codebuild.arn
encryption_key = module.artifact_store.kms_key_arn

Expand Down
14 changes: 8 additions & 6 deletions environment-pipelines/codepipeline.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ data "aws_codestarconnections_connection" "github_codestar_connection" {
}

resource "aws_codepipeline" "environment_pipeline" {
name = "${var.application}-environment-pipeline"
role_arn = aws_iam_role.environment_pipeline_codepipeline.arn
depends_on = [aws_iam_role_policy.artifact_store_access_for_environment_codebuild]
name = "${var.application}-${var.pipeline_name}-environment-pipeline"
role_arn = aws_iam_role.environment_pipeline_codepipeline.arn
depends_on = [aws_iam_role_policy.artifact_store_access_for_environment_codebuild]
pipeline_type = "V2"

artifact_store {
location = module.artifact_store.bucket_name
Expand All @@ -32,6 +33,7 @@ resource "aws_codepipeline" "environment_pipeline" {
ConnectionArn = data.aws_codestarconnections_connection.github_codestar_connection.arn
FullRepositoryId = var.repository
BranchName = var.branch
DetectChanges = var.trigger_on_push
}
}
}
Expand All @@ -50,7 +52,7 @@ resource "aws_codepipeline" "environment_pipeline" {
namespace = "slack"

configuration = {
ProjectName = "${var.application}-environment-pipeline-build"
ProjectName = "${var.application}-${var.pipeline_name}-environment-pipeline-build"
PrimarySource = "project_deployment_source"
EnvironmentVariables : jsonencode([
{ name : "APPLICATION", value : var.application },
Expand Down Expand Up @@ -88,9 +90,9 @@ module "artifact_store" {

application = var.application
environment = "not-applicable"
name = "${var.application}-environment-pipeline-artifact-store"
name = "${var.application}-${var.pipeline_name}-environment-pipeline-artifact-store"

config = {
bucket_name = "${var.application}-environment-pipeline-artifact-store"
bucket_name = "${var.application}-${var.pipeline_name}-environment-pipeline-artifact-store"
}
}
Loading

0 comments on commit 4399fc9

Please sign in to comment.