This repository was archived by the owner on Jan 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathfunc_getatt.go
More file actions
48 lines (41 loc) · 1.31 KB
/
func_getatt.go
File metadata and controls
48 lines (41 loc) · 1.31 KB
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
package cloudformation
import "encoding/json"
// GetAtt returns a new instance of GetAttFunc.
func GetAtt(resource, name string) *StringExpr {
return GetAttFunc{Resource: resource, Name: name}.String()
}
// GetAttFunc represents an invocation of the Fn::GetAtt intrinsic.
//
// The intrinsic function Fn::GetAtt returns the value of an attribute from a
// resource in the template.
//
// See http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-getatt.html
type GetAttFunc struct {
Resource string
Name string
}
// MarshalJSON returns a JSON representation of the object
func (f GetAttFunc) MarshalJSON() ([]byte, error) {
return json.Marshal(struct {
FnGetAtt []string `json:"Fn::GetAtt"`
}{FnGetAtt: []string{f.Resource, f.Name}})
}
// UnmarshalJSON sets the object from the provided JSON representation
func (f *GetAttFunc) UnmarshalJSON(data []byte) error {
v := struct {
FnGetAtt []string `json:"Fn::GetAtt"`
}{}
if err := json.Unmarshal(data, &v); err != nil {
return err
}
if len(v.FnGetAtt) != 2 {
return &json.UnsupportedValueError{Str: string(data)}
}
f.Resource = v.FnGetAtt[0]
f.Name = v.FnGetAtt[1]
return nil
}
func (f GetAttFunc) String() *StringExpr {
return &StringExpr{Func: f}
}
var _ StringFunc = GetAttFunc{} // GetAttFunc must implement StringFunc