Skip to content

Commit

Permalink
fix(template): field Export on type Output should be pointer (awslabs…
Browse files Browse the repository at this point in the history
…#299)

the field Export of th type Output should be a pointer,
otherwise it would produce invalid output, by adding
an empty struct to the export field:

Outputs:
  VpcId:
    Export: {}

This empty struct will cause a template validation error:

"Template format error: Output VpcId is malformed.
The Name field of every Export member is required."

Closes awslabs#294
  • Loading branch information
paulbes committed Feb 9, 2021
1 parent 4dd9776 commit 7d5870e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cloudformation/template.go
Expand Up @@ -40,7 +40,7 @@ type Parameter struct {
type Output struct {
Value interface{} `json:"Value"`
Description string `json:"Description,omitempty"`
Export Export `json:"Export,omitempty"`
Export *Export `json:"Export,omitempty"`
}

type Export struct {
Expand Down
44 changes: 44 additions & 0 deletions goformation_test.go
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/awslabs/goformation/v4"
"github.com/awslabs/goformation/v4/cloudformation"
"github.com/awslabs/goformation/v4/cloudformation/ec2"
"github.com/awslabs/goformation/v4/cloudformation/lambda"
"github.com/awslabs/goformation/v4/cloudformation/policies"
"github.com/awslabs/goformation/v4/cloudformation/route53"
Expand Down Expand Up @@ -1252,4 +1253,47 @@ var _ = Describe("Goformation", func() {

})

Context("with a template that contains outputs with no exports", func() {

Context("described as Go structs", func() {

template := cloudformation.NewTemplate()

template.Resources["Vpc"] = &ec2.VPC{
CidrBlock: "192.168.0.0/20",
}

template.Outputs["VpcId"] = cloudformation.Output{
Value: cloudformation.Ref("Vpc"),
}

expected := `{
"AWSTemplateFormatVersion": "2010-09-09",
"Outputs": {
"VpcId": {
"Value": {
"Ref": "Vpc"
}
}
},
"Resources": {
"Vpc": {
"Properties": {
"CidrBlock": "192.168.0.0/20"
},
"Type": "AWS::EC2::VPC"
}
}
}`

got, err := template.JSON()
It("should marshal template successfully", func() {
Expect(err).To(BeNil())
})

It("should be equal to expected output", func() {
Expect(string(got)).To(Equal(expected))
})
})
})
})

0 comments on commit 7d5870e

Please sign in to comment.