Skip to content

Commit

Permalink
Fix (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
abiydv authored Feb 5, 2019
1 parent d60fa74 commit 7d3971a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 33 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# AWS Cross Account Codepipeline
[![CodeFactor](https://www.codefactor.io/repository/github/abiydv/aws-cf-codepipeline/badge)](https://www.codefactor.io/repository/github/abiydv/aws-cf-codepipeline)

![cli](https://github.com/abiydv/ref-docs/blob/master/images/logos/aws-cli_small.png)
![cf](https://github.com/abiydv/ref-docs/blob/master/images/logos/aws-cf_small.png)
![github](https://github.com/abiydv/ref-docs/blob/master/images/logos/github_small.png)
Expand Down
18 changes: 9 additions & 9 deletions codepipeline-base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Parameters:
Project:
Type: String
Default: "PROJECT" # Replace with your custom project name

PullAccounts:
Type: CommaDelimitedList
Default: "arn:aws:iam::DEV_ACCOUNT_ID:root,arn:aws:iam::QA_ACCOUNT_ID:root, arn:aws:iam::PROD_ACCOUNT_ID:root"
Default: "arn:aws:iam::DEV_ACCOUNT_ID:root,arn:aws:iam::QA_ACCOUNT_ID:root, arn:aws:iam::PROD_ACCOUNT_ID:root"
# Enter the account ids where the ECS clusters will be.

KMSAdmin:
Expand Down Expand Up @@ -87,7 +87,7 @@ Resources:
- s3:Put*
- s3:ListBucket
Effect: Allow
Resource:
Resource:
- !Join ["",["arn:aws:s3:::",!Ref 'ArtifactBucket',"/*"]]
- !Join ["",["arn:aws:s3:::",!Ref 'ArtifactBucket']]
Principal:
Expand Down Expand Up @@ -116,15 +116,15 @@ Resources:
Repository:
Type: AWS::ECR::Repository
DeletionPolicy: Retain
Properties:
Properties:
RepositoryName: !Join [ "-", [ "ecr", !Ref Project, "repository" ]]
RepositoryPolicyText:
RepositoryPolicyText:
Version: 2012-10-17
Statement:
-
Sid: AllowAll
Effect: Allow
Principal:
Principal:
AWS:
- !Sub "arn:aws:iam::${AWS::AccountId}:root"
Action:
Expand All @@ -145,19 +145,19 @@ Resources:
Outputs:
ArtifactBucketArn:
Value: !GetAtt ArtifactBucket.Arn
Export:
Export:
Name: !Join [ ":", [ !Ref "AWS::StackName", ArtifactBucketArn ]]

ArtifactBucket:
Value: !Ref ArtifactBucket
Export:
Export:
Name: !Join [ ":", [ !Ref "AWS::StackName", ArtifactBucket ]]

RepositoryArn:
Value: !GetAtt Repository.Arn
Export:
Name: !Join [ ":", [ !Ref "AWS::StackName", RepositoryArn ]]

Repository:
Value: !Ref Repository
Export:
Expand Down
48 changes: 24 additions & 24 deletions codepipeline-stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ Parameters:
Type: String
NoEcho: true
Default: "GITHUBTOKEN" # Replace with your github oauth token

GitHubUser:
Type: String
Default: "GITHUBUSER" # Replace with your github username

BaseStackName:
Type: String
Default: "codepipeline-base-stack"
Expand All @@ -35,7 +35,7 @@ Parameters:
Type: String
Default: "APPROVE@EXAMPLE.COM" # Replace with an email where approval notifications will be sent

Mappings:
Mappings:
Account:
tools:
id: "112233445566" # Replace with your aws tools account id
Expand Down Expand Up @@ -77,14 +77,14 @@ Resources:
- kms:GenerateDataKey*
- kms:DescribeKey
- sns:Publish*
- Resource:
- Resource:
!Join [ '', [ "Fn::ImportValue" : { "Fn::Sub": '${BaseStackName}:ArtifactBucketArn' }, '/*' ]]
Effect: Allow
Action:
- s3:GetObject
- s3:PutObject
- s3:GetObjectVersion
- Resource:
- Resource:
Fn::ImportValue: !Sub "${BaseStackName}:RepositoryArn"
Effect: Allow
Action:
Expand Down Expand Up @@ -160,7 +160,7 @@ Resources:
- TAG="$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | head -c 10)"
- IMAGE_URI="${REPOSITORY_URI}:${TAG}"
build:
commands:
commands:
- docker build --tag "$IMAGE_URI" .
- docker run -d -p 80:80 "$IMAGE_URI"
- sleep 40
Expand Down Expand Up @@ -194,10 +194,10 @@ Resources:
RoleArn: !GetAtt CodePipelineServiceRole.Arn
ArtifactStore:
Type: S3
Location:
Location:
Fn::ImportValue: !Sub "${BaseStackName}:ArtifactBucket"
EncryptionKey:
Id:
Id:
Fn::ImportValue: !Sub "${BaseStackName}:KMSKey"
Type: KMS
Stages:
Expand Down Expand Up @@ -256,10 +256,10 @@ Resources:
Owner: AWS
Version: 1
Provider: Manual
Configuration:
Configuration:
NotificationArn: !Ref SNSApproveTopic
CustomData: "Approve Deployment to QA"
RunOrder: 1
RunOrder: 1
- Name: QADeploy
Actions:
- Name: QADeploy
Expand All @@ -284,10 +284,10 @@ Resources:
Owner: AWS
Version: 1
Provider: Manual
Configuration:
Configuration:
NotificationArn: !Ref SNSApproveTopic
CustomData: "Approve Deployment to Prod"
RunOrder: 1
RunOrder: 1
- Name: ProdDeploy
Actions:
- Name: ProdDeploy
Expand All @@ -307,20 +307,20 @@ Resources:

SNSNotifyTopic:
Type: AWS::SNS::Topic
Properties:
Properties:
DisplayName: "AWS-Tools"
Subscription:
-
-
Endpoint: !Ref Email
Protocol: email
Protocol: email
TopicName: !Sub sns-${Project}-notify

SNSNotifyTopicPolicy:
Type: AWS::SNS::TopicPolicy
Properties:
Topics:
- !Ref SNSNotifyTopic
PolicyDocument:
PolicyDocument:
Version: 2012-10-17
Statement:
- Resource: !Ref SNSNotifyTopic
Expand All @@ -339,20 +339,20 @@ Resources:

SNSApproveTopic:
Type: AWS::SNS::Topic
Properties:
Properties:
DisplayName: "AWS-Tools"
Subscription:
-
-
Endpoint: !Ref ApproverEmail
Protocol: email
Protocol: email
TopicName: !Sub sns-${Project}-approve

SNSApproveTopicPolicy:
Type: AWS::SNS::TopicPolicy
Properties:
Topics:
- !Ref SNSApproveTopic
PolicyDocument:
PolicyDocument:
Version: 2012-10-17
Statement:
- Resource: !Ref SNSApproveTopic
Expand All @@ -371,7 +371,7 @@ Resources:

PipelineEvent:
Type: AWS::Events::Rule
Properties:
Properties:
Description: "Notify on codepipeline STATE change"
Name: !Sub "cwe-${Project}-codepipeline-event-rule"
EventPattern:
Expand All @@ -382,7 +382,7 @@ Resources:
detail:
pipeline: [ !Ref Pipeline ]

State: ENABLED
State: ENABLED
Targets:
- Arn: !Ref SNSNotifyTopic
Id: eventTarget
Expand All @@ -396,7 +396,7 @@ Resources:

BuildEvent:
Type: AWS::Events::Rule
Properties:
Properties:
Description: "Notify on codepipeline STATE change"
Name: !Sub "cwe-${Project}-codebuild-event-rule"
EventPattern:
Expand All @@ -407,7 +407,7 @@ Resources:
detail:
project-name: [ !Ref CodeBuildProject ]

State: ENABLED
State: ENABLED
Targets:
- Arn: !Ref SNSNotifyTopic
Id: eventTarget
Expand Down

0 comments on commit 7d3971a

Please sign in to comment.