Skip to content

Commit

Permalink
fix(schema): Add architectures support for sam functions (awslabs#419)
Browse files Browse the repository at this point in the history
Co-authored-by: Zihao Zhang <[email protected]>
  • Loading branch information
zzh8829 and zzh8829 authored Dec 30, 2021
1 parent a8be603 commit b505b69
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cloudformation/global/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import (
// See: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
type Function struct {

// Architectures AWS CloudFormation Property
// Required: false
// See: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-function.html#sam-function-architectures
Architectures []string `json:"Architectures,omitempty"`

// AssumeRolePolicyDocument AWS CloudFormation Property
// Required: false
// See: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-function.html#sam-function-assumerolepolicydocument
Expand Down
5 changes: 5 additions & 0 deletions cloudformation/serverless/aws-serverless-function.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ import (
// See: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
type Function struct {

// Architectures AWS CloudFormation Property
// Required: false
// See: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-function.html#sam-function-architectures
Architectures []string `json:"Architectures,omitempty"`

// AssumeRolePolicyDocument AWS CloudFormation Property
// Required: false
// See: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-function.html#sam-function-assumerolepolicydocument
Expand Down
7 changes: 7 additions & 0 deletions generate/sam-2016-10-31.json
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,13 @@
"Required": false,
"PrimitiveType": "String",
"UpdateType": "Immutable"
},
"Architectures": {
"Documentation": "https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-function.html#sam-function-architectures",
"Required": false,
"Type": "List",
"ItemType": "String",
"UpdateType": "Immutable"
}
}
},
Expand Down
37 changes: 37 additions & 0 deletions goformation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1449,5 +1449,42 @@ var _ = Describe("Goformation", func() {
Expect(string(got)).To(Equal(expected))
})
})

Context("that has an image in arm64 architecture", func() {
template := cloudformation.NewTemplate()
transform := "AWS::Serverless-2016-10-31"
template.Transform = &cloudformation.Transform{
String: &transform,
}
template.Resources["TestFunction"] = &serverless.Function{
Architectures: []string{"arm64"},
ImageUri: "image:latest-arm64",
}

expected := `{
"AWSTemplateFormatVersion": "2010-09-09",
"Resources": {
"TestFunction": {
"Properties": {
"Architectures": [
"arm64"
],
"ImageUri": "image:latest-arm64"
},
"Type": "AWS::Serverless::Function"
}
},
"Transform": "AWS::Serverless-2016-10-31"
}`

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))
})
})
})
})
12 changes: 12 additions & 0 deletions schema/sam.go
Original file line number Diff line number Diff line change
Expand Up @@ -115596,6 +115596,12 @@ var SamSchema = `{
"Properties": {
"additionalProperties": false,
"properties": {
"Architectures": {
"items": {
"type": "string"
},
"type": "array"
},
"AssumeRolePolicyDocument": {
"type": "object"
},
Expand Down Expand Up @@ -125865,6 +125871,12 @@ var SamSchema = `{
},
"Function": {
"properties": {
"Architectures": {
"items": {
"type": "string"
},
"type": "array"
},
"AssumeRolePolicyDocument": {
"type": "object"
},
Expand Down
12 changes: 12 additions & 0 deletions schema/sam.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -115593,6 +115593,12 @@
"Properties": {
"additionalProperties": false,
"properties": {
"Architectures": {
"items": {
"type": "string"
},
"type": "array"
},
"AssumeRolePolicyDocument": {
"type": "object"
},
Expand Down Expand Up @@ -125862,6 +125868,12 @@
},
"Function": {
"properties": {
"Architectures": {
"items": {
"type": "string"
},
"type": "array"
},
"AssumeRolePolicyDocument": {
"type": "object"
},
Expand Down

0 comments on commit b505b69

Please sign in to comment.