-
Notifications
You must be signed in to change notification settings - Fork 1
/
fn_if.go
40 lines (32 loc) · 920 Bytes
/
fn_if.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
package parser
func ResolveIf(property *Property) (resolved *Property, success bool) {
if !property.isFunction() {
return property, true
}
refValue := property.AsMap()["Fn::If"].AsList()
if len(refValue) != 3 {
return abortIntrinsic(property, "Fn::If should have exactly 3 values, returning original Property")
}
condition, _ := refValue[0].resolveValue()
trueState, _ := refValue[1].resolveValue()
falseState, _ := refValue[2].resolveValue()
conditionMet := false
con, _ := condition.resolveValue()
if con.IsBool() {
conditionMet = con.AsBool()
} else if property.ctx.Conditions != nil &&
condition.IsString() {
condition := property.ctx.Conditions[condition.AsString()]
if condition.isFunction() {
con, _ := condition.resolveValue()
if con.IsBool() {
conditionMet = con.AsBool()
}
}
}
if conditionMet {
return trueState, true
} else {
return falseState, true
}
}