Skip to content

Commit

Permalink
updated func to latest module syntax (#40)
Browse files Browse the repository at this point in the history
* updated to latest lambda module syntax

* added Codeowners
  • Loading branch information
moritzzimmer committed Mar 17, 2021
1 parent a3449f9 commit 35617d8
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 54 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @moritzzimmer
2 changes: 1 addition & 1 deletion generate/ci/templates/-dot-github/workflows/build.yml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ jobs:

- uses: actions/setup-go@v1.1.3
with:
go-version: '1.15'
go-version: '1.16'

- run: make
6 changes: 3 additions & 3 deletions generate/core/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ func DefaultOpts() *Options {
},
Aws: &Aws{Region: "eu-west-1"},
Terraform: &Terraform{
AwsProvider: "3.21",
Version: "0.14.2",
AwsProvider: "3.32.0",
Version: "0.14.8",
Module: &Module{
Source: "moritzzimmer/lambda/aws",
Version: "5.7.0",
Version: "5.12.0",
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion generate/core/templates/Makefile.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ init: ## Initialize Terraform working directory and backend configuration
@terraform init -input=false terraform/

.PHONY: validate
validate: ## Validates and rewrited the Terraform files to canonical format
validate: ## Validates and rewrites Terraform files to canonical format
@echo "+ $@"
@terraform fmt -check=true terraform/
@terraform validate terraform/
Expand Down
89 changes: 73 additions & 16 deletions generate/core/templates/terraform/main.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,101 @@ locals {
artifact = "${path.module}/../bin/{{.opts.App.Name}}.zip"
}

{{if eq .opts.App.Event "dynamodb" -}}
resource "aws_dynamodb_table" "table_1" {
name = "example-dynamodb-table-1"
hash_key = "UserId"
read_capacity = 1
stream_enabled = true
stream_view_type = "KEYS_ONLY"
write_capacity = 1

attribute {
name = "UserId"
type = "S"
}
}
{{end -}}

{{if eq .opts.App.Event "kinesis" -}}
resource "aws_kinesis_stream" "stream_1" {
name = "example-kinesis-stream-1"
shard_count = 1
}
{{end -}}

{{if eq .opts.App.Event "s3" -}}
data "aws_s3_bucket" "example" {
bucket = "replace-me-with-existing-bucket"
}
{{end -}}

{{if eq .opts.App.Event "sns" -}}
resource "aws_sns_topic" "topic_1" {
name = "example-sns-topic-1"
}
{{end -}}

{{if eq .opts.App.Event "sqs" -}}
resource "aws_sqs_queue" "queue_1" {
name = "example-sqs-queue-1"
}
{{end -}}

module "{{.opts.App.Name}}" {
source = "{{.opts.Terraform.Module.Source}}"
version = "{{.opts.Terraform.Module.Version}}"

description = "bootstrapped Lambda, powered by func"
filename = local.artifact
function_name = "{{.opts.App.Name}}"
handler = "{{.opts.App.Name}}"
runtime = "go1.x"
source_code_hash = filebase64sha256(local.artifact)

tags = {
managed_by = "terraform"
managed_by = "terraform"
}

{{if eq .opts.App.Event "cloudwatch-event" -}}
event = {
type = "cloudwatch-event"
schedule_expression = "rate(1 minute)"
// see https://github.com/moritzzimmer/terraform-aws-lambda/tree/master/examples/with-cloudwatch-event-rules for details
cloudwatch_event_rules = {
scheduled = {
schedule_expression = "rate(1 minute)"
}

pattern = {
event_pattern = <<PATTERN
{
"detail-type": [
"AWS Console Sign In via CloudTrail"
]
}
PATTERN
}
}
{{end -}}

{{if eq .opts.App.Event "dynamodb" -}}
event = {
type = "dynamodb"
event_source_arn = "arn:aws:dynamodb:eu-west-1:647379381847:table/some-table/stream/some-identifier"
// see // see https://github.com/moritzzimmer/terraform-aws-lambda/tree/master/examples/with-event-source-mappings/dynamodb for details
event_source_mappings = {
table_1 = {
event_source_arn = aws_dynamodb_table.table_1.stream_arn
}
}
{{end -}}

{{if eq .opts.App.Event "kinesis" -}}
event = {
type = "kinesis"
event_source_arn = "arn:aws:kinesis:eu-central-1:647379381847:stream/some-stream"
// see https://github.com/moritzzimmer/terraform-aws-lambda/tree/master/examples/with-event-source-mappings/kinesis for details
event_source_mappings = {
stream_1 = {
event_source_arn = aws_kinesis_stream.stream_1.arn
}
}
{{end -}}

{{if eq .opts.App.Event "s3" -}}
// s3 events are deprecated and will be removed in the next major version of https://github.com/moritzzimmer/terraform-aws-lambda
event = {
type = "s3"
s3_bucket_arn = data.aws_s3_bucket.example.arn
Expand All @@ -52,16 +105,20 @@ module "{{.opts.App.Name}}" {
{{end -}}

{{if eq .opts.App.Event "sns" -}}
event = {
type = "sns"
topic_arn = "arn:aws:sns:eu-west-1:123456789:test-topic"
// see https://github.com/moritzzimmer/terraform-aws-lambda/tree/master/examples/with-sns-subscriptions for details
sns_subscriptions = {
topic_1 = {
topic_arn = aws_sns_topic.topic_1.arn
}
}
{{end -}}

{{if eq .opts.App.Event "sqs" -}}
event = {
type = "sqs"
event_source_arn = "arn:aws:sqs:eu-west-1:123456789:test-queue"
// see https://github.com/moritzzimmer/terraform-aws-lambda/tree/master/examples/with-event-source-mappings/sqs for details
event_source_mappings = {
queue_1 = {
event_source_arn = aws_sqs_queue.queue_1.arn
}
}
{{end -}}
}
Expand Down
6 changes: 2 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/moritzzimmer/func

go 1.13
go 1.16

require (
github.com/gobuffalo/genny v0.6.0
Expand All @@ -11,8 +11,6 @@ require (
github.com/spf13/cobra v0.0.7
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.7.1
golang.org/x/crypto v0.0.0-20200115085410-6d4e4cb37c7d // indirect
golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f
golang.org/x/sys v0.0.0-20200116001909-b77594299b42 // indirect
honnef.co/go/tools v0.1.0
honnef.co/go/tools v0.1.3
)

0 comments on commit 35617d8

Please sign in to comment.