Skip to content

Commit 3c8d838

Browse files
committed
add stackset for service catalog products and a resource server product
1 parent 77e1060 commit 3c8d838

File tree

7 files changed

+177
-2
lines changed

7 files changed

+177
-2
lines changed

.github/workflows/main.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,15 @@ jobs:
2929
- name: Validate template
3030
run: sam validate --lint
3131

32-
- name: Validate template
32+
- name: Validate template (userpool stackset)
3333
run: sam validate --lint --template ./stacksets/userpool/stackset.yaml
3434

35+
- name: Validate template (products stackset)
36+
run: sam validate --lint --template ./products/stackset.yaml
37+
38+
- name: Validate template (server product)
39+
run: sam validate --lint --template ./products/server/product.yaml
40+
3541
- name: Synethsize StackSet templates
3642
run: |
3743
for _f in $(find . -type f -name 'template.yaml'); do
@@ -68,6 +74,13 @@ jobs:
6874
build_aws_account_id: ${{ secrets.AWS_CICD_ACCOUNT_ID }}
6975
deploy_aws_account_id: ${{ secrets.AWS_MANAGEMENT_ACCOUNT_ID }}
7076

77+
- name: Sync product templates to S3
78+
id: sync-templates
79+
shell: bash
80+
env:
81+
AWS_ACCOUNT_ID: ${{ secrets.AWS_MANAGEMENT_ACCOUNT_ID }}
82+
run: aws s3 sync products/ s3://aws-service-catalog-templates-${AWS_ACCOUNT_ID}-${AWS_REGION}/serverlessops-api-authnz/${GITHUB_SHA}/
83+
7184
- name: Deploy via AWS SAM
7285
uses: ServerlessOpsIO/gha-deploy-aws-sam@v1
7386
with:

cfn-parameters.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@
99
"TargetOuIds": $secrets.DEPLOYMENT_TARGET_OU,
1010
"TargetRegions": "us-east-1",
1111
"TargetAccountIds": $secrets.DEPLOYMENT_TARGET_ACCOUNT_ID,
12+
"GitHubSha": $env.GITHUB_SHA,
13+
"CfnTemplateBucket": $secrets.CFN_TEMPLATE_BUCKET
1214
}

products/server/product.yaml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
AWSTemplateFormatVersion: '2010-09-09'
2+
Description: Create a Cognito Resource Server
3+
4+
Parameters:
5+
CognitoUserPoolId:
6+
Type: AWS::SSM::Parameter::Value<String>
7+
Description: The ID of the user pool to which the resource server belongs
8+
Default: /org/authnz/UserPoolId
9+
ApplicationName:
10+
Type: String
11+
Description: The name of the application
12+
ApplicationUrl:
13+
Type: String
14+
Description: The URL of the application
15+
ScopeName:
16+
Type: String
17+
Description: The name of the scope
18+
ReadActionAvailable:
19+
Type: String
20+
Description: Whether the read scope is available
21+
Default: 'true'
22+
WriteActionAvailable:
23+
Type: String
24+
Description: Whether the write scope is available
25+
Default: 'true'
26+
ListActionAvailable:
27+
Type: String
28+
Description: Whether the list scope is available
29+
Default: 'true'
30+
AdminActionAvailable:
31+
Type: String
32+
Description: Whether the admin scope is available
33+
Default: 'false'
34+
35+
Conditions:
36+
HasReadAction: !Equals [!Ref ReadActionAvailable, 'true']
37+
HasWriteAction: !Equals [!Ref WriteActionAvailable, 'true']
38+
HasListAction: !Equals [!Ref ListActionAvailable, 'true']
39+
HasAdminAction: !Equals [!Ref AdminActionAvailable, 'true']
40+
41+
Resources:
42+
CognitoResourceServer:
43+
Type: AWS::Cognito::UserPoolResourceServer
44+
Properties:
45+
Name: !Ref ApplicationName
46+
Identifier: !Ref ApplicationUrl
47+
UserPoolId: !Ref CognitoUserPoolId
48+
Scopes:
49+
- Fn::If:
50+
- HasReadAction
51+
- ScopeName: !Sub '${ScopeName}.read'
52+
ScopeDescription: Read access
53+
- Ref: AWS::NoValue
54+
- Fn::If:
55+
- HasWriteAction
56+
- ScopeName: !Sub '${ScopeName}.write'
57+
ScopeDescription: Write access
58+
- Ref: AWS::NoValue
59+
- Fn::If:
60+
- HasListAction
61+
- ScopeName: !Sub '${ScopeName}.list'
62+
ScopeDescription: List access
63+
- Ref: AWS::NoValue
64+
- Fn::If:
65+
- HasAdminAction
66+
- ScopeName: !Sub '${ScopeName}.admin'
67+
ScopeDescription: Admin access
68+
- Ref: AWS::NoValue

products/stackset.yaml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
AWSTemplateFormatVersion: '2010-09-09'
2+
Description: Create a Cognito Resource Server
3+
4+
Parameters:
5+
GitHubSha:
6+
Type: String
7+
Description: GitHub SHA
8+
CfnTemplateBucket:
9+
Type: String
10+
Description: The S3 bucket CloudFormation templates are stored
11+
12+
Resources:
13+
# Portfolio
14+
ApiAuthnzPortfolio:
15+
Type: AWS::ServiceCatalog::Portfolio
16+
Properties:
17+
DisplayName: ServerlessOpsAuthnz
18+
Description: "API Authentication & Authorization services"
19+
ProviderName: ServerlessOps
20+
21+
ApiAuthnzPortfolioPrincipalAdmin:
22+
Type: AWS::ServiceCatalog::PortfolioPrincipalAssociation
23+
Properties:
24+
PortfolioId: !Ref ApiAuthnzPortfolio
25+
PrincipalARN: !Sub 'arn:${AWS::Partition}:iam:::role/aws-reserved/sso.amazonaws.com/AWSReservedSSO_AWSAdministratorAccess_*'
26+
PrincipalType: IAM_PATTERN
27+
28+
ApiAuthnzPortfolioPrincipalPowerUser:
29+
Type: AWS::ServiceCatalog::PortfolioPrincipalAssociation
30+
Properties:
31+
PortfolioId: !Ref ApiAuthnzPortfolio
32+
PrincipalARN: !Sub 'arn:${AWS::Partition}:iam:::role/aws-reserved/sso.amazonaws.com/AWSReservedSSO_AWSPowerUserAccess_*'
33+
PrincipalType: IAM_PATTERN
34+
35+
36+
# Products
37+
CognitoResourceServerProduct:
38+
Type: AWS::ServiceCatalog::CloudFormationProduct
39+
Properties:
40+
Name: Cognito Resource Server
41+
Description: Create a Cognito Resource Server
42+
Owner: ServerlessOps
43+
ProvisioningArtifactParameters:
44+
- Name: latest
45+
Description: latest release
46+
Info:
47+
LoadTemplateFromURL: !Sub 'https://${CfnTemplateBucket}.s3.amazonaws.com/serverlessops-api-authnz/${GitHubSha}/server/product.yaml'
48+
49+
CognitoResourceServerProductAssociation:
50+
Type: AWS::ServiceCatalog::PortfolioProductAssociation
51+
Properties:
52+
PortfolioId: !Ref ApiAuthnzPortfolio
53+
ProductId: !Ref CognitoResourceServerProduct

stacksets/server/stackset.yaml

Whitespace-only changes.

template.yaml

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Metadata:
22
UserPool:
33
localTemplateFile: &user_pool_template_body ./stacksets/userpool/stackset.yaml
4+
Products:
5+
localTemplateFile: &products_template_body ./products/stackset.yaml
46

57
AWSTemplateFormatVersion: '2010-09-09'
68
Description: ServerlessOps API Authnz Service
@@ -24,6 +26,12 @@ Parameters:
2426
ParentDnsZoneId:
2527
Type: String
2628
Description: "Route53 Hosted Zone ID of parent zone"
29+
GitHubSha:
30+
Type: String
31+
Description: GitHub SHA
32+
CfnTemplateBucket:
33+
Type: String
34+
Description: The S3 bucket CloudFormation templates are stored
2735

2836
Resources:
2937
UserPoolStackSet:
@@ -57,4 +65,35 @@ Resources:
5765
Capabilities:
5866
- CAPABILITY_NAMED_IAM
5967
- CAPABILITY_AUTO_EXPAND
60-
TemplateBody: *user_pool_template_body
68+
TemplateBody: *user_pool_template_body
69+
70+
ProductsStackSet:
71+
Type: AWS::CloudFormation::StackSet
72+
Properties:
73+
StackSetName: ServerlessOpsAuthnzProducts
74+
Description: ServerlessOps Authnz Service Catalog Products
75+
Parameters:
76+
- ParameterKey: GitHubSha
77+
ParameterValue: !Ref GitHubSha
78+
- ParameterKey: CfnTemplateBucket
79+
ParameterValue: !Ref CfnTemplateBucket
80+
StackInstancesGroup:
81+
- DeploymentTargets:
82+
AccountFilterType: INTERSECTION
83+
OrganizationalUnitIds: !Ref TargetOuIds
84+
Accounts: !Ref TargetAccountIds
85+
Regions: !Ref TargetRegions
86+
AutoDeployment:
87+
Enabled: true
88+
RetainStacksOnAccountRemoval: false
89+
ManagedExecution:
90+
Active: true
91+
OperationPreferences:
92+
RegionConcurrencyType: PARALLEL
93+
FailureToleranceCount: 1
94+
MaxConcurrentCount: 5
95+
PermissionModel: SERVICE_MANAGED
96+
Capabilities:
97+
- CAPABILITY_NAMED_IAM
98+
- CAPABILITY_AUTO_EXPAND
99+
TemplateBody: *products_template_body

0 commit comments

Comments
 (0)