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

Commit

Permalink
Fn::GetAtt working with arbitrary attributes on CustomResources (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
akdor1154 authored and martysweet committed Nov 18, 2017
1 parent 2b66f7b commit ea61f5f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
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 @@ -880,11 +880,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

0 comments on commit ea61f5f

Please sign in to comment.