-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added lambda support and goreleaser.
- Loading branch information
1 parent
20432ef
commit 60d31b1
Showing
10 changed files
with
348 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,3 +120,7 @@ dist | |
.pnp.* | ||
|
||
config.yml | ||
|
||
dist/ | ||
cf-params.json | ||
.build.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# This is an example .goreleaser.yml file with some sensible defaults. | ||
# Make sure to check the documentation at https://goreleaser.com | ||
before: | ||
hooks: | ||
# You may remove this if you don't use go modules. | ||
- go mod tidy | ||
|
||
builds: | ||
- id: standalone | ||
main: ./cmd/nr-entity-tag-sync/nr-entity-tag-sync.go | ||
env: | ||
- CGO_ENABLED=0 | ||
goos: | ||
- linux | ||
#- windows | ||
#- darwin | ||
goarch: | ||
- amd64 | ||
- id: lambda | ||
main: ./cmd/nr-entity-tag-sync-lambda/nr-entity-tag-sync-lambda.go | ||
binary: nr-entity-tag-sync-lambda | ||
env: | ||
- CGO_ENABLED=0 | ||
goos: | ||
- linux | ||
goarch: | ||
- amd64 | ||
|
||
dockers: | ||
- id: lambda-image | ||
ids: | ||
- lambda | ||
image_templates: | ||
- "{{ .Env.AWS_ECR_REPO_URI }}:latest" | ||
- "{{ .Env.AWS_ECR_REPO_URI }}:{{ .Tag }}" | ||
dockerfile: ./deployments/Dockerfile-lambda | ||
extra_files: | ||
- configs/config.yml | ||
|
||
archives: | ||
- format: tar.gz | ||
builds: | ||
- standalone | ||
# this name template makes the OS and Arch compatible with the results of uname. | ||
name_template: >- | ||
{{ .ProjectName }}_ | ||
{{- title .Os }}_ | ||
{{- if eq .Arch "amd64" }}x86_64 | ||
{{- else if eq .Arch "386" }}i386 | ||
{{- else }}{{ .Arch }}{{ end }} | ||
{{- if .Arm }}v{{ .Arm }}{{ end }} | ||
# use zip for windows archives | ||
format_overrides: | ||
- goos: windows | ||
format: zip | ||
|
||
checksum: | ||
name_template: 'checksums.txt' | ||
|
||
snapshot: | ||
name_template: "{{ incpatch .Version }}-next" | ||
changelog: | ||
sort: asc | ||
filters: | ||
exclude: | ||
- '^docs:' | ||
- '^test:' | ||
|
||
# The lines beneath this are called `modelines`. See `:help modeline` | ||
# Feel free to remove those if you don't want/use them. | ||
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json | ||
# vim: set ts=2 sw=2 tw=0 fo=cnqoj |
39 changes: 39 additions & 0 deletions
39
cmd/nr-entity-tag-sync-lambda/nr-entity-tag-sync-lambda.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
_ "github.com/newrelic/nr-entity-tag-sync/internal/provider/servicenow" | ||
|
||
"github.com/aws/aws-lambda-go/lambda" | ||
"github.com/newrelic/nr-entity-tag-sync/internal/sync" | ||
"github.com/newrelic/nr-entity-tag-sync/pkg/interop" | ||
) | ||
|
||
type TagSyncResult struct { | ||
Success bool | ||
Message error | ||
} | ||
|
||
func HandleRequest(ctx context.Context) (TagSyncResult, error) { | ||
i, err := interop.NewInteroperability() | ||
if err != nil { | ||
retErr := fmt.Errorf("failed to create interop: %s", err) | ||
return TagSyncResult{false, retErr}, retErr | ||
} | ||
|
||
defer i.Shutdown() | ||
|
||
err = sync.Sync(i) | ||
if err != nil { | ||
retErr := fmt.Errorf("sync failed: %s", err) | ||
return TagSyncResult{false, retErr}, retErr | ||
} | ||
|
||
return TagSyncResult{true, nil}, nil | ||
} | ||
|
||
func main() { | ||
lambda.Start(HandleRequest) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
FROM public.ecr.aws/lambda/provided:al2 | ||
COPY nr-entity-tag-sync-lambda /main | ||
COPY configs/config.yml /var/task/configs/config.yml | ||
ENTRYPOINT [ "/main" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
[ | ||
{ | ||
"ParameterKey": "ImageRepoUri", | ||
"ParameterValue": "12345.dkr.ecr.aws_region.amazonaws.com/example-repo-name" | ||
}, | ||
{ | ||
"ParameterKey": "ImageTag", | ||
"ParameterValue": "1.0.0" | ||
}, | ||
{ | ||
"ParameterKey": "ExecRoleArn", | ||
"ParameterValue": "arn:aws:iam::12345:role/my-execute-lambda-role" | ||
}, | ||
{ | ||
"ParameterKey": "FunctionName", | ||
"ParameterValue": "NrEntityTagSync" | ||
}, | ||
{ | ||
"ParameterKey": "FunctionTimeout", | ||
"ParameterValue": "120" | ||
}, | ||
{ | ||
"ParameterKey": "FunctionMemorySize", | ||
"ParameterValue": "512" | ||
}, | ||
{ | ||
"ParameterKey": "NRLicenseKey", | ||
"ParameterValue": "123456" | ||
}, | ||
{ | ||
"ParameterKey": "NRLogLevel", | ||
"ParameterValue": "INFO" | ||
}, | ||
{ | ||
"ParameterKey": "UserApiKey", | ||
"ParameterValue": "123456" | ||
}, | ||
{ | ||
"ParameterKey": "SnowApiUser", | ||
"ParameterValue": "admin" | ||
}, | ||
{ | ||
"ParameterKey": "SnowApiPassword", | ||
"ParameterValue": "admin" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
AWSTemplateFormatVersion: '2010-09-09' | ||
Description: Sample CloudFormation template for deploying the AWS Lambda image. | ||
|
||
Parameters: | ||
# | ||
# URI of the ECR repository. | ||
# | ||
ImageRepoUri: | ||
Type: String | ||
Description: URI of the ECR repository. | ||
# | ||
# ECR image tag. | ||
# | ||
ImageTag: | ||
Type: String | ||
Description: ECR image tag. | ||
Default: latest | ||
# | ||
# ARN of the lambda execution role used to execute the lambda. | ||
# | ||
# Used during deployment. | ||
# | ||
ExecRoleArn: | ||
Type: String | ||
Description: ARN of the IAM role used for lambda execution. | ||
AllowedPattern: 'arn:(aws[a-zA-Z-]*)?:iam::\d{12}:role/?[a-zA-Z_0-9+=,.@\-_/]+' | ||
# | ||
# Name of the lambda function. | ||
# | ||
# Used during deployment. | ||
# | ||
FunctionName: | ||
Type: String | ||
Description: Name of the lambda function. | ||
Default: NrEntityTagSync | ||
# | ||
# Timeout (in seconds) for the lambda function. | ||
# | ||
# Used during deployment. | ||
# | ||
FunctionTimeout: | ||
Type: Number | ||
Description: Timeout (in seconds) for the lambda function. | ||
MinValue: 1 | ||
MaxValue: 900 | ||
Default: 60 | ||
# | ||
# Memory size for the lambda function. | ||
# | ||
# Used during deployment. | ||
# | ||
FunctionMemorySize: | ||
Type: Number | ||
Description: Memory size for the lambda function. | ||
MinValue: 128 | ||
MaxValue: 10240 | ||
Default: 256 | ||
# | ||
# New Relic license key for the New Relic Go APM agent. | ||
# | ||
NRLicenseKey: | ||
Type: String | ||
Description: Your New Relic license key. | ||
AllowedPattern: '[a-zA-Z0-9\-_]*' | ||
Default: '' | ||
# | ||
# Log level for the New Relic AWS lambda extension. Defaults to 'INFO'. | ||
# | ||
# Used at runtime by the New Relic AWS lambda extension. | ||
# See https://docs.newrelic.com/docs/serverless-function-monitoring/aws-lambda-monitoring/enable-lambda-monitoring/account-linking/#env-var | ||
# | ||
NRLogLevel: | ||
Type: String | ||
Description: Log level for the New Relic Lamba extension. | ||
Default: INFO | ||
AllowedValues: | ||
- INFO | ||
- DEBUG | ||
# | ||
# New Relic User API key used for GraphQL Nerdstorage queries and mutations. | ||
# | ||
UserApiKey: | ||
Type: String | ||
Description: The New Relic User API key to use. | ||
AllowedPattern: '[a-zA-Z0-9._\-]*' | ||
Default: '' | ||
# | ||
# Service Now API user name used by the Service Now provider. | ||
# | ||
SnowApiUser: | ||
Type: String | ||
Description: The Service Now API user. | ||
Default: '' | ||
# | ||
# Service Now API password name used by the Service Now provider. | ||
# | ||
SnowApiPassword: | ||
Type: String | ||
Description: The Service Now API password. | ||
Default: '' | ||
|
||
Resources: | ||
|
||
# | ||
# The lambda. | ||
# | ||
|
||
NrEntityTagSync: | ||
Type: AWS::Lambda::Function | ||
Properties: | ||
PackageType: Image | ||
Code: | ||
ImageUri: !Sub ${ImageRepoUri}:${ImageTag} | ||
Role: !Sub ${ExecRoleArn} | ||
Description: A lambda for syncing tags between external entities and New Relic entities. | ||
FunctionName: !Sub ${FunctionName} | ||
Timeout: !Ref FunctionTimeout | ||
MemorySize: !Ref FunctionMemorySize | ||
Environment: | ||
Variables: | ||
# Lambda environment variables | ||
NEW_RELIC_LICENSE_KEY: !Sub ${NRLicenseKey} | ||
NEW_RELIC_API_KEY: !Sub ${UserApiKey} | ||
|
||
# Service Now provider variables | ||
NR_CMDB_SNOW_APIUSER: !Sub ${SnowApiUser} | ||
NR_CMDB_SNOW_APIPASSWORD: !Sub ${SnowApiPassword} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.