Skip to content

Commit

Permalink
Fix parsing of GetAtt strings
Browse files Browse the repository at this point in the history
  • Loading branch information
stilvoid committed Jun 3, 2019
1 parent 1b91850 commit ceadd4e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
5 changes: 0 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@ github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/gucumber/gucumber v0.0.0-20180127021336-7d5c79e832a2/go.mod h1:YbdHRK9ViqwGMS0rtRY+1I6faHvVyyurKPIPwifihxI=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
Expand Down Expand Up @@ -55,5 +51,4 @@ golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
google.golang.org/appengine v1.2.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
8 changes: 8 additions & 0 deletions parse/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"io/ioutil"
"reflect"
"strings"

"github.com/google/go-cmp/cmp"
yaml "github.com/sanathkr/go-yaml"
Expand Down Expand Up @@ -50,6 +51,13 @@ func (t *tagUnmarshalerType) UnmarshalYAMLTag(tag string, value reflect.Value) r
}
tag = prefix + tag

// Deal with tricksy GetAtt
if tag == "Fn::GetAtt" {
if s, ok := value.Interface().(string); ok {
value = reflect.ValueOf(strings.SplitN(s, ".", 2))
}
}

output := reflect.ValueOf(make(map[interface{}]interface{}))
key := reflect.ValueOf(tag)
output.SetMapIndex(key, value)
Expand Down
18 changes: 18 additions & 0 deletions parse/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,24 @@ var expected = map[string]interface{}{
},
},
},
"Outputs": map[string]interface{}{
"Bucket1Arn": map[string]interface{}{
"Value": map[string]interface{}{
"Fn::GetAtt": []interface{}{
"Bucket1",
"Arn",
},
},
},
"Bucket2Arn": map[string]interface{}{
"Value": map[string]interface{}{
"Fn::GetAtt": []interface{}{
"Bucket2",
"Arn",
},
},
},
},
}

func init() {
Expand Down
9 changes: 9 additions & 0 deletions parse/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,12 @@ Resources:
Properties:
BucketName: !Base64
Ref: Cakes

Outputs:
Bucket1Arn:
Value: !GetAtt Bucket1.Arn
Bucket2Arn:
Value:
Fn::GetAtt:
- Bucket2
- Arn

0 comments on commit ceadd4e

Please sign in to comment.