Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module12 #13

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b326160
Lab 12.1.1
afisher-stelligent Jul 12, 2022
7e9951a
Lab 12.1.1 fixing pipeline errors
afisher-stelligent Jul 12, 2022
f9a14db
Fixed stack parameters
afisher-stelligent Jul 12, 2022
13850a6
Final tweaks for 12.1.1
afisher-stelligent Jul 12, 2022
e22ec08
First part of 12.1.2
afisher-stelligent Jul 12, 2022
e5d1a01
further tweaking of 12.1.2
afisher-stelligent Jul 12, 2022
72108ff
further tweaking of 12.1.2
afisher-stelligent Jul 12, 2022
c97acf8
further tweaking of 12.1.2
afisher-stelligent Jul 12, 2022
77d56eb
fixed bug
afisher-stelligent Jul 12, 2022
ca0d8f4
Fixing buildspec
afisher-stelligent Jul 12, 2022
dce017a
fixed typo
afisher-stelligent Jul 12, 2022
df8a011
tweaked buildspec:
afisher-stelligent Jul 12, 2022
9c89b60
fixed python runtime version
afisher-stelligent Jul 12, 2022
6d60fd2
unnecessary commands
afisher-stelligent Jul 12, 2022
9130a2e
Start of test stage for 12.1.2
afisher-stelligent Jul 13, 2022
99f5e1d
fixed typo
afisher-stelligent Jul 13, 2022
f32d2f9
Permission fixes attempt
afisher-stelligent Jul 13, 2022
bddca83
Fixed typo in testspec.yml
afisher-stelligent Jul 13, 2022
d8054ee
Fixed another typo
afisher-stelligent Jul 13, 2022
07fb94a
debugging
afisher-stelligent Jul 13, 2022
bfee432
Fixed access for bucket
afisher-stelligent Jul 13, 2022
25c196d
Final cleanup and finish of lab 12.1.2
afisher-stelligent Jul 13, 2022
4aaaaa7
Lab 12.2.1
afisher-stelligent Jul 13, 2022
1088823
Lab 12.2.2
afisher-stelligent Jul 13, 2022
6fe255b
Forgot the webhook...
afisher-stelligent Jul 13, 2022
ce157c2
Updated Key in Appstack
afisher-stelligent Jul 13, 2022
cd2157f
Updated AppStack PK
afisher-stelligent Jul 13, 2022
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ __pycache__

.ruby-version
*.pem
00-dev-environment/aws-mfa-cli/.venv
00-dev-environment/aws-mfa-cli/.venv
12-codepipeline/1211_parameters.json
12-codepipeline/12.2/pipeline_parameters.json
251 changes: 251 additions & 0 deletions 12-codepipeline/12.1.1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
---
AWSTemplateFormatVersion: '2010-09-09'
Description: Lab 12.1.1

Parameters:
GHToken:
Type: String
NoEcho: true
MinLength: '40'
MaxLength: '40'

CodeOwner:
Type: String
AllowedPattern: '[A-Za-z0-9-]+'
Default: afisher-stelligent

Repo:
Type: String
AllowedPattern: '[A-Za-z0-9-]+'
Default: stelligent-u

Branch:
Type: String
AllowedPattern: '[A-Za-z0-9-]+'
Default: module12

AppStackName:
Type: String
AllowedPattern: '[A-Za-z0-9-]+'
Default: allen-f-module12-app

CfnTemplatePath:
Type: String
Default: 12-codepipeline/bucket.yaml

StackBucketName:
Type: String
Default: allenmodule12.codepipeline.bucket

Resources:
ArtifactBucket:
Type: AWS::S3::Bucket
Properties:
VersioningConfiguration:
Status: Enabled

CodeBuildProject:
Type: AWS::CodeBuild::Project
Properties:
Artifacts:
Type: CODEPIPELINE
Source:
Type: CODEPIPELINE
BuildSpec: 12-codepipeline/buildspec.yml
Environment:
ComputeType: BUILD_GENERAL1_SMALL
Image: aws/codebuild/amazonlinux2-x86_64-standard:4.0
Type: LINUX_CONTAINER
Name: !Ref AWS::StackName
ServiceRole: !Ref CodeBuildRole

CodeBuildTestProject:
Type: AWS::CodeBuild::Project
Properties:
Name: !Sub ${AWS::StackName}-testing
Artifacts:
Type: CODEPIPELINE
Source:
Type: CODEPIPELINE
BuildSpec: 12-codepipeline/testspec.yml
Environment:
ComputeType: BUILD_GENERAL1_SMALL
Image: aws/codebuild/amazonlinux2-x86_64-standard:4.0
Type: LINUX_CONTAINER
EnvironmentVariables:
- Name: S3_BUCKET
Type: PLAINTEXT
Value: !Ref StackBucketName
ServiceRole: !Ref CodeBuildRole

MyCodePipeline:
Type: AWS::CodePipeline::Pipeline
Properties:
ArtifactStore:
Type: S3
Location: !Ref ArtifactBucket
RestartExecutionOnUpdate: true
RoleArn: !GetAtt PipelineRole.Arn
Stages:
- Name: Source
Actions:
- Name: GetSource
InputArtifacts: []
ActionTypeId:
Category: Source
Owner: ThirdParty
Version: '1'
Provider: GitHub
OutputArtifacts:
- Name: SourceCode
Configuration:
Owner: !Ref CodeOwner
Repo: !Ref Repo
Branch: !Ref Branch
PollForSourceChanges: false
OAuthToken: !Ref GHToken
RunOrder: 1

- Name: BuildIt
Actions:
- Name: BuildIt
ActionTypeId:
Category: Build
Owner: AWS
Version: '1'
Provider: CodeBuild
Configuration:
ProjectName: !Ref CodeBuildProject
InputArtifacts:
- Name: SourceCode
RunOrder: 1

- Name: Deploy
Actions:
- Name: CloudFormationDeploy
ActionTypeId:
Category: Deploy
Owner: AWS
Provider: CloudFormation
Version: '1'
InputArtifacts:
- Name: SourceCode
Configuration:
ActionMode: CREATE_UPDATE
Capabilities: CAPABILITY_IAM
RoleArn: !GetAtt CfnRole.Arn
StackName: !Ref AppStackName
TemplatePath: !Sub SourceCode::${CfnTemplatePath}
ParameterOverrides: !Sub '{"BucketNameParameter": "${StackBucketName}"}'
OutputArtifacts:
- Name: S3Bucket
RunOrder: 1

- Name: Test
Actions:
- Name: ValidateBucketExists
ActionTypeId:
Category: Build
Owner: AWS
Provider: CodeBuild
Version: '1'
InputArtifacts:
- Name: SourceCode
Configuration:
ProjectName: !Ref CodeBuildTestProject
RunOrder: 1

# ROLES
PipelineRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Action: [sts:AssumeRole]
Effect: Allow
Principal:
Service: [codepipeline.amazonaws.com]
Version: '2012-10-17'
Path: /
Policies:
- PolicyName: CodePipelineAccess
PolicyDocument:
Version: '2012-10-17'
Statement:
- Action:
- s3:*
- cloudformation:CreateStack
- cloudformation:DescribeStacks
- cloudformation:DeleteStack
- cloudformation:UpdateStack
- cloudformation:CreateChangeSet
- cloudformation:ExecuteChangeSet
- cloudformation:DeleteChangeSet
- cloudformation:DescribeChangeSet
- cloudformation:SetStackPolicy
- codebuild:StartBuild
- codebuild:BatchGetBuilds
- iam:PassRole
Effect: Allow
Resource: '*'
CfnRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
Effect: Allow
Principal:
Service: cloudformation.amazonaws.com
Action: sts:AssumeRole
ManagedPolicyArns:
- arn:aws:iam::aws:policy/AdministratorAccess

CodeBuildRole:
Type: AWS::IAM::Role
Properties:
Path: /
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service: codebuild.amazonaws.com
Action: sts:AssumeRole
Policies:
- PolicyName: S3
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- s3:GetObject
- s3:PutObject
- s3:GetObjectVersion
Resource: !Sub ${ArtifactBucket.Arn}/*
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource: '*'
- Effect: Allow
Action:
- s3:ListBucket
Resource: '*'

# GITHUB WebHook
GhWebHook:
Type: AWS::CodePipeline::Webhook
Properties:
Authentication: GITHUB_HMAC
AuthenticationConfiguration:
SecretToken: !Ref GHToken
Filters:
- JsonPath: '$.ref'
MatchEquals: refs/heads/{Branch}
Name: String
RegisterWithThirdParty: true
TargetAction: GetSource
TargetPipeline: !Ref MyCodePipeline
TargetPipelineVersion: !GetAtt MyCodePipeline.Version
49 changes: 49 additions & 0 deletions 12-codepipeline/12.2/appstack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
AWSTemplateFormatVersion: '2010-09-09'
Description: App stack for module 12.2

Parameters:
PartsTableName:
Type: String
Default: AllenF-Module122-BikeParts

Resources:
BikePartsDDBTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: !Ref PartsTableName
AttributeDefinitions:
- AttributeName: ID3
AttributeType: S
KeySchema:
- AttributeName: ID3
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5

DdbTableRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- dynamodb.amazonaws.com
Action:
- sts:AssumeRole
ManagedPolicyArns:
- arn:aws:iam::aws:policy/AmazonDynamoDBReadOnlyAccess

Outputs:
PartsTableName:
Value: !Ref BikePartsDDBTable
Export:
Name: AllenF122PartsTableName

PartsTableArn:
Value: !GetAtt BikePartsDDBTable.Arn
Export:
Name: AllenF122PartsTableArn
Loading