Skip to content
This repository has been archived by the owner on Jun 29, 2022. It is now read-only.

Commit

Permalink
fix boolean params in aws:branch choices (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
udondan authored Apr 3, 2021
1 parent b770f61 commit 4de42d4
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 10 deletions.
47 changes: 38 additions & 9 deletions lambda/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ interface DocumentEvent extends LambdaEvent {
default?: any;
};
};
mainSteps?: [
{
name: string;
action: string;
inputs: {
[key: string]: any;
};
}
];
};
};
}
Expand Down Expand Up @@ -291,16 +300,36 @@ function missingTags(newTags: AWS.SSM.TagList) {
* @returns DocumentEvent
*/
function fixBooleanParameters(event: DocumentEvent) {
if (typeof event.ResourceProperties.Content.parameters !== 'object') {
return event;
}
for (let [key, param] of Object.entries(
event.ResourceProperties.Content.parameters
)) {
if (param.type == 'Boolean' && 'default' in param) {
event.ResourceProperties.Content.parameters[key].default =
param.default == 'true';
// fixing Boolean input parameters
if (typeof event.ResourceProperties.Content.parameters == 'object') {
for (let [key, param] of Object.entries(
event.ResourceProperties.Content.parameters
)) {
if (param.type == 'Boolean' && 'default' in param) {
event.ResourceProperties.Content.parameters[key].default =
param.default == 'true';
}
}
}

// fixing BooleanEquals in aws:branch https://docs.aws.amazon.com/systems-manager/latest/userguide/automation-action-branch.html
if (Array.isArray(event.ResourceProperties.Content.mainSteps)) {
event.ResourceProperties.Content.mainSteps.forEach((step, i) => {
if (
step.action == 'aws:branch' &&
'Choices' in step.inputs &&
Array.isArray(step.inputs.Choices)
) {
step.inputs.Choices.forEach((choice, j) => {
if ('BooleanEquals' in choice) {
event.ResourceProperties.Content.mainSteps[i].inputs.Choices[
j
].BooleanEquals = choice.BooleanEquals == 'true';
}
});
}
});
}

return event;
}
33 changes: 32 additions & 1 deletion test/documents/automation/automation-document.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
---
description: Custom Automation Backup and Recovery Sample
schemaVersion: "0.3"
parameters:
doSomething:
type: Boolean
description: Do something
default: true
mainSteps:
- name: createImage
- name: DoSomethingCheck
action: aws:branch
inputs:
Choices:
- NextStep: createImage1
Variable: "{{ doSomething }}"
BooleanEquals: true

- NextStep: createImage2
Variable: "{{ doSomething }}"
BooleanEquals: false

- name: createImage1
action: aws:executeAwsApi
onFailure: Abort
inputs:
Expand All @@ -15,3 +32,17 @@ mainSteps:
- Name: newImageId
Selector: "$.ImageId"
Type: String

- name: createImage2
action: aws:executeAwsApi
onFailure: Abort
inputs:
Service: ec2
Api: CreateImage
InstanceId: i-0987654321
Name: Image
NoReboot: false
outputs:
- Name: newImageId
Selector: "$.ImageId"
Type: String

0 comments on commit 4de42d4

Please sign in to comment.