Skip to content

Commit

Permalink
feat(schema): Improve SAM Global support (awslabs#376)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Improved implementation of Globals (in SAM tempates)

This PR introduces a new implementation for both defining SAM templates with `Global` values, as well as parsing templates containing them.

Note: Globals only apply to SAM templates - if you are using regular CloudFormation templates this breaking change should not impact you. The only impact you might see is if you are creating `cloudFormation.Template` structs manually rather than using the `cloudformation.NewTemplate()` constructor. As part of this change, a new field (`Globals`) was added to the `Template{}` struct. If you are not using the constructor, your compiler will probably complain that this field is missing from the struct instantiation in your code.    

For more information about what `Globals` are in SAM templates, see this link:
https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-specification-template-anatomy-globals.html

In previous versions of Goformation (before v5), goformation was able to parse SAM templates that contained a `Globals` section, however the implementation just overwrote the resource properties in the template, with the global values at parse time.

This meant that:

 - It was not possible to compose a template in Go that had a Globals section.
 - The JSON Schema generated by this repo, had no concept of Globals.

 **This new implementation DOES NOT does not overwrite the values in the template, like the previous implementation did**. It replaces the old implementation completely, and exposes Globals as a series of structs that are marshalled/unmarshalled to/from JSON/YAML.

 This allows you to compose a template:

```go
template := cloudformation.NewTemplate()

template.Globals["Function"] = &global.Function{
    Timeout: 1800,
}
```

As well as parse a JSON/YAML template, and inspect the global properties:

```go
template, err := goformation.Open("../some-template-with-globals.yml")
if err != nil {
    fmt.Printf("failed to open template: %s\n", err)
    os.Exit(1)
} 

fmt.Printf("%v", template.Globals["Function"])

// You can view the global as above, however it's type is downcast to a basic interface.
// If you want to inspect properties specific to the global type (e.g. the timeout for a Lambda function)
// then use the following helper methods to get the various global types from the template:

globalAPI, _:= template.GetServerlessGlobalApi()
globalFunction, _ := template.GetServerlessGlobalFunction()
globalHttpApi, _ := template.GetServerlessGlobalHttpApi()
globalSimpleTable, _ := template.GetServerlessGlobalSimpleTable()

fmt.Printf("Global Function Timeout: %d\n", globalFunction.Timeout)
```

*Issue #, if available:* Fixes issues awslabs#199 and awslabs#305
  • Loading branch information
bryceitoc9 committed Jun 20, 2021
1 parent 8da07d9 commit d56929b
Show file tree
Hide file tree
Showing 3,588 changed files with 8,856 additions and 4,916 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
8 changes: 4 additions & 4 deletions README.md
Expand Up @@ -29,7 +29,7 @@
As with other Go libraries, GoFormation can be installed with `go get`.

```
$ go get github.com/awslabs/goformation/v4
$ go get github.com/awslabs/goformation/v5
```

## Usage
Expand All @@ -46,8 +46,8 @@ import (
"strconv"
"time"

"github.com/awslabs/goformation/v4/cloudformation"
"github.com/awslabs/goformation/v4/cloudformation/sns"
"github.com/awslabs/goformation/v5/cloudformation"
"github.com/awslabs/goformation/v5/cloudformation/sns"


)
Expand Down Expand Up @@ -161,7 +161,7 @@ package main
import (
"log"

"github.com/awslabs/goformation/v4"
"github.com/awslabs/goformation/v5"
)

func main() {
Expand Down
4 changes: 2 additions & 2 deletions cloudformation/accessanalyzer/aws-accessanalyzer-analyzer.go
Expand Up @@ -5,8 +5,8 @@ import (
"encoding/json"
"fmt"

"github.com/awslabs/goformation/v4/cloudformation/policies"
"github.com/awslabs/goformation/v4/cloudformation/tags"
"github.com/awslabs/goformation/v5/cloudformation/policies"
"github.com/awslabs/goformation/v5/cloudformation/tags"
)

// Analyzer AWS CloudFormation Resource (AWS::AccessAnalyzer::Analyzer)
Expand Down
@@ -1,7 +1,7 @@
package accessanalyzer

import (
"github.com/awslabs/goformation/v4/cloudformation/policies"
"github.com/awslabs/goformation/v5/cloudformation/policies"
)

// Analyzer_ArchiveRule AWS CloudFormation Resource (AWS::AccessAnalyzer::Analyzer.ArchiveRule)
Expand Down
@@ -1,7 +1,7 @@
package accessanalyzer

import (
"github.com/awslabs/goformation/v4/cloudformation/policies"
"github.com/awslabs/goformation/v5/cloudformation/policies"
)

// Analyzer_Filter AWS CloudFormation Resource (AWS::AccessAnalyzer::Analyzer.Filter)
Expand Down
2 changes: 1 addition & 1 deletion cloudformation/acmpca/aws-acmpca-certificate.go
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"fmt"

"github.com/awslabs/goformation/v4/cloudformation/policies"
"github.com/awslabs/goformation/v5/cloudformation/policies"
)

// Certificate AWS CloudFormation Resource (AWS::ACMPCA::Certificate)
Expand Down
@@ -1,7 +1,7 @@
package acmpca

import (
"github.com/awslabs/goformation/v4/cloudformation/policies"
"github.com/awslabs/goformation/v5/cloudformation/policies"
)

// Certificate_ApiPassthrough AWS CloudFormation Resource (AWS::ACMPCA::Certificate.ApiPassthrough)
Expand Down
@@ -1,7 +1,7 @@
package acmpca

import (
"github.com/awslabs/goformation/v4/cloudformation/policies"
"github.com/awslabs/goformation/v5/cloudformation/policies"
)

// Certificate_CertificatePolicyList AWS CloudFormation Resource (AWS::ACMPCA::Certificate.CertificatePolicyList)
Expand Down
@@ -1,7 +1,7 @@
package acmpca

import (
"github.com/awslabs/goformation/v4/cloudformation/policies"
"github.com/awslabs/goformation/v5/cloudformation/policies"
)

// Certificate_EdiPartyName AWS CloudFormation Resource (AWS::ACMPCA::Certificate.EdiPartyName)
Expand Down
@@ -1,7 +1,7 @@
package acmpca

import (
"github.com/awslabs/goformation/v4/cloudformation/policies"
"github.com/awslabs/goformation/v5/cloudformation/policies"
)

// Certificate_ExtendedKeyUsage AWS CloudFormation Resource (AWS::ACMPCA::Certificate.ExtendedKeyUsage)
Expand Down
@@ -1,7 +1,7 @@
package acmpca

import (
"github.com/awslabs/goformation/v4/cloudformation/policies"
"github.com/awslabs/goformation/v5/cloudformation/policies"
)

// Certificate_ExtendedKeyUsageList AWS CloudFormation Resource (AWS::ACMPCA::Certificate.ExtendedKeyUsageList)
Expand Down
2 changes: 1 addition & 1 deletion cloudformation/acmpca/aws-acmpca-certificate_extensions.go
@@ -1,7 +1,7 @@
package acmpca

import (
"github.com/awslabs/goformation/v4/cloudformation/policies"
"github.com/awslabs/goformation/v5/cloudformation/policies"
)

// Certificate_Extensions AWS CloudFormation Resource (AWS::ACMPCA::Certificate.Extensions)
Expand Down
@@ -1,7 +1,7 @@
package acmpca

import (
"github.com/awslabs/goformation/v4/cloudformation/policies"
"github.com/awslabs/goformation/v5/cloudformation/policies"
)

// Certificate_GeneralName AWS CloudFormation Resource (AWS::ACMPCA::Certificate.GeneralName)
Expand Down
@@ -1,7 +1,7 @@
package acmpca

import (
"github.com/awslabs/goformation/v4/cloudformation/policies"
"github.com/awslabs/goformation/v5/cloudformation/policies"
)

// Certificate_GeneralNameList AWS CloudFormation Resource (AWS::ACMPCA::Certificate.GeneralNameList)
Expand Down
2 changes: 1 addition & 1 deletion cloudformation/acmpca/aws-acmpca-certificate_keyusage.go
@@ -1,7 +1,7 @@
package acmpca

import (
"github.com/awslabs/goformation/v4/cloudformation/policies"
"github.com/awslabs/goformation/v5/cloudformation/policies"
)

// Certificate_KeyUsage AWS CloudFormation Resource (AWS::ACMPCA::Certificate.KeyUsage)
Expand Down
2 changes: 1 addition & 1 deletion cloudformation/acmpca/aws-acmpca-certificate_othername.go
@@ -1,7 +1,7 @@
package acmpca

import (
"github.com/awslabs/goformation/v4/cloudformation/policies"
"github.com/awslabs/goformation/v5/cloudformation/policies"
)

// Certificate_OtherName AWS CloudFormation Resource (AWS::ACMPCA::Certificate.OtherName)
Expand Down
@@ -1,7 +1,7 @@
package acmpca

import (
"github.com/awslabs/goformation/v4/cloudformation/policies"
"github.com/awslabs/goformation/v5/cloudformation/policies"
)

// Certificate_PolicyInformation AWS CloudFormation Resource (AWS::ACMPCA::Certificate.PolicyInformation)
Expand Down
@@ -1,7 +1,7 @@
package acmpca

import (
"github.com/awslabs/goformation/v4/cloudformation/policies"
"github.com/awslabs/goformation/v5/cloudformation/policies"
)

// Certificate_PolicyQualifierInfo AWS CloudFormation Resource (AWS::ACMPCA::Certificate.PolicyQualifierInfo)
Expand Down
@@ -1,7 +1,7 @@
package acmpca

import (
"github.com/awslabs/goformation/v4/cloudformation/policies"
"github.com/awslabs/goformation/v5/cloudformation/policies"
)

// Certificate_PolicyQualifierInfoList AWS CloudFormation Resource (AWS::ACMPCA::Certificate.PolicyQualifierInfoList)
Expand Down
2 changes: 1 addition & 1 deletion cloudformation/acmpca/aws-acmpca-certificate_qualifier.go
@@ -1,7 +1,7 @@
package acmpca

import (
"github.com/awslabs/goformation/v4/cloudformation/policies"
"github.com/awslabs/goformation/v5/cloudformation/policies"
)

// Certificate_Qualifier AWS CloudFormation Resource (AWS::ACMPCA::Certificate.Qualifier)
Expand Down
2 changes: 1 addition & 1 deletion cloudformation/acmpca/aws-acmpca-certificate_subject.go
@@ -1,7 +1,7 @@
package acmpca

import (
"github.com/awslabs/goformation/v4/cloudformation/policies"
"github.com/awslabs/goformation/v5/cloudformation/policies"
)

// Certificate_Subject AWS CloudFormation Resource (AWS::ACMPCA::Certificate.Subject)
Expand Down
2 changes: 1 addition & 1 deletion cloudformation/acmpca/aws-acmpca-certificate_validity.go
@@ -1,7 +1,7 @@
package acmpca

import (
"github.com/awslabs/goformation/v4/cloudformation/policies"
"github.com/awslabs/goformation/v5/cloudformation/policies"
)

// Certificate_Validity AWS CloudFormation Resource (AWS::ACMPCA::Certificate.Validity)
Expand Down
4 changes: 2 additions & 2 deletions cloudformation/acmpca/aws-acmpca-certificateauthority.go
Expand Up @@ -5,8 +5,8 @@ import (
"encoding/json"
"fmt"

"github.com/awslabs/goformation/v4/cloudformation/policies"
"github.com/awslabs/goformation/v4/cloudformation/tags"
"github.com/awslabs/goformation/v5/cloudformation/policies"
"github.com/awslabs/goformation/v5/cloudformation/tags"
)

// CertificateAuthority AWS CloudFormation Resource (AWS::ACMPCA::CertificateAuthority)
Expand Down
@@ -1,7 +1,7 @@
package acmpca

import (
"github.com/awslabs/goformation/v4/cloudformation/policies"
"github.com/awslabs/goformation/v5/cloudformation/policies"
)

// CertificateAuthority_AccessDescription AWS CloudFormation Resource (AWS::ACMPCA::CertificateAuthority.AccessDescription)
Expand Down
@@ -1,7 +1,7 @@
package acmpca

import (
"github.com/awslabs/goformation/v4/cloudformation/policies"
"github.com/awslabs/goformation/v5/cloudformation/policies"
)

// CertificateAuthority_AccessMethod AWS CloudFormation Resource (AWS::ACMPCA::CertificateAuthority.AccessMethod)
Expand Down
@@ -1,7 +1,7 @@
package acmpca

import (
"github.com/awslabs/goformation/v4/cloudformation/policies"
"github.com/awslabs/goformation/v5/cloudformation/policies"
)

// CertificateAuthority_CrlConfiguration AWS CloudFormation Resource (AWS::ACMPCA::CertificateAuthority.CrlConfiguration)
Expand Down
@@ -1,7 +1,7 @@
package acmpca

import (
"github.com/awslabs/goformation/v4/cloudformation/policies"
"github.com/awslabs/goformation/v5/cloudformation/policies"
)

// CertificateAuthority_CsrExtensions AWS CloudFormation Resource (AWS::ACMPCA::CertificateAuthority.CsrExtensions)
Expand Down
@@ -1,7 +1,7 @@
package acmpca

import (
"github.com/awslabs/goformation/v4/cloudformation/policies"
"github.com/awslabs/goformation/v5/cloudformation/policies"
)

// CertificateAuthority_EdiPartyName AWS CloudFormation Resource (AWS::ACMPCA::CertificateAuthority.EdiPartyName)
Expand Down
@@ -1,7 +1,7 @@
package acmpca

import (
"github.com/awslabs/goformation/v4/cloudformation/policies"
"github.com/awslabs/goformation/v5/cloudformation/policies"
)

// CertificateAuthority_GeneralName AWS CloudFormation Resource (AWS::ACMPCA::CertificateAuthority.GeneralName)
Expand Down
@@ -1,7 +1,7 @@
package acmpca

import (
"github.com/awslabs/goformation/v4/cloudformation/policies"
"github.com/awslabs/goformation/v5/cloudformation/policies"
)

// CertificateAuthority_KeyUsage AWS CloudFormation Resource (AWS::ACMPCA::CertificateAuthority.KeyUsage)
Expand Down
@@ -1,7 +1,7 @@
package acmpca

import (
"github.com/awslabs/goformation/v4/cloudformation/policies"
"github.com/awslabs/goformation/v5/cloudformation/policies"
)

// CertificateAuthority_OtherName AWS CloudFormation Resource (AWS::ACMPCA::CertificateAuthority.OtherName)
Expand Down
@@ -1,7 +1,7 @@
package acmpca

import (
"github.com/awslabs/goformation/v4/cloudformation/policies"
"github.com/awslabs/goformation/v5/cloudformation/policies"
)

// CertificateAuthority_RevocationConfiguration AWS CloudFormation Resource (AWS::ACMPCA::CertificateAuthority.RevocationConfiguration)
Expand Down
@@ -1,7 +1,7 @@
package acmpca

import (
"github.com/awslabs/goformation/v4/cloudformation/policies"
"github.com/awslabs/goformation/v5/cloudformation/policies"
)

// CertificateAuthority_Subject AWS CloudFormation Resource (AWS::ACMPCA::CertificateAuthority.Subject)
Expand Down
@@ -1,7 +1,7 @@
package acmpca

import (
"github.com/awslabs/goformation/v4/cloudformation/policies"
"github.com/awslabs/goformation/v5/cloudformation/policies"
)

// CertificateAuthority_SubjectInformationAccess AWS CloudFormation Resource (AWS::ACMPCA::CertificateAuthority.SubjectInformationAccess)
Expand Down
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"fmt"

"github.com/awslabs/goformation/v4/cloudformation/policies"
"github.com/awslabs/goformation/v5/cloudformation/policies"
)

// CertificateAuthorityActivation AWS CloudFormation Resource (AWS::ACMPCA::CertificateAuthorityActivation)
Expand Down

0 comments on commit d56929b

Please sign in to comment.