Skip to content

Commit

Permalink
massively overhaul the CI/CD
Browse files Browse the repository at this point in the history
This should make managing the stack in the management account easier
  • Loading branch information
tmclaugh committed Oct 24, 2024
1 parent 94cfca5 commit ef1f94d
Show file tree
Hide file tree
Showing 10 changed files with 566 additions and 646 deletions.
35 changes: 23 additions & 12 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,24 @@ jobs:
- name: Install AWS SAM
uses: aws-actions/setup-sam@v2

# FIXME: We're only validating the top-level template and not the rest.
- name: Validate artifact
run: sam validate --lint
- name: Validate artifact (deploy)
run: sam validate --lint -t stackset-deploy-template.yaml

- name: Validate artifact (build)
run: sam validate --lint -t stackset-build-template.yaml

- name: Validate artifact (SAM artifact)
run: sam validate --lint -t stacksets/gha-build/sam-deployment.yaml

- name: Validate artifact (build stackset)
run: sam validate --lint -t stacksets/gha-build/stackset.yaml

- name: Validate artifact (deploy stackset)
run: sam validate --lint -t stacksets/gha-deploy/stackset.yaml

- name: Synethsize StackSet templates
run: |
for _f in $(find . -type f -name 'stackset.yaml'); do
for _f in $(find . -type f -name 'stackset-*-template.yaml'); do
_dir="$(dirname $_f)/" \
yq \
-i \
Expand All @@ -67,7 +78,7 @@ jobs:
shell: bash
run: |
sam package \
--template template.yaml \
--template stacksets/gha-deploy/stackset.yaml \
--s3-bucket aws-sam-cli-sourcebucket-225989329251-us-east-1 \
--s3-prefix ${{ env.GITHUB_REPOSITORY_OWNER_PART_SLUG_URL }}/${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL }}/${{ env.GITHUB_REF_SLUG_URL }} \
--region us-east-1 \
Expand All @@ -78,22 +89,22 @@ jobs:
shell: bash
run: |
sam package \
--template stacksets-build-template.yaml \
--template stackset-build-template.yaml \
--s3-bucket aws-sam-cli-sourcebucket-225989329251-us-east-1 \
--s3-prefix ${{ env.GITHUB_REPOSITORY_OWNER_PART_SLUG_URL }}/${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL }}/${{ env.GITHUB_REF_SLUG_URL }} \
--region us-east-1 \
--output-template-file packaged-stacksets-build-template.yaml
--output-template-file packaged-stackset-build-template.yaml
- name: Upload SAM artifact (Deploy Account)
id: upload-sam-stackset-deploy-template
shell: bash
run: |
sam package \
--template stacksets-deploy-template.yaml \
--template stackset-deploy-template.yaml \
--s3-bucket aws-sam-cli-sourcebucket-225989329251-us-east-1 \
--s3-prefix ${{ env.GITHUB_REPOSITORY_OWNER_PART_SLUG_URL }}/${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL }}/${{ env.GITHUB_REF_SLUG_URL }} \
--region us-east-1 \
--output-template-file packaged-stacksets-deploy-template.yaml
--output-template-file packaged-stackset-deploy-template.yaml
- name: Store Artifacts
uses: ServerlessOpsIO/gha-store-artifacts@v1
Expand Down Expand Up @@ -147,8 +158,8 @@ jobs:
uses: ServerlessOpsIO/gha-deploy-aws-sam@v1
with:
aws_account_id: ${{ secrets.AWS_MANAGEMENT_ACCOUNT_ID }}
template_file: packaged-stacksets-build-template.yaml
stack_name: "${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL }}-${{ env.GITHUB_EVENT_REF_SLUG_URL }}-build"
template_file: packaged-stackset-build-template.yaml
stack_name: "${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL }}-${{ env.GITHUB_EVENT_REF_SLUG_URL }}-stackset-build"
cfn_capabilities: CAPABILITY_NAMED_IAM,CAPABILITY_AUTO_EXPAND
env_json: ${{ toJson(env) }}
secrets_json: ${{ toJson(secrets) }}
Expand Down Expand Up @@ -204,7 +215,7 @@ jobs:
uses: ServerlessOpsIO/gha-deploy-aws-sam@v1
with:
aws_account_id: ${{ secrets.AWS_MANAGEMENT_ACCOUNT_ID }}
stack_name: "${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL }}-${{ env.GITHUB_EVENT_REF_SLUG_URL }}-deploy"
stack_name: "${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL }}-${{ env.GITHUB_EVENT_REF_SLUG_URL }}-stackset-deploy"
template_file: packaged-stacksets-deploy-template.yaml
cfn_capabilities: CAPABILITY_NAMED_IAM,CAPABILITY_AUTO_EXPAND
env_json: ${{ toJson(env) }}
Expand Down
78 changes: 78 additions & 0 deletions stackset-build-template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
Metadata:
GhaStack:
localTemplateFile: &gha_stackset_body ./stacksets/gha-build/stackset.yaml
SamStack:
localTemplateFile: &sam_template_body ./stacksets/gha-build/sam-deployment.yaml

AWSTemplateFormatVersion: '2010-09-09'
Transform:
- 'AWS::Serverless-2016-10-31'
Description: GitHib Actions integration stacks

Parameters:
TargetOuIds:
Type: CommaDelimitedList
Description: Comma separated list of OUs
TargetRegions:
Type: CommaDelimitedList
Description: Comma separated list of regions
AwsOrganizationId:
Type: String
Description: AWS Organization ID

Resources:
OrgCiCdSamArtifacts:
Type: AWS::CloudFormation::StackSet
Properties:
StackSetName: CiCdSamArtifacts
Description: AWS SAM Deployment
Parameters:
- ParameterKey: AwsOrganizationId
ParameterValue: !Ref AwsOrganizationId
- ParameterKey: BuildAccount
ParameterValue: 'true'
StackInstancesGroup:
- DeploymentTargets:
OrganizationalUnitIds: !Ref TargetOuIds
Regions: !Ref TargetRegions
AutoDeployment:
Enabled: true
RetainStacksOnAccountRemoval: false
ManagedExecution:
Active: true
OperationPreferences:
RegionConcurrencyType: PARALLEL
FailureToleranceCount: 1
MaxConcurrentCount: 5
PermissionModel: SERVICE_MANAGED
TemplateBody: *sam_template_body


OrgCiCdGhaBuild:
Type: AWS::CloudFormation::StackSet
DependsOn: OrgCiCdSamArtifacts
Properties:
StackSetName: CiCdGhaBuild
Description: GHA CI/CD Deployment Build
Parameters:
- ParameterKey: DeployBucketArn
ParameterValue: '/org/cicd/SamDeployBucketArn'
- ParameterKey: AwsOrganizationId
ParameterValue: !Ref AwsOrganizationId
StackInstancesGroup:
- DeploymentTargets:
OrganizationalUnitIds: !Ref TargetOuIds
Regions: !Ref TargetRegions
Capabilities:
- CAPABILITY_NAMED_IAM
AutoDeployment:
Enabled: true
RetainStacksOnAccountRemoval: false
ManagedExecution:
Active: true
OperationPreferences:
RegionConcurrencyType: PARALLEL
FailureToleranceCount: 1
MaxConcurrentCount: 5
PermissionModel: SERVICE_MANAGED
TemplateBody: *gha_stackset_body
49 changes: 49 additions & 0 deletions stackset-deploy-template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
Metadata:
localTemplateFile: &template_body stacksets/gha-deploy/template.yaml

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: AWS account infrastructure stackset (GHA Deployments)

Parameters:
TargetOuIds:
Type: CommaDelimitedList
Description: List of OUs
TargetRegions:
Type: CommaDelimitedList
Description: Regions to deploy to
CicdAwsAccountId:
Type: String
Description: AWS Account ID for CI/CD
DeployBucketArn:
Type: String
Description: S3 bucket ARN for deployment

Resources:
OrgCiCdGhaDeploy:
Type: AWS::CloudFormation::StackSet
Properties:
StackSetName: CiCdGhaDeploy
Description: GHA CI/CD Deployment
Parameters:
- ParameterKey: CicdAwsAccountId
ParameterValue: !Ref CicdAwsAccountId
- ParameterKey: DeployBucketArn
ParameterValue: !Ref DeployBucketArn
Capabilities:
- CAPABILITY_NAMED_IAM
StackInstancesGroup:
- DeploymentTargets:
OrganizationalUnitIds: !Ref TargetOuIds
Regions: !Ref TargetRegions
AutoDeployment:
Enabled: true
RetainStacksOnAccountRemoval: false
ManagedExecution:
Active: true
OperationPreferences:
RegionConcurrencyType: PARALLEL
FailureToleranceCount: 1
MaxConcurrentCount: 5
PermissionModel: SERVICE_MANAGED
TemplateBody: *template_body
31 changes: 0 additions & 31 deletions stacksets-build-template.yaml

This file was deleted.

32 changes: 0 additions & 32 deletions stacksets-deploy-template.yaml

This file was deleted.

Loading

0 comments on commit ef1f94d

Please sign in to comment.