This repository has been archived by the owner on Oct 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 197
/
ref.go
58 lines (48 loc) · 1.89 KB
/
ref.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package intrinsics
// Ref resolves the 'Ref' AWS CloudFormation intrinsic function.
// Currently, this only resolves against CloudFormation Parameter default values
// See: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html
func Ref(name string, input interface{}, template interface{}) interface{} {
// Dang son, this has got more nest than a bald eagle
// Check the input is a string
if name, ok := input.(string); ok {
switch name {
case "AWS::AccountId":
return "123456789012"
case "AWS::NotificationARNs": //
return []string{"arn:aws:sns:us-east-1:123456789012:MyTopic"}
case "AWS::NoValue":
return nil
case "AWS::Region":
return "us-east-1"
case "AWS::StackId":
return "arn:aws:cloudformation:us-east-1:123456789012:stack/MyStack/1c2fa620-982a-11e3-aff7-50e2416294e0"
case "AWS::StackName":
return "goformation-stack"
default:
// This isn't a pseudo 'Ref' paramater, so we need to look inside the CloudFormation template
// to see if we can resolve the reference. This implementation just looks at the Parameters section
// to see if there is a parameter matching the name, and if so, return the default value.
// Check the template is a map
if template, ok := template.(map[string]interface{}); ok {
// Check there is a parameters section
if uparameters, ok := template["Parameters"]; ok {
// Check the parameters section is a map
if parameters, ok := uparameters.(map[string]interface{}); ok {
// Check there is a parameter with the same name as the Ref
if uparameter, ok := parameters[name]; ok {
// Check the parameter is a map
if parameter, ok := uparameter.(map[string]interface{}); ok {
// Check the parameter has a default
if def, ok := parameter["Default"]; ok {
return def
}
}
}
}
}
}
}
}
return nil
}