|
2 | 2 | * CloudFormation Intrinsic Functions Helpers |
3 | 3 | */ |
4 | 4 |
|
5 | | -export const Fn = { |
6 | | - /** |
7 | | - * Ref - Returns the value of the specified parameter or resource |
8 | | - */ |
9 | | - Ref: (logicalName: string): { Ref: string } => ({ Ref: logicalName }), |
| 5 | +export interface IntrinsicFunctions { |
| 6 | + Ref: (logicalName: string) => { Ref: string } |
| 7 | + GetAtt: (logicalName: string, attributeName: string) => { 'Fn::GetAtt': [string, string] } |
| 8 | + Sub: (template: string, variables?: Record<string, any>) => { 'Fn::Sub': string | [string, Record<string, any>] } |
| 9 | + Join: (delimiter: string, values: any[]) => { 'Fn::Join': [string, any[]] } |
| 10 | + Select: (index: number | string, list: any[]) => { 'Fn::Select': [number | string, any[]] } |
| 11 | + Split: (delimiter: string, source: string) => { 'Fn::Split': [string, string] } |
| 12 | + GetAZs: (region?: string) => { 'Fn::GetAZs': string } |
| 13 | + ImportValue: (name: string) => { 'Fn::ImportValue': string } |
| 14 | + If: (condition: string, trueValue: any, falseValue: any) => { 'Fn::If': [string, any, any] } |
| 15 | + Equals: (value1: any, value2: any) => { 'Fn::Equals': [any, any] } |
| 16 | + And: (...conditions: any[]) => { 'Fn::And': any[] } |
| 17 | + Or: (...conditions: any[]) => { 'Fn::Or': any[] } |
| 18 | + Not: (condition: any) => { 'Fn::Not': [any] } |
| 19 | + Base64: (input: string) => { 'Fn::Base64': string } |
| 20 | +} |
10 | 21 |
|
11 | | - /** |
12 | | - * GetAtt - Returns the value of an attribute from a resource |
13 | | - */ |
14 | | - GetAtt: (logicalName: string, attributeName: string): { 'Fn::GetAtt': [string, string] } => ({ |
| 22 | +export const Fn: IntrinsicFunctions = { |
| 23 | + Ref: (logicalName: string) => ({ Ref: logicalName }), |
| 24 | + GetAtt: (logicalName: string, attributeName: string) => ({ |
15 | 25 | 'Fn::GetAtt': [logicalName, attributeName] as [string, string], |
16 | 26 | }), |
17 | | - |
18 | | - /** |
19 | | - * Sub - Substitutes variables in an input string with values |
20 | | - */ |
21 | | - Sub: (template: string, variables?: Record<string, any>): { 'Fn::Sub': string | [string, Record<string, any>] } => { |
| 27 | + Sub: (template: string, variables?: Record<string, any>) => { |
22 | 28 | if (variables) { |
23 | 29 | return { 'Fn::Sub': [template, variables] as [string, Record<string, any>] } |
24 | 30 | } |
25 | 31 | return { 'Fn::Sub': template } |
26 | 32 | }, |
27 | | - |
28 | | - /** |
29 | | - * Join - Appends a set of values into a single value, separated by delimiter |
30 | | - */ |
31 | | - Join: (delimiter: string, values: any[]): { 'Fn::Join': [string, any[]] } => ({ |
| 33 | + Join: (delimiter: string, values: any[]) => ({ |
32 | 34 | 'Fn::Join': [delimiter, values] as [string, any[]], |
33 | 35 | }), |
34 | | - |
35 | | - /** |
36 | | - * Select - Returns a single object from a list of objects by index |
37 | | - */ |
38 | | - Select: (index: number | string, list: any[]): { 'Fn::Select': [number | string, any[]] } => ({ |
| 36 | + Select: (index: number | string, list: any[]) => ({ |
39 | 37 | 'Fn::Select': [index, list] as [number | string, any[]], |
40 | 38 | }), |
41 | | - |
42 | | - /** |
43 | | - * Split - Splits a string into a list of string values |
44 | | - */ |
45 | | - Split: (delimiter: string, source: string): { 'Fn::Split': [string, string] } => ({ |
| 39 | + Split: (delimiter: string, source: string) => ({ |
46 | 40 | 'Fn::Split': [delimiter, source] as [string, string], |
47 | 41 | }), |
48 | | - |
49 | | - /** |
50 | | - * GetAZs - Returns an array of Availability Zones for a region |
51 | | - */ |
52 | | - GetAZs: (region: string = ''): { 'Fn::GetAZs': string } => ({ |
| 42 | + GetAZs: (region: string = '') => ({ |
53 | 43 | 'Fn::GetAZs': region, |
54 | 44 | }), |
55 | | - |
56 | | - /** |
57 | | - * ImportValue - Returns the value of an output exported by another stack |
58 | | - */ |
59 | | - ImportValue: (name: string): { 'Fn::ImportValue': string } => ({ |
| 45 | + ImportValue: (name: string) => ({ |
60 | 46 | 'Fn::ImportValue': name, |
61 | 47 | }), |
62 | | - |
63 | | - /** |
64 | | - * If - Returns one value if condition is true, another if false |
65 | | - */ |
66 | | - If: (condition: string, trueValue: any, falseValue: any): { 'Fn::If': [string, any, any] } => ({ |
| 48 | + If: (condition: string, trueValue: any, falseValue: any) => ({ |
67 | 49 | 'Fn::If': [condition, trueValue, falseValue] as [string, any, any], |
68 | 50 | }), |
69 | | - |
70 | | - /** |
71 | | - * Equals - Compares if two values are equal |
72 | | - */ |
73 | | - Equals: (value1: any, value2: any): { 'Fn::Equals': [any, any] } => ({ |
| 51 | + Equals: (value1: any, value2: any) => ({ |
74 | 52 | 'Fn::Equals': [value1, value2] as [any, any], |
75 | 53 | }), |
76 | | - |
77 | | - /** |
78 | | - * And - Returns true if all conditions are true |
79 | | - */ |
80 | | - And: (...conditions: any[]): { 'Fn::And': any[] } => ({ |
| 54 | + And: (...conditions: any[]) => ({ |
81 | 55 | 'Fn::And': conditions, |
82 | 56 | }), |
83 | | - |
84 | | - /** |
85 | | - * Or - Returns true if any condition is true |
86 | | - */ |
87 | | - Or: (...conditions: any[]): { 'Fn::Or': any[] } => ({ |
| 57 | + Or: (...conditions: any[]) => ({ |
88 | 58 | 'Fn::Or': conditions, |
89 | 59 | }), |
90 | | - |
91 | | - /** |
92 | | - * Not - Returns true if condition is false |
93 | | - */ |
94 | | - Not: (condition: any): { 'Fn::Not': [any] } => ({ |
| 60 | + Not: (condition: any) => ({ |
95 | 61 | 'Fn::Not': [condition] as [any], |
96 | 62 | }), |
97 | | - |
98 | | - /** |
99 | | - * Base64 - Returns the Base64 representation of the input string |
100 | | - */ |
101 | | - Base64: (input: string): { 'Fn::Base64': string } => ({ |
| 63 | + Base64: (input: string) => ({ |
102 | 64 | 'Fn::Base64': input, |
103 | 65 | }), |
104 | | -} as const |
| 66 | +} |
105 | 67 |
|
106 | 68 | /** |
107 | 69 | * Pseudo Parameters - AWS CloudFormation provides several built-in parameters |
|
0 commit comments