From c4b970b6c1c654bb805c46b3cf438f773e2b8fc5 Mon Sep 17 00:00:00 2001 From: Efe Hakan Gencoglu Date: Thu, 22 Aug 2024 09:56:04 +0300 Subject: [PATCH 1/2] chore: add create new module script --- hacks/create-new-module.sh | 102 +++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100755 hacks/create-new-module.sh diff --git a/hacks/create-new-module.sh b/hacks/create-new-module.sh new file mode 100755 index 0000000..a7cd9b5 --- /dev/null +++ b/hacks/create-new-module.sh @@ -0,0 +1,102 @@ +#!/bin/bash + +# Get module name +if [ $# -ne 1 ]; then + echo "Usage: $0 " + exit 1 +fi + +MODULE_NAME="$1" + +# Validate module name +if ! [[ $MODULE_NAME =~ ^[a-zA-Z0-9-]+$ ]]; then + echo "Error: Module name can only contain lower case alphanumeric characters and dashes." + exit 1 +fi + +# Get the git repo root +REPO_ROOT=$(git rev-parse --show-toplevel) +if [ $? -ne 0 ]; then + echo "Error: Not in a git repository." + exit 1 +fi + +# Check if the module directory already exists +MODULE_PATH="$REPO_ROOT/modules/$MODULE_NAME" +if [ -d "$MODULE_PATH" ]; then + echo "Error: Module directory already exists: $MODULE_PATH" + exit 1 +fi + +# Create the directory +mkdir -p "$MODULE_PATH" +if [ $? -ne 0 ]; then + echo "Error: Failed to create directory $MODULE_PATH" + exit 1 +fi + +# Create versions.tf +cat <"$MODULE_PATH/versions.tf" +terraform { + required_version = ">= 1.0.0" +} + +# TODO: add your providers +EOF +if [ $? -ne 0 ]; then + echo "Error: Failed to create file versions.tf" + exit 1 +fi + +# Create .tflint.hcl +cat <"$MODULE_PATH/.tflint.hcl" +plugin "terraform" { + enabled = true + preset = "recommended" +} + +# TODO: setup tflint rulesets for your providers +# for example: https://github.com/terraform-linters/tflint-ruleset-aws +EOF +if [ $? -ne 0 ]; then + echo "Error: Failed to create file .tflint.hcl" + exit 1 +fi + +# Update release-please-config.json +CONFIG_FILE="$REPO_ROOT/release-please-config.json" +if [ ! -f "$CONFIG_FILE" ]; then + echo "Error: release-please-config.json not found at $CONFIG_FILE" + exit 1 +fi + +# Use jq to add the new module to the config file +jq --arg module "$MODULE_NAME" \ + '.packages += { + "modules/\($module)": { + "component": $module, + "release-type": "terraform-module", + "changelog-path": "CHANGELOG.md", + "bump-minor-pre-major": false, + "bump-patch-for-minor-pre-major": false, + "draft": false, + "prerelease": false + } + }' \ + "$CONFIG_FILE" >"$CONFIG_FILE.tmp" && + mv "$CONFIG_FILE.tmp" "$CONFIG_FILE" +if [ $? -ne 0 ]; then + echo "Error: Failed to update release-please-config.json" + exit 1 +fi + +echo "Module $MODULE_NAME created, you should create a new branch with these changes and open a pull request" +echo "\ +From the repo root: + +git switch -c new-module/$MODULE_NAME +git add modules/$MODULE_NAME +git add release-please-config.json +git commit -m \"feat: add new module $MODULE_NAME\" +git push -u +" From c422fb786b1d1cc9f8ada610de4660b17e985bc8 Mon Sep 17 00:00:00 2001 From: Efe Hakan Gencoglu Date: Thu, 22 Aug 2024 10:00:31 +0300 Subject: [PATCH 2/2] chore: update git push help snippet --- hacks/create-new-module.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hacks/create-new-module.sh b/hacks/create-new-module.sh index a7cd9b5..4a83b02 100755 --- a/hacks/create-new-module.sh +++ b/hacks/create-new-module.sh @@ -98,5 +98,5 @@ git switch -c new-module/$MODULE_NAME git add modules/$MODULE_NAME git add release-please-config.json git commit -m \"feat: add new module $MODULE_NAME\" -git push -u +git push -u origin new-module/$MODULE_NAME "