Skip to content

Commit f33da60

Browse files
feat: Add luthername max_length + modernize CI (#57)
* feat: Add max_length support to luthername (#56) When downstream modules append suffixes (e.g., -exec, -role), names can exceed AWS service limits. Add an optional max_length variable that truncates the prefix while preserving the ID suffix for uniqueness. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: Modernize CI workflow following insideout-terraform-presets patterns - Dynamic module/example discovery with matrix strategy for parallel validation - Upgrade from hashicorp/terraform:1.5.7 container to hashicorp/setup-terraform@v3 (1.7.5) - Update actions/checkout v3 → v4 - Add push-to-main trigger alongside pull request trigger - Separate jobs for modules, examples, format check, and terraform tests - Use -backend=false for init to avoid backend configuration issues - Support .validate-skip and .tftest.hcl patterns from insideout-terraform-presets Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: Fix CI failures from workflow modernization - Skip modules with tests/ dirs from validate-modules (they use provider aliases that can't validate standalone, matching old validate.sh behavior) - Remove validate-examples job (examples use SSH git sources unavailable in CI, matching old validate.sh which excluded examples) - Fix pre-existing formatting in config.tfvars (now caught by -recursive flag) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 6c019af commit f33da60

File tree

6 files changed

+137
-22
lines changed

6 files changed

+137
-22
lines changed

.github/workflows/main.yml

Lines changed: 89 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,97 @@
11
name: Terraform CI
22

33
on:
4+
push:
5+
branches: [main]
46
pull_request:
5-
branches: ["main"]
7+
branches: [main]
68

79
jobs:
8-
check_format_and_validate:
10+
discover:
911
runs-on: ubuntu-latest
10-
container:
11-
image: hashicorp/terraform:1.5.7
12-
env:
13-
TF_PLUGIN_CACHE_DIR: /github/home/.terraform.d/plugin-cache
12+
outputs:
13+
modules: ${{ steps.find-modules.outputs.dirs }}
14+
modules_with_tests: ${{ steps.find-testable.outputs.dirs }}
1415
steps:
15-
- name: Checkout
16-
uses: actions/checkout@v3
17-
- name: Create Plugin Cache Dir
18-
run: mkdir -p $TF_PLUGIN_CACHE_DIR
19-
- name: Check format
20-
run: terraform fmt -diff=true -check=true
21-
- name: Validate
22-
run: ./validate.sh
16+
- uses: actions/checkout@v4
17+
18+
- id: find-modules
19+
name: Discover modules
20+
run: |
21+
dirs=$(find . -maxdepth 1 -type d ! -name '.*' | sed 's|^\./||' | sort | while read -r d; do
22+
if ls "$d"/*.tf >/dev/null 2>&1; then
23+
# Skip modules with .validate-skip or tests/ (tests handle their own validation)
24+
[ -f "$d/.validate-skip" ] && continue
25+
[ -d "$d/tests" ] && continue
26+
echo "$d"
27+
fi
28+
done | jq -R -s -c 'split("\n") | map(select(length > 0))')
29+
echo "dirs=$dirs" >> "$GITHUB_OUTPUT"
30+
31+
- id: find-testable
32+
name: Discover modules with terraform tests
33+
run: |
34+
dirs=$(find . -maxdepth 1 -type d ! -name '.*' | sed 's|^\./||' | sort | while read -r d; do
35+
if ls "$d"/tests/*.tftest.hcl >/dev/null 2>&1 || ls "$d"/*.tftest.hcl >/dev/null 2>&1; then
36+
echo "$d"
37+
fi
38+
done | jq -R -s -c 'split("\n") | map(select(length > 0))')
39+
echo "dirs=$dirs" >> "$GITHUB_OUTPUT"
40+
41+
validate-modules:
42+
needs: discover
43+
if: ${{ needs.discover.outputs.modules != '[]' }}
44+
runs-on: ubuntu-latest
45+
strategy:
46+
fail-fast: false
47+
matrix:
48+
dir: ${{ fromJson(needs.discover.outputs.modules) }}
49+
steps:
50+
- uses: actions/checkout@v4
51+
52+
- uses: hashicorp/setup-terraform@v3
53+
with:
54+
terraform_version: "1.7.5"
55+
56+
- name: Terraform Init
57+
run: terraform init -backend=false -input=false
58+
working-directory: ${{ matrix.dir }}
59+
60+
- name: Terraform Validate
61+
run: terraform validate
62+
working-directory: ${{ matrix.dir }}
63+
64+
test-modules:
65+
needs: discover
66+
if: ${{ needs.discover.outputs.modules_with_tests != '[]' }}
67+
runs-on: ubuntu-latest
68+
strategy:
69+
fail-fast: false
70+
matrix:
71+
dir: ${{ fromJson(needs.discover.outputs.modules_with_tests) }}
72+
steps:
73+
- uses: actions/checkout@v4
74+
75+
- uses: hashicorp/setup-terraform@v3
76+
with:
77+
terraform_version: "1.7.5"
78+
79+
- name: Terraform Init
80+
run: terraform init -backend=false -input=false
81+
working-directory: ${{ matrix.dir }}
82+
83+
- name: Terraform Test
84+
run: terraform test -no-color
85+
working-directory: ${{ matrix.dir }}
86+
87+
format-check:
88+
runs-on: ubuntu-latest
89+
steps:
90+
- uses: actions/checkout@v4
91+
92+
- uses: hashicorp/setup-terraform@v3
93+
with:
94+
terraform_version: "1.7.5"
95+
96+
- name: Terraform Format Check
97+
run: terraform fmt -check -recursive
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
luther_project = "tst"
2-
luther_project_name = "testp"
1+
luther_project = "tst"
2+
luther_project_name = "testp"
33
luther_project_human = "Test Project"
4-
luther_env = "test"
5-
org_name = "testo"
6-
org_human = "Test Organization"
4+
luther_env = "test"
5+
org_name = "testo"
6+
org_human = "Test Organization"
77

88
aws_region = "eu-west-2"
99

10-
callback_url = "https://test.luthersystemsapp.com/callback"
10+
callback_url = "https://test.luthersystemsapp.com/callback"
1111
default_redirect_uri = "https://test.luthersystemsapp.com/callback"

luthername/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
11
# Uniquely Identifying Names
22

33
Luther Style!
4+
5+
## Variables
6+
7+
### `max_length`
8+
9+
Optional. Maximum length for generated names. Default is `0` (no limit).
10+
11+
When set, the prefix portion of the name is truncated to fit within the limit
12+
while always preserving the ID suffix for uniqueness. This is useful when
13+
downstream modules append suffixes (e.g., `-exec`, `-role`) and the combined
14+
name must stay within AWS service limits (64-char IAM roles, 50-char backup
15+
rules, etc.).

luthername/data.tf

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,14 @@ locals {
1212
var.resource,
1313
]))
1414

15-
ids = [for i in range(var.replication) : "${var.subcomponent}${var.id == "" ? i : var.id}"]
16-
names = [for i in range(var.replication) : "${local.prefix}${var.delim}${local.ids[i]}"]
15+
ids = [for i in range(var.replication) : "${var.subcomponent}${var.id == "" ? i : var.id}"]
16+
raw_names = [for i in range(var.replication) : "${local.prefix}${var.delim}${local.ids[i]}"]
17+
18+
names = [for i in range(var.replication) :
19+
var.max_length > 0 && length(local.raw_names[i]) > var.max_length
20+
? "${substr(local.prefix, 0, max(0, var.max_length - length(local.ids[i]) - length(var.delim)))}${var.delim}${local.ids[i]}"
21+
: local.raw_names[i]
22+
]
1723

1824
id = var.replication == 1 ? local.ids[0] : null
1925
name = var.replication == 1 ? local.names[0] : null

luthername/examples/simple-luthername/main.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,14 @@ module "luthername" {
77
component = "infra"
88
resource = "tf"
99
}
10+
11+
module "luthername_short" {
12+
source = "git::ssh://git@bitbucket.org/luthersystems/tf-modules.git//luthername?ref=master"
13+
luther_project = "terraform-test"
14+
aws_region = "eu-west-2"
15+
luther_env = "dev"
16+
org_name = "luther"
17+
component = "infra"
18+
resource = "tf"
19+
max_length = 40
20+
}

luthername/variables.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,14 @@ variable "delim" {
5050
type = string
5151
default = "-"
5252
}
53+
54+
variable "max_length" {
55+
type = number
56+
default = 0
57+
description = "Maximum length for generated names. 0 means no limit. When set, the prefix is truncated to fit within the limit while preserving the ID suffix for uniqueness."
58+
59+
validation {
60+
condition = var.max_length >= 0
61+
error_message = "max_length must be non-negative."
62+
}
63+
}

0 commit comments

Comments
 (0)