Skip to content

Commit fd65280

Browse files
authored
Merge pull request #86 from badsyntax/feature/custom-capabilities
Add custom capabilities
2 parents 66ea158 + 1c3a2f0 commit fd65280

File tree

11 files changed

+48
-43
lines changed

11 files changed

+48
-43
lines changed

.github/release-drafter.yml

Lines changed: 0 additions & 4 deletions
This file was deleted.

.github/workflows/release-drafter.yml

Lines changed: 0 additions & 19 deletions
This file was deleted.

.github/workflows/test-build-deploy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ jobs:
6666
apply-change-set: ${{ github.event_name != 'repository_dispatch' }}
6767
aws-region: 'us-east-1'
6868
parameters: 'S3BucketName=badsyntax-github-action-example-aws-cloudformation-us-east-1&S3AllowedOrigins=https://richardwillis.info'
69+
capabilities: 'CAPABILITY_NAMED_IAM, CAPABILITY_IAM'
6970

7071
- uses: badsyntax/[email protected]
7172
name: Comment on Pull Request

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ This Action is actively maintained and includes additional features.
1616
- Apply or Preview ChangeSet with Pull Request comments
1717
- Log intervals to show constant feedback
1818
- CloudFormation outputs set as Action Outputs (which can be used in subsequent steps)
19+
- Template validation
1920

2021
## Getting Started
2122

@@ -72,13 +73,14 @@ jobs:
7273
7374
## Action Inputs
7475
75-
| key | description | example |
76-
| ----------------------- | --------------------------------------------------------------------------------------------------- | ----------------------------------------------- |
77-
| `stack-name` | The name of the Cloudformation stack to be created | `example-com-static-cloudformation-stack` |
78-
| `template` | The relative path to the CloudFormation stack template | `./cloudformation/s3bucket_with_cloudfront.yml` |
79-
| `aws-region` | The AWS region in which to create the stack | `us-east-1` |
80-
| `parameters` (optional) | The parameters to override in the stack inputs, in query string format. Whitespace will be stripped | `Param1=foo&Param2=http://example.com` |
81-
| `apply-change-set` | Whether to apply the ChangeSet, or provide a summary of the ChangeSet | `true` |
76+
| key | description | example |
77+
| ------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------- |
78+
| `stack-name` | The name of the Cloudformation stack to be created | `example-com-static-cloudformation-stack` |
79+
| `template` | The relative path to the CloudFormation stack template | `./cloudformation/s3bucket_with_cloudfront.yml` |
80+
| `aws-region` | The AWS region in which to create the stack | `us-east-1` |
81+
| `parameters` (optional) | The parameters to override in the stack inputs, in query string format. Whitespace will be stripped | `Param1=foo&Param2=http://example.com` |
82+
| `apply-change-set` | Whether to apply the ChangeSet, or provide a summary of the ChangeSet | `true` |
83+
| `capabilities` (optional) | A comma-delimited list of stack template [capabilities](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-cloudformation/interfaces/createchangesetcommandinput.html#capabilities) to acknowledge. Defaults to `CAPABILITY_IAM` | `CAPABILITY_IAM` |
8284

8385
## Action Outputs
8486

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ inputs:
2020
apply-change-set:
2121
required: false
2222
description: 'Whether to show the ChangeSet as a Pull Request comment'
23+
capabilities:
24+
description: "A comma-delimited list of stack template capabilities to acknowledge. Defaults to 'CAPABILITY_IAM'"
25+
required: false
26+
default: 'CAPABILITY_IAM'
2327
outputs:
2428
outputs:
2529
description: 'JSON string array of CloudFormation outputs'

dist/index.js

Lines changed: 12 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

run.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
#!/usr/bin/env bash
22

3-
INPUT_STACKNAME="badsyntax-github-action-example-aws-cloudformation" \
3+
env 'INPUT_STACK-NAME=badsyntax-github-action-example-aws-cloudformation' \
44
INPUT_TEMPLATE="./cloudformation/s3bucket-example.yml" \
55
INPUT_PREVIEW="false" \
6-
INPUT_AWSREGION="us-east-1" \
6+
env 'INPUT_AWS-REGION=us-east-1' \
77
INPUT_PARAMETERS="S3BucketName=badsyntax-github-action-example-aws-cloudformation-us-east-12&S3AllowedOrigins=https://richardwillis.info" \
8-
INPUT_APPLYCHANGESET="false" \
8+
env 'INPUT_APPLY-CHANGE-SET=false' \
9+
INPUT_CAPABILITIES="false" \
910
GITHUB_EVENT_NAME="pull_request" \
1011
GITHUB_ACTION="synchronize" \
1112
GITHUB_REPOSITORY="badsyntax/github-action-aws-cloudformation" \

src/cloudformation.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { debug, info, notice, warning } from '@actions/core';
1+
import { debug, error, info, notice, warning } from '@actions/core';
22
import {
33
Parameter,
44
CloudFormationClient,
@@ -195,7 +195,8 @@ async function createChangeSet(
195195
cfStackName: string,
196196
changeSetType: ChangeSetType,
197197
cfTemplateBody: string,
198-
parameters: Parameter[]
198+
parameters: Parameter[],
199+
capabilities: string
199200
) {
200201
return client.send(
201202
new CreateChangeSetCommand({
@@ -204,7 +205,9 @@ async function createChangeSet(
204205
ChangeSetName: `test-changeset-${Date.now()}`,
205206
ChangeSetType: changeSetType,
206207
Parameters: parameters,
207-
Capabilities: [Capability.CAPABILITY_IAM],
208+
Capabilities: capabilities
209+
.split(',')
210+
.map((capability) => capability.trim()),
208211
})
209212
);
210213
}
@@ -346,10 +349,12 @@ export async function updateCloudFormationStack(
346349
client: CloudFormationClient,
347350
cfStackName: string,
348351
applyChangeSet: boolean,
352+
capabilities: string,
349353
cfTemplateBody: string,
350354
cfParameters: Parameter[]
351355
): Promise<UpdateCloudFormationStackResponse> {
352356
await validateTemplate(client, cfTemplateBody);
357+
353358
const changeSetType = await getChangeSetType(
354359
client,
355360
cfStackName,
@@ -361,7 +366,8 @@ export async function updateCloudFormationStack(
361366
cfStackName,
362367
changeSetType,
363368
cfTemplateBody,
364-
cfParameters
369+
cfParameters,
370+
capabilities
365371
);
366372

367373
const changes = await getChanges(client, cfStackName, changeSet);

src/inputs.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ export function getInputs() {
2121
trimWhitespace: true,
2222
});
2323

24+
const capabilities = getInput('capabilities', {
25+
required: false,
26+
trimWhitespace: true,
27+
});
28+
2429
const applyChangeSet =
2530
getInput('apply-change-set', {
2631
required: true,
@@ -33,5 +38,6 @@ export function getInputs() {
3338
template,
3439
applyChangeSet,
3540
parameters,
41+
capabilities,
3642
};
3743
}

src/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export async function run(): Promise<void> {
4141
cloudFormationClient,
4242
inputs.stackName,
4343
inputs.applyChangeSet,
44+
inputs.capabilities,
4445
cfTemplateBody,
4546
cfParameters
4647
);

0 commit comments

Comments
 (0)