Skip to content

Commit

Permalink
refactor: bump github.com/awslabs/goformation/v4 to current major ver…
Browse files Browse the repository at this point in the history
…sion (elastic#40160)

* refactor: bump github.com/awslabs/goformation/v4 to current major version

github.com/awslabs/goformation/v4 was released in 2019 and is no longer supported.
It also depends on v3 and has more dependencies compared to v7.
Bump the dependency to v7 to use a supported version.

* lint: fix linting issues
  • Loading branch information
kruskall authored Jul 10, 2024
1 parent fec980b commit 733f898
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 356 deletions.
285 changes: 7 additions & 278 deletions NOTICE.txt

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ require (
github.com/aws/aws-sdk-go-v2/service/s3 v1.53.1
github.com/aws/aws-sdk-go-v2/service/sqs v1.31.4
github.com/aws/aws-sdk-go-v2/service/sts v1.28.6
github.com/awslabs/goformation/v4 v4.1.0
github.com/blakesmith/ar v0.0.0-20150311145944-8bd4349a67f2
github.com/bsm/sarama-cluster v2.1.14-0.20180625083203-7e67d87a6b3f+incompatible
github.com/cavaliercoder/badio v0.0.0-20160213150051-ce5280129e9e // indirect
Expand Down Expand Up @@ -134,7 +133,6 @@ require (
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475
github.com/samuel/go-parser v0.0.0-20130731160455-ca8abbf65d0e // indirect
github.com/samuel/go-thrift v0.0.0-20140522043831-2187045faa54
github.com/sanathkr/yaml v1.0.1-0.20170819201035-0056894fa522 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5
Expand Down Expand Up @@ -195,6 +193,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/health v1.24.4
github.com/aws/aws-sdk-go-v2/service/kinesis v1.27.4
github.com/aws/smithy-go v1.20.2
github.com/awslabs/goformation/v7 v7.14.9
github.com/awslabs/kinesis-aggregation/go/v2 v2.0.0-20220623125934-28468a6701b5
github.com/elastic/bayeux v1.0.5
github.com/elastic/ebpfevents v0.6.0
Expand Down Expand Up @@ -351,7 +350,6 @@ require (
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/prometheus/client_golang v1.11.1 // indirect
github.com/rootless-containers/rootlesskit v1.1.0 // indirect
github.com/sanathkr/go-yaml v0.0.0-20170819195128-ed9d249f429b // indirect
github.com/sergi/go-diff v1.3.1 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/stoewer/go-strcase v1.2.0 // indirect
Expand Down
25 changes: 6 additions & 19 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,8 @@ github.com/aws/smithy-go v1.8.0/go.mod h1:SObp3lf9smib00L/v3U2eAKG8FyQ7iLrJnQiAm
github.com/aws/smithy-go v1.13.3/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA=
github.com/aws/smithy-go v1.20.2 h1:tbp628ireGtzcHDDmLT/6ADHidqnwgF57XOXZe6tp4Q=
github.com/aws/smithy-go v1.20.2/go.mod h1:krry+ya/rV9RDcV/Q16kpu6ypI4K2czasz0NC3qS14E=
github.com/awslabs/goformation/v3 v3.1.0/go.mod h1:hQ5RXo3GNm2laHWKizDzU5DsDy+yNcenSca2UxN0850=
github.com/awslabs/goformation/v4 v4.1.0 h1:JRxIW0IjhYpYDrIZOTJGMu2azXKI+OK5dP56ubpywGU=
github.com/awslabs/goformation/v4 v4.1.0/go.mod h1:MBDN7u1lMNDoehbFuO4uPvgwPeolTMA2TzX1yO6KlxI=
github.com/awslabs/goformation/v7 v7.14.9 h1:sZjjpTqXrcBDz4Fi07JWTT7zKM68XsQkW/7iLAJbA/M=
github.com/awslabs/goformation/v7 v7.14.9/go.mod h1:7obldQ8NQ/AkMsgL5K3l4lRMDFB6kCGUloz5dURcXIs=
github.com/awslabs/kinesis-aggregation/go/v2 v2.0.0-20220623125934-28468a6701b5 h1:lxW5Q6K2IisyF5tlr6Ts0W4POGWQZco05MJjFmoeIHs=
github.com/awslabs/kinesis-aggregation/go/v2 v2.0.0-20220623125934-28468a6701b5/go.mod h1:0Qr1uMHFmHsIYMcG4T7BJ9yrJtWadhOmpABCX69dwuc=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
Expand Down Expand Up @@ -1100,7 +1099,6 @@ github.com/icholy/digest v0.1.22 h1:dRIwCjtAcXch57ei+F0HSb5hmprL873+q7PoVojdMzM=
github.com/icholy/digest v0.1.22/go.mod h1:uLAeDdWKIWNFMH0wqbwchbTQOmJWhzSnL7zmqSPqEEc=
github.com/imdario/mergo v0.3.4/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/imdario/mergo v0.3.6/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU=
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
Expand Down Expand Up @@ -1363,20 +1361,18 @@ github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:v
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/onsi/ginkgo v0.0.0-20170829012221-11459a886d9c/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.5.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.11.0 h1:JAKSXpt1YjtLA7YpPiqO9ss6sNXEsPfSGdwN0UHqzrw=
github.com/onsi/ginkgo v1.11.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo/v2 v2.13.0 h1:0jY9lJquiL8fcf3M4LAXN5aMlS/b2BV86HFFPCPMgE4=
github.com/onsi/ginkgo/v2 v2.13.0/go.mod h1:TE309ZR8s5FsKKpuB1YAQYBzCaAfUgatB/xlT/ETL/o=
github.com/onsi/ginkgo/v2 v2.17.1 h1:V++EzdbhI4ZV4ev0UTIj0PzhzOcReJFyJaLjtSF55M8=
github.com/onsi/ginkgo/v2 v2.17.1/go.mod h1:llBI3WDLL9Z6taip6f33H76YcWtJv+7R3HigUjbIBOs=
github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
github.com/onsi/gomega v1.2.0/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/onsi/gomega v1.29.0 h1:KIA/t2t5UBzoirT4H9tsML45GEbo3ouUnBHsCfD2tVg=
github.com/onsi/gomega v1.29.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ=
github.com/onsi/gomega v1.33.0 h1:snPCflnZrpMsy94p4lXVEkHo12lmPnc3vY5XBbreexE=
github.com/onsi/gomega v1.33.0/go.mod h1:+925n5YtiFsLzzafLUHzVMBpvvRAzrydIBiSIxjX3wY=
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
Expand Down Expand Up @@ -1532,11 +1528,6 @@ github.com/samuel/go-parser v0.0.0-20130731160455-ca8abbf65d0e/go.mod h1:Sb6li54
github.com/samuel/go-thrift v0.0.0-20140522043831-2187045faa54 h1:jbchLJWyhKcmOjkbC4zDvT/n5EEd7g6hnnF760rEyRA=
github.com/samuel/go-thrift v0.0.0-20140522043831-2187045faa54/go.mod h1:Vrkh1pnjV9Bl8c3P9zH0/D4NlOHWP5d4/hF4YTULaec=
github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E=
github.com/sanathkr/go-yaml v0.0.0-20170819195128-ed9d249f429b h1:jUK33OXuZP/l6babJtnLo1qsGvq6G9so9KMflGAm4YA=
github.com/sanathkr/go-yaml v0.0.0-20170819195128-ed9d249f429b/go.mod h1:8458kAagoME2+LN5//WxE71ysZ3B7r22fdgb7qVmXSY=
github.com/sanathkr/yaml v0.0.0-20170819201035-0056894fa522/go.mod h1:tQTYKOQgxoH3v6dEmdHiz4JG+nbxWwM5fgPQUpSZqVQ=
github.com/sanathkr/yaml v1.0.1-0.20170819201035-0056894fa522 h1:39BJIaZIhIBmXATIhdlTBlTQpAiGXHnz17CrO7vF2Ss=
github.com/sanathkr/yaml v1.0.1-0.20170819201035-0056894fa522/go.mod h1:tQTYKOQgxoH3v6dEmdHiz4JG+nbxWwM5fgPQUpSZqVQ=
github.com/satori/go.uuid v0.0.0-20160603004225-b111a074d5ef/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.7.0.20210223165440-c65ae3540d44/go.mod h1:CJJ5VAbozOl0yEw7nHB9+7BXTJbIn6h7W+f6Gau5IP8=
Expand Down Expand Up @@ -1659,9 +1650,6 @@ github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c/go.mod h1:lB8K/P019DLNhe
github.com/xdg/scram v1.0.3/go.mod h1:lB8K/P019DLNhemzwFU4jHLhdvlE6uDZjXFejJXr49I=
github.com/xdg/stringprep v0.0.0-20180714160509-73f8eece6fdc/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y=
github.com/xdg/stringprep v1.0.3/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y=
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ=
github.com/xeipuuv/gojsonschema v0.0.0-20181112162635-ac52e6811b56/go.mod h1:5yf86TLmAcydyeJq5YvxkGPE2fm/u4myDekKRoLuqhs=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xlab/treeprint v0.0.0-20180616005107-d6fb6747feb6/go.mod h1:ce1O1j6UtZfjr22oyGxGLbauSBp2YVXpARAosm7dHBg=
github.com/xlab/treeprint v1.1.0/go.mod h1:gj5Gd3gPdKtR1ikdDK6fnFLdmIS0X30kTTuNd/WEJu0=
Expand Down Expand Up @@ -1889,7 +1877,6 @@ golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20191002035440-2ec189313ef0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20191004110552-13f9640d40b9/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20191021144547-ec77196f6094/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20191112182307-2180aed22343/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20191126235420-ef20fe5d7933/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
Expand Down
13 changes: 6 additions & 7 deletions x-pack/functionbeat/manager/aws/cli_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ package aws
import (
"context"
"fmt"
"io/ioutil"
"os"
"strings"

"github.com/aws/aws-sdk-go-v2/aws"
cf "github.com/aws/aws-sdk-go-v2/service/cloudformation"
"github.com/awslabs/goformation/v4/cloudformation"
"github.com/awslabs/goformation/v4/cloudformation/iam"
"github.com/awslabs/goformation/v4/cloudformation/lambda"
"github.com/awslabs/goformation/v7/cloudformation"
"github.com/awslabs/goformation/v7/cloudformation/iam"
"github.com/awslabs/goformation/v7/cloudformation/lambda"

"github.com/elastic/beats/v7/x-pack/functionbeat/function/provider"
"github.com/elastic/beats/v7/x-pack/functionbeat/manager/core"
Expand Down Expand Up @@ -113,7 +112,7 @@ func (c *CLIManager) deployTemplate(update bool, name string) error {
ctx := newStackContext()
if err := executer.Execute(ctx); err != nil {
if rollbackErr := executer.Rollback(ctx); rollbackErr != nil {
return fmt.Errorf("could not rollback, error: %s, %w", rollbackErr, err)
return fmt.Errorf("could not rollback, error: %s, %w", rollbackErr.Error(), err)
}
return err
}
Expand Down Expand Up @@ -163,7 +162,7 @@ func (c *CLIManager) Remove(name string) error {
ctx := newStackContext()
if err := executer.Execute(ctx); err != nil {
if rollbackErr := executer.Rollback(ctx); rollbackErr != nil {
return fmt.Errorf("could not rollback, error: %s, %w", rollbackErr, err)
return fmt.Errorf("could not rollback, error: %s, %w", rollbackErr.Error(), err)
}
return err
}
Expand Down Expand Up @@ -191,7 +190,7 @@ func (c *CLIManager) Package(outputPattern string) error {
}

output := strings.ReplaceAll(outputPattern, "{{.Provider}}", "aws")
err = ioutil.WriteFile(output, content, 0644)
err = os.WriteFile(output, content, 0644)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions x-pack/functionbeat/manager/aws/policies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ package aws
import (
"testing"

"github.com/awslabs/goformation/v4/cloudformation"
"github.com/awslabs/goformation/v4/cloudformation/iam"
"github.com/awslabs/goformation/v7/cloudformation"
"github.com/awslabs/goformation/v7/cloudformation/iam"
"github.com/stretchr/testify/assert"

"github.com/elastic/beats/v7/x-pack/functionbeat/function/provider"
Expand Down
56 changes: 28 additions & 28 deletions x-pack/functionbeat/manager/aws/template_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (
"errors"
"fmt"

"github.com/awslabs/goformation/v4/cloudformation"
"github.com/awslabs/goformation/v4/cloudformation/iam"
"github.com/awslabs/goformation/v4/cloudformation/lambda"
"github.com/awslabs/goformation/v4/cloudformation/logs"
"github.com/awslabs/goformation/v4/cloudformation/tags"
"github.com/awslabs/goformation/v7/cloudformation"
"github.com/awslabs/goformation/v7/cloudformation/iam"
"github.com/awslabs/goformation/v7/cloudformation/lambda"
"github.com/awslabs/goformation/v7/cloudformation/logs"
"github.com/awslabs/goformation/v7/cloudformation/tags"

"github.com/elastic/beats/v7/x-pack/functionbeat/function/provider"
"github.com/elastic/beats/v7/x-pack/functionbeat/manager/core"
Expand Down Expand Up @@ -164,7 +164,7 @@ func (d *defaultTemplateBuilder) template(function installer, name, codeLoc stri
var dlc *lambda.Function_DeadLetterConfig
if lambdaConfig.DeadLetterConfig != nil && len(lambdaConfig.DeadLetterConfig.TargetArn) != 0 {
dlc = &lambda.Function_DeadLetterConfig{
TargetArn: lambdaConfig.DeadLetterConfig.TargetArn,
TargetArn: cloudformation.String(lambdaConfig.DeadLetterConfig.TargetArn),
}
}

Expand All @@ -177,7 +177,7 @@ func (d *defaultTemplateBuilder) template(function installer, name, codeLoc stri
}
}

var ts []tags.Tag
ts := make([]tags.Tag, 0, len(lambdaConfig.Tags))
for name, val := range lambdaConfig.Tags {
tag := tags.Tag{
Key: name,
Expand All @@ -191,10 +191,10 @@ func (d *defaultTemplateBuilder) template(function installer, name, codeLoc stri
template.Resources[prefix("")] = &AWSLambdaFunction{
Function: &lambda.Function{
Code: &lambda.Function_Code{
S3Bucket: d.bucket,
S3Key: codeLoc,
S3Bucket: cloudformation.String(d.bucket),
S3Key: cloudformation.String(codeLoc),
},
Description: lambdaConfig.Description,
Description: cloudformation.String(lambdaConfig.Description),
Environment: &lambda.Function_Environment{
// Configure which function need to be run by the lambda function.
Variables: map[string]string{
Expand All @@ -204,21 +204,21 @@ func (d *defaultTemplateBuilder) template(function installer, name, codeLoc stri
},
DeadLetterConfig: dlc,
VpcConfig: vcpConf,
FunctionName: name,
FunctionName: cloudformation.String(name),
Role: role,
Runtime: runtime,
Handler: handlerName,
MemorySize: lambdaConfig.MemorySize.Megabytes(),
ReservedConcurrentExecutions: lambdaConfig.Concurrency,
Timeout: int(lambdaConfig.Timeout.Seconds()),
Runtime: cloudformation.String(runtime),
Handler: cloudformation.String(handlerName),
MemorySize: cloudformation.Int(lambdaConfig.MemorySize.Megabytes()),
ReservedConcurrentExecutions: cloudformation.Int(lambdaConfig.Concurrency),
Timeout: cloudformation.Int(int(lambdaConfig.Timeout.Seconds())),
Tags: ts,
},
DependsOn: dependsOn,
}

// Create the log group for the specific function lambda.
template.Resources[prefix("LogGroup")] = &logs.LogGroup{
LogGroupName: "/aws/lambda/" + name,
LogGroupName: cloudformation.String("/aws/lambda/" + name),
}

return template
Expand Down Expand Up @@ -263,8 +263,8 @@ func (d *defaultTemplateBuilder) roleTemplate(function installer, name string) *
},
},
},
Path: "/",
RoleName: "functionbeat-lambda-" + name + "-" + cloudformation.Ref("AWS::Region"),
Path: cloudformation.String("/"),
RoleName: cloudformation.String("functionbeat-lambda-" + name + "-" + cloudformation.Ref("AWS::Region")),
// Allow the lambda to write log to cloudwatch logs.
// doc: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-iam-policy.html
Policies: policies,
Expand All @@ -277,18 +277,18 @@ func (d *defaultTemplateBuilder) RawTemplate(name string) (string, error) {
return string(data.json), err
}

// mergeTemplate takes two cloudformation and merge them, if a key already exist we return an error.
func mergeTemplate(to, from *cloudformation.Template) error {
merge := func(m1 map[string]interface{}, m2 map[string]interface{}) error {
for k, v := range m2 {
if _, ok := m1[k]; ok {
return fmt.Errorf("key %s already exist in the template map", k)
}
m1[k] = v
func merge[M1 ~map[K]V, M2 ~map[K]V, K comparable, V any](m1 M1, m2 M2) error {
for k, v := range m2 {
if _, ok := m1[k]; ok {
return fmt.Errorf("key %v already exist in the template map", k)
}
return nil
m1[k] = v
}
return nil
}

// mergeTemplate takes two cloudformation and merge them, if a key already exist we return an error.
func mergeTemplate(to, from *cloudformation.Template) error {
err := merge(to.Parameters, from.Parameters)
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions x-pack/functionbeat/provider/aws/aws/cloudwatch_kinesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (

"github.com/aws/aws-lambda-go/events"
lambdarunner "github.com/aws/aws-lambda-go/lambda"
"github.com/awslabs/goformation/v4/cloudformation"
"github.com/awslabs/goformation/v4/cloudformation/iam"
"github.com/awslabs/goformation/v7/cloudformation"
"github.com/awslabs/goformation/v7/cloudformation/iam"

"github.com/elastic/beats/v7/libbeat/feature"
"github.com/elastic/beats/v7/libbeat/publisher/pipeline"
Expand Down
10 changes: 5 additions & 5 deletions x-pack/functionbeat/provider/aws/aws/cloudwatch_logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import (

"github.com/aws/aws-lambda-go/events"
lambdarunner "github.com/aws/aws-lambda-go/lambda"
"github.com/awslabs/goformation/v4/cloudformation"
"github.com/awslabs/goformation/v4/cloudformation/iam"
"github.com/awslabs/goformation/v4/cloudformation/lambda"
"github.com/awslabs/goformation/v4/cloudformation/policies"
"github.com/awslabs/goformation/v7/cloudformation"
"github.com/awslabs/goformation/v7/cloudformation/iam"
"github.com/awslabs/goformation/v7/cloudformation/lambda"
"github.com/awslabs/goformation/v7/cloudformation/policies"

"github.com/elastic/beats/v7/libbeat/feature"
"github.com/elastic/beats/v7/libbeat/publisher/pipeline"
Expand Down Expand Up @@ -193,7 +193,7 @@ func (c *CloudwatchLogs) Template() *cloudformation.Template {
".",
cloudformation.Ref("AWS::URLSuffix"), // awsamazon.com or .com.ch
}),
SourceArn: cloudformation.Join(
SourceArn: cloudformation.JoinPtr(
"",
[]string{
"arn:",
Expand Down
14 changes: 7 additions & 7 deletions x-pack/functionbeat/provider/aws/aws/kinesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (

"github.com/aws/aws-lambda-go/events"
lambdarunner "github.com/aws/aws-lambda-go/lambda"
"github.com/awslabs/goformation/v4/cloudformation"
"github.com/awslabs/goformation/v4/cloudformation/iam"
"github.com/awslabs/goformation/v4/cloudformation/lambda"
"github.com/awslabs/goformation/v7/cloudformation"
"github.com/awslabs/goformation/v7/cloudformation/iam"
"github.com/awslabs/goformation/v7/cloudformation/lambda"

"github.com/elastic/beats/v7/libbeat/feature"
"github.com/elastic/beats/v7/libbeat/publisher/pipeline"
Expand Down Expand Up @@ -181,11 +181,11 @@ func (k *Kinesis) Template() *cloudformation.Template {
for _, trigger := range k.config.Triggers {
resourceName := prefix(k.Name() + trigger.EventSourceArn)
template.Resources[resourceName] = &lambda.EventSourceMapping{
BatchSize: trigger.BatchSize,
ParallelizationFactor: trigger.ParallelizationFactor,
EventSourceArn: trigger.EventSourceArn,
BatchSize: cloudformation.Int(trigger.BatchSize),
ParallelizationFactor: cloudformation.Int(trigger.ParallelizationFactor),
EventSourceArn: cloudformation.String(trigger.EventSourceArn),
FunctionName: cloudformation.GetAtt(prefix(""), "Arn"),
StartingPosition: trigger.StartingPosition.String(),
StartingPosition: cloudformation.String(trigger.StartingPosition.String()),
}
}

Expand Down
10 changes: 5 additions & 5 deletions x-pack/functionbeat/provider/aws/aws/sqs.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (

"github.com/aws/aws-lambda-go/events"
lambdarunner "github.com/aws/aws-lambda-go/lambda"
"github.com/awslabs/goformation/v4/cloudformation"
"github.com/awslabs/goformation/v4/cloudformation/iam"
"github.com/awslabs/goformation/v4/cloudformation/lambda"
"github.com/awslabs/goformation/v7/cloudformation"
"github.com/awslabs/goformation/v7/cloudformation/iam"
"github.com/awslabs/goformation/v7/cloudformation/lambda"

"github.com/elastic/beats/v7/libbeat/feature"
"github.com/elastic/beats/v7/libbeat/publisher/pipeline"
Expand Down Expand Up @@ -106,8 +106,8 @@ func (s *SQS) Template() *cloudformation.Template {
for _, trigger := range s.config.Triggers {
resourceName := prefix("SQS") + NormalizeResourceName(trigger.EventSourceArn)
template.Resources[resourceName] = &lambda.EventSourceMapping{
BatchSize: batchSize,
EventSourceArn: trigger.EventSourceArn,
BatchSize: cloudformation.Int(batchSize),
EventSourceArn: cloudformation.String(trigger.EventSourceArn),
FunctionName: cloudformation.GetAtt(prefix(""), "Arn"),
}
}
Expand Down

0 comments on commit 733f898

Please sign in to comment.