Skip to content

Instantly share code, notes, and snippets.

@bboure
Created December 26, 2021 10:26
Show Gist options
  • Save bboure/a35fd060b367bd832f5294c37db95dc9 to your computer and use it in GitHub Desktop.
Save bboure/a35fd060b367bd832f5294c37db95dc9 to your computer and use it in GitHub Desktop.
Create AWS OIDC identity provider and IAM role for Github Actions
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