Created
December 26, 2021 10:26
-
-
Save bboure/a35fd060b367bd832f5294c37db95dc9 to your computer and use it in GitHub Desktop.
Create AWS OIDC identity provider and IAM role for Github Actions
This file contains hidden or 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
Parameters: | |
GitHubOrg: | |
Type: String | |
RepositoryName: | |
Type: String | |
OIDCProviderArn: | |
Description: Arn for the GitHub OIDC Provider. | |
Default: "" | |
Type: String | |
Conditions: | |
CreateOIDCProvider: !Equals | |
- !Ref OIDCProviderArn | |
- "" | |
Resources: | |
Role: | |
Type: AWS::IAM::Role | |
Properties: | |
AssumeRolePolicyDocument: | |
Statement: | |
- Effect: Allow | |
Action: sts:AssumeRoleWithWebIdentity | |
Principal: | |
Federated: !If | |
- CreateOIDCProvider | |
- !Ref GithubOidc | |
- !Ref OIDCProviderArn | |
Condition: | |
StringLike: | |
token.actions.githubusercontent.com:sub: !Sub repo:${GitHubOrg}/${RepositoryName}:* | |
GithubOidc: | |
Type: AWS::IAM::OIDCProvider | |
Condition: CreateOIDCProvider | |
Properties: | |
Url: https://token.actions.githubusercontent.com | |
ClientIdList: | |
- sts.amazonaws.com | |
ThumbprintList: | |
- a031c46782e6e6c662c2c87c76da9aa62ccabd8e | |
Outputs: | |
Role: | |
Value: !GetAtt Role.Arn |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment