Skip to content

Commit

Permalink
Merge pull request #5 from pbs/chore/template_update
Browse files Browse the repository at this point in the history
Template Updates
  • Loading branch information
yhakbar authored Jan 17, 2023
2 parents dc2f851 + 72026a4 commit 62c0dfa
Show file tree
Hide file tree
Showing 17 changed files with 1,567 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .tflint.hcl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugin "aws" {
enabled = true
version = "0.14.0"
version = "0.17.1"
source = "github.com/terraform-linters/tflint-ruleset-aws"
}

Expand Down
8 changes: 4 additions & 4 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
terraform 1.2.4
golang 1.18.3
terraform 1.3.2
golang 1.18.5
ripgrep 13.0.0
tflint 0.38.1
github-cli 2.13.0
tflint 0.41.0
github-cli 2.14.4
fd 8.4.0
terraform-docs 0.16.0
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Use this URL for the source of the module. See the usage examples below for more details.

```hcl
github.com/pbs/terraform-aws-lambda-cron-module?ref=0.1.1
github.com/pbs/terraform-aws-lambda-cron-module?ref=x.y.z
```

### Alternative Installation Methods
Expand All @@ -22,7 +22,7 @@ Integrate this module like so:

```hcl
module "lambda-cron" {
source = "github.com/pbs/terraform-aws-lambda-cron-module?ref=0.1.1"
source = "github.com/pbs/terraform-aws-lambda-cron-module?ref=x.y.z"
# Required Parameters
handler = "main"
Expand All @@ -44,7 +44,7 @@ module "lambda-cron" {

If this repo is added as a subtree, then the version of the module should be close to the version shown here:

`0.1.1`
`x.y.z`

Note, however that subtrees can be altered as desired within repositories.

Expand All @@ -60,7 +60,7 @@ Below is automatically generated documentation on this Terraform module using [t

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.1.7 |
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3.2 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.5.0 |

## Providers
Expand All @@ -82,6 +82,7 @@ Below is automatically generated documentation on this Terraform module using [t
| [aws_cloudwatch_event_rule.event_rule](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_event_rule) | resource |
| [aws_cloudwatch_event_target.event_target](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_event_target) | resource |
| [aws_lambda_permission.allow_event_invocation](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_permission) | resource |
| [aws_default_tags.common_tags](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/default_tags) | data source |

## Inputs

Expand Down
2 changes: 1 addition & 1 deletion examples/arm/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module "lambda_cron" {
source = "../.."

handler = "main"
filename = "../artifacts/handler.zip"
filename = "../artifacts/arm-handler.zip"
runtime = "go1.x"

architectures = ["arm64"]
Expand Down
12 changes: 12 additions & 0 deletions examples/basic/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion go.work
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
go 1.18

use ./tests
use (
./examples/src
./tests
)
6 changes: 5 additions & 1 deletion locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ locals {

creator = "terraform"

tags = merge(
defaulted_tags = merge(
var.tags,
{
Name = local.name
Expand All @@ -18,4 +18,8 @@ locals {
repo = var.repo
}
)

tags = merge({ for k, v in local.defaulted_tags : k => v if lookup(data.aws_default_tags.common_tags.tags, k, "") != v })
}

data "aws_default_tags" "common_tags" {}
4 changes: 2 additions & 2 deletions scripts/document.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -euo pipefail
IFS=$'\n\t'

GIT_ROOT=$(git rev-parse --show-toplevel)
pushd "$GIT_ROOT" > /dev/null || exit 1
if terraform-docs markdown --header-from README-HEADER.md . > README.md; then
pushd "$GIT_ROOT" >/dev/null || exit 1
if terraform-docs markdown --header-from README-HEADER.md . >README.md; then
git add README.md
fi
2 changes: 1 addition & 1 deletion scripts/format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ set -euo pipefail
IFS=$'\n\t'

GIT_ROOT=$(git rev-parse --show-toplevel)
pushd "$GIT_ROOT" > /dev/null || exit 1
pushd "$GIT_ROOT" >/dev/null || exit 1
export AWS_DEFAULT_REGION='us-east-1'
terraform fmt -recursive
16 changes: 16 additions & 0 deletions scripts/package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

# Unofficial bash strict mode: http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -euo pipefail
IFS=$'\n\t'

GIT_ROOT=$(git rev-parse --show-toplevel)

mkdir -p "$GIT_ROOT"/examples/artifacts
pushd "$GIT_ROOT"/examples/src >/dev/null

GOOS=linux GOARCH=amd64 go build -o "$GIT_ROOT"/examples/artifacts/main
zip -j "$GIT_ROOT"/examples/artifacts/handler.zip "$GIT_ROOT"/examples/artifacts/main

GOOS=linux GOARCH=arm64 go build -o "$GIT_ROOT"/examples/artifacts/main
zip -j "$GIT_ROOT"/examples/artifacts/arm-handler.zip "$GIT_ROOT"/examples/artifacts/main
5 changes: 2 additions & 3 deletions scripts/setup-hooks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
set -euo pipefail
IFS=$'\n\t'


GIT_ROOT=$(git rev-parse --show-toplevel)

create_general_hooks() {
cat <<'EOF' >> "$GIT_ROOT"/.git/hooks/pre-commit
cat <<'EOF' >>"$GIT_ROOT"/.git/hooks/pre-commit
# terraform-aws-template-hooks
GIT_ROOT=$(git rev-parse --show-toplevel)
"$GIT_ROOT"/scripts/validate.sh
Expand All @@ -18,7 +17,7 @@ EOF
}

add_non_template_hook() {
echo '"$GIT_ROOT"/scripts/document.sh' >> "$GIT_ROOT"/.git/hooks/pre-commit
echo '"$GIT_ROOT"/scripts/document.sh' >>"$GIT_ROOT"/.git/hooks/pre-commit
}

get_mod_name() {
Expand Down
5 changes: 4 additions & 1 deletion scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ set -euo pipefail
IFS=$'\n\t'

GIT_ROOT=$(git rev-parse --show-toplevel)
pushd "$GIT_ROOT"/tests > /dev/null || exit 1

"$GIT_ROOT"/scripts/package.sh

pushd "$GIT_ROOT"/tests >/dev/null
go test -timeout 30m -count=1 -parallel 10 ./...
8 changes: 4 additions & 4 deletions scripts/todo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ set -euo pipefail
IFS=$'\n\t'

GIT_ROOT=$(git rev-parse --show-toplevel)
pushd "$GIT_ROOT" > /dev/null || exit 1
pushd "$GIT_ROOT" >/dev/null || exit 1

todo_check () {
todo_check() {
grep \
-I \
-r 'TODO' \
Expand All @@ -18,6 +18,6 @@ todo_check () {
}

if todo_check; then
echo 'Please address TODOs before merging into main.'
exit 1
echo 'Please address TODOs before merging into main.'
exit 1
fi
2 changes: 1 addition & 1 deletion scripts/validate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -euo pipefail
IFS=$'\n\t'

GIT_ROOT=$(git rev-parse --show-toplevel)
pushd "$GIT_ROOT" > /dev/null
pushd "$GIT_ROOT" >/dev/null
export AWS_DEFAULT_REGION='us-east-1'
terraform init -backend=false
terraform validate
Expand Down
6 changes: 3 additions & 3 deletions scripts/wizard.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ declare -A REPLACEMENT_KEYS=(
["MOD_SHORTNAME"]="$MOD_SHORTNAME"
)

pushd "$GIT_ROOT" > /dev/null
pushd "$GIT_ROOT" >/dev/null
BOILERPLATE_FILES=$(fd -tf -E wizard.sh -c never .)

for BOILERPLATE_FILE in $BOILERPLATE_FILES; do
for REPLACEMENT_KEY in "${!REPLACEMENT_KEYS[@]}"; do
if command -v sd > /dev/null; then
if command -v sd >/dev/null; then
sd "$REPLACEMENT_KEY" "${REPLACEMENT_KEYS[$REPLACEMENT_KEY]}" "$BOILERPLATE_FILE"
else
tmp="$(mktemp)"
sed "s/$REPLACEMENT_KEY/${REPLACEMENT_KEYS[$REPLACEMENT_KEY]}/g" "$BOILERPLATE_FILE" > "$tmp"
sed "s/$REPLACEMENT_KEY/${REPLACEMENT_KEYS[$REPLACEMENT_KEY]}/g" "$BOILERPLATE_FILE" >"$tmp"
mv "$tmp" "$BOILERPLATE_FILE"
fi
done
Expand Down
2 changes: 1 addition & 1 deletion terraform.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
terraform {
required_version = ">= 1.1.7"
required_version = ">= 1.3.2"
required_providers {
# tflint-ignore: terraform_unused_required_providers
aws = {
Expand Down
Loading

0 comments on commit 62c0dfa

Please sign in to comment.