-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ContinuousDeployment construct
BREAKING CHANGE: the imports are new at @bifravst/ci
- Loading branch information
1 parent
edb72da
commit 24d19d6
Showing
3 changed files
with
52 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Duration, aws_iam as IAM, Stack } from 'aws-cdk-lib' | ||
import { Construct } from 'constructs' | ||
|
||
export class ContinuousDeployment extends Construct { | ||
public readonly role: IAM.IRole | ||
constructor( | ||
parent: Construct, | ||
{ | ||
repository: { owner, repo }, | ||
gitHubOICDProviderArn, | ||
}: { | ||
repository: { | ||
owner: string | ||
repo: string | ||
} | ||
gitHubOICDProviderArn: string | ||
}, | ||
) { | ||
super(parent, 'cd') | ||
|
||
const gitHubOIDC = IAM.OpenIdConnectProvider.fromOpenIdConnectProviderArn( | ||
this, | ||
'gitHubOICDProvider', | ||
gitHubOICDProviderArn, | ||
) | ||
|
||
this.role = new IAM.Role(this, 'ghRole', { | ||
roleName: `${Stack.of(this).stackName}-cd`, | ||
assumedBy: new IAM.WebIdentityPrincipal( | ||
gitHubOIDC.openIdConnectProviderArn, | ||
{ | ||
StringEquals: { | ||
[`token.actions.githubusercontent.com:sub`]: `repo:${owner}/${repo}:environment:production`, | ||
[`token.actions.githubusercontent.com:aud`]: 'sts.amazonaws.com', | ||
}, | ||
}, | ||
), | ||
description: `This role is used by GitHub Actions to deploy ${ | ||
Stack.of(this).stackName | ||
}`, | ||
maxSessionDuration: Duration.hours(1), | ||
managedPolicies: [ | ||
IAM.ManagedPolicy.fromAwsManagedPolicyName('AdministratorAccess'), | ||
], | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './ContinuousDeployment.js' | ||
export * from './RepoPermission.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters