Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Commit

Permalink
fix(template): field Export on type Output should be pointer (#299)
Browse files Browse the repository at this point in the history
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 #294
  • Loading branch information
paulbes authored 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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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.