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

allow GetAtt to work on with arbitrary attributes on CustomResources #80

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/test/validatorTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,16 @@ describe('validator', () => {

});

describe('Fn::GetAtt', () => {
it('Fn::GetAtt for an arbitrary attribute on a custom resource should return a mock result', () => {
const input = 'testData/valid/yaml/valid_getatt_custom_resource.yaml';
let result = validator.validateFile(input);
expect(result).to.have.property('templateValid', true);
expect(validator.fnGetAtt('Custom', 'SomeAttribute')).to.equal('mockAttr_Custom_SomeAttribute');
expect(validator.fnGetAtt('Custom2', 'SomeAttribute')).to.equal('mockAttr_Custom2_SomeAttribute');
})
})

describe('conditions', () => {

it('1 invalid if condition arguments should return an object with validTemplate = false, 1 crit errors', () => {
Expand Down
11 changes: 7 additions & 4 deletions src/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -865,11 +865,14 @@ function fnJoin(join: any, parts: any){
return parts.join(join);
}

function fnGetAtt(reference: string, attribute: string){
export function fnGetAtt(reference: string, attribute: string){
if(workingInput['Resources'].hasOwnProperty(reference)){
if(workingInput['Resources'][reference]['Attributes'].hasOwnProperty(attribute)){
return workingInput['Resources'][reference]['Attributes'][attribute];
}
const resource = workingInput['Resources'][reference];
if (resource['Attributes'].hasOwnProperty(attribute)){
return resource['Attributes'][attribute];
} else if (resource['Type'].indexOf('Custom::') === 0 || resource['Type'] === 'AWS::CloudFormation::CustomResource') {
return `mockAttr_${reference}_${attribute}`;
}
}
// Return null if not found
return null;
Expand Down
20 changes: 20 additions & 0 deletions testData/valid/yaml/valid_getatt_custom_resource.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Resources:
Custom:
Type: Custom::Dooby
Properties:
ServiceToken: arn:aws:blahblahblah

Custom2:
Type: AWS::CloudFormation::CustomResource
Properties:
ServiceToken: arn:aws:blahblahblah

Bucket:
Type: AWS::S3::Bucket
Properties:
Tags:
- Key: key1
Value: !GetAtt Custom.SomeAttribute
- Key: key2
Value: !GetAtt Custom2.SomeAttribute