Skip to content

Commit 4cf163b

Browse files
committed
update terraform and naming
Signed-off-by: sk593 <[email protected]>
1 parent 2a73570 commit 4cf163b

File tree

16 files changed

+221
-124
lines changed

16 files changed

+221
-124
lines changed

.github/build/test.mk

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
##@ Testing
1818

1919
RESOURCE_TYPE_ROOT ?=$(shell pwd)
20+
ENVIRONMENT ?= default
21+
RECIPE_TYPE ?= all
2022

2123
.PHONY: build
2224
build: ## Build all resource types and recipes
@@ -53,8 +55,8 @@ endif
5355
@./.github/scripts/register-recipe.sh "$(RECIPE_PATH)"
5456

5557
.PHONY: register
56-
register: ## Register all built recipes
57-
@./.github/scripts/register-all-recipes.sh "$(RESOURCE_TYPE_ROOT)"
58+
register: ## Register built recipes (set ENVIRONMENT and/or RECIPE_TYPE to override defaults)
59+
@./.github/scripts/register-all-recipes.sh "$(RESOURCE_TYPE_ROOT)" "$(ENVIRONMENT)" "$(RECIPE_TYPE)"
5860

5961
.PHONY: test-recipe
6062
test-recipe: ## Test a single recipe (assumes already registered, requires RECIPE_PATH parameter)
@@ -64,8 +66,8 @@ endif
6466
@./.github/scripts/test-recipe.sh "$(RECIPE_PATH)"
6567

6668
.PHONY: test
67-
test: ## Run all recipe tests (assumes already registered)
68-
@./.github/scripts/test-all-recipes.sh "$(RESOURCE_TYPE_ROOT)"
69+
test: ## Run recipe tests (assumes already registered)
70+
@./.github/scripts/test-all-recipes.sh "$(RESOURCE_TYPE_ROOT)" "$(ENVIRONMENT)" "$(RECIPE_TYPE)"
6971

7072
.PHONY: list-resource-types
7173
list-resource-types: ## List resource type folders under the specified root

.github/scripts/list-recipe-folders.sh

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
set -euo pipefail
3232

3333
ROOT_DIR="${1:-$(pwd)}"
34+
FILTER_TYPE="${2:-all}"
35+
FILTER_TYPE="$(echo "$FILTER_TYPE" | tr '[:upper:]' '[:lower:]')"
3436

3537
if [[ ! -d "$ROOT_DIR" ]]; then
3638
echo "Error: Root directory '$ROOT_DIR' does not exist" >&2
@@ -40,26 +42,36 @@ fi
4042
# Convert ROOT_DIR to an absolute path
4143
ROOT_DIR="$(cd "$ROOT_DIR" && pwd)"
4244

43-
declare -A RECIPE_DIRS=()
45+
# Validate filter type
46+
case "$FILTER_TYPE" in
47+
all|bicep|terraform)
48+
;;
49+
*)
50+
echo "Error: Unsupported recipe type filter '$FILTER_TYPE'. Expected 'bicep', 'terraform', or 'all'." >&2
51+
exit 1
52+
;;
53+
esac
4454

45-
find_recipe_dirs() {
46-
local -a find_expression=("$@")
55+
# Use a regular array and sort/uniq instead of associative array for bash 3.x compatibility
56+
RECIPE_DIRS=()
4757

58+
# Find Bicep recipe directories (directories containing .bicep files under recipes/)
59+
if [[ "$FILTER_TYPE" == "all" || "$FILTER_TYPE" == "bicep" ]]; then
4860
while IFS= read -r -d '' matched_path; do
49-
local dir
50-
dir="$(dirname "$matched_path")"
51-
RECIPE_DIRS["$dir"]=1
52-
done < <(find "$ROOT_DIR" "${find_expression[@]}" -print0 2>/dev/null)
53-
}
54-
55-
# Collect Bicep recipe directories (directories containing .bicep files under recipes/)
56-
find_recipe_dirs -type f -path "*/recipes/*/*.bicep"
61+
RECIPE_DIRS+=("$(dirname "$matched_path")")
62+
done < <(find "$ROOT_DIR" -type f -path "*/recipes/*/*.bicep" -print0 2>/dev/null)
63+
fi
5764

58-
# Collect Terraform recipe directories (directories containing main.tf under recipes/terraform)
59-
find_recipe_dirs -type f -path "*/recipes/*/terraform/main.tf"
65+
# Find Terraform recipe directories (directories containing main.tf under recipes/terraform)
66+
if [[ "$FILTER_TYPE" == "all" || "$FILTER_TYPE" == "terraform" ]]; then
67+
while IFS= read -r -d '' matched_path; do
68+
RECIPE_DIRS+=("$(dirname "$matched_path")")
69+
done < <(find "$ROOT_DIR" -type f -path "*/recipes/*/terraform/main.tf" -print0 2>/dev/null)
70+
fi
6071

6172
if [[ ${#RECIPE_DIRS[@]} -eq 0 ]]; then
6273
exit 0
6374
fi
6475

65-
printf '%s\n' "${!RECIPE_DIRS[@]}" | sort
76+
# Remove duplicates and sort
77+
printf '%s\n' "${RECIPE_DIRS[@]}" | sort -u

.github/scripts/register-all-recipes.sh

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,40 @@
2020
# Register all Radius recipes in the repository by calling register-recipe.sh
2121
# for each discovered recipe directory. This should be run after building all
2222
# recipes but before testing them.
23+
#
24+
# Usage: ./register-all-recipes.sh [repo-root] [environment] [recipe-type]
25+
# Example: ./register-all-recipes.sh . bicep-test bicep
26+
# Example: ./register-all-recipes.sh . terraform-test terraform
2327
# =============================================================================
2428

2529
set -euo pipefail
2630

2731
REPO_ROOT="${1:-$(pwd)}"
32+
ENVIRONMENT="${2:-default}"
33+
RECIPE_TYPE="${3:-all}"
2834
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
2935

30-
echo "==> Finding all recipes in $REPO_ROOT"
36+
echo "==> Finding $RECIPE_TYPE recipes in $REPO_ROOT for environment $ENVIRONMENT"
3137

3238
# Use while read loop for better compatibility (mapfile requires bash 4+)
3339
RECIPE_DIRS=()
3440
while IFS= read -r line; do
35-
RECIPE_DIRS+=("$line")
36-
done < <("$SCRIPT_DIR"/list-recipe-folders.sh "$REPO_ROOT")
41+
# Filter by recipe type if specified
42+
if [[ "$RECIPE_TYPE" == "all" ]]; then
43+
RECIPE_DIRS+=("$line")
44+
elif [[ "$RECIPE_TYPE" == "bicep" ]] && [[ "$line" == *"/bicep" ]] && ls "$line"/*.bicep &>/dev/null; then
45+
RECIPE_DIRS+=("$line")
46+
elif [[ "$RECIPE_TYPE" == "terraform" ]] && [[ "$line" == *"/terraform" ]] && [[ -f "$line/main.tf" ]]; then
47+
RECIPE_DIRS+=("$line")
48+
fi
49+
done < <("$SCRIPT_DIR"/list-recipe-folders.sh "$REPO_ROOT" "$RECIPE_TYPE")
3750

3851
if [[ ${#RECIPE_DIRS[@]} -eq 0 ]]; then
39-
echo "==> No recipes found"
52+
echo "==> No $RECIPE_TYPE recipes found"
4053
exit 0
4154
fi
4255

43-
echo "==> Found ${#RECIPE_DIRS[@]} recipe(s) to register"
56+
echo "==> Found ${#RECIPE_DIRS[@]} $RECIPE_TYPE recipe(s) to register"
4457

4558
FAILED_RECIPES=()
4659
PASSED_RECIPES=()
@@ -54,7 +67,7 @@ for recipe_dir in "${RECIPE_DIRS[@]}"; do
5467
echo "Registering: $RELATIVE_PATH"
5568
echo "================================================"
5669

57-
if ./.github/scripts/register-recipe.sh "$recipe_dir"; then
70+
if ./.github/scripts/register-recipe.sh "$recipe_dir" "$ENVIRONMENT"; then
5871
PASSED_RECIPES+=("$RELATIVE_PATH")
5972
else
6073
FAILED_RECIPES+=("$RELATIVE_PATH")
@@ -86,4 +99,4 @@ echo ""
8699
echo "================================================"
87100
echo "Currently Registered Recipes"
88101
echo "================================================"
89-
rad recipe list --environment default || echo "Warning: Could not list registered recipes"
102+
rad recipe list --environment "$ENVIRONMENT" || echo "Warning: Could not list registered recipes"

.github/scripts/test-all-recipes.sh

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,39 @@
1919
# =============================================================================
2020
# Find and test all Radius recipes in the repository by calling test-recipe.sh
2121
# for each discovered recipe directory.
22+
#
23+
# Usage: ./test-all-recipes.sh [repo-root] [environment] [recipe-type]
24+
# Example: ./test-all-recipes.sh . bicep-env bicep
2225
# =============================================================================
2326

2427
set -euo pipefail
2528

2629
REPO_ROOT="${1:-$(pwd)}"
30+
ENVIRONMENT="${2:-default}"
31+
RECIPE_TYPE="${3:-all}"
2732
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
2833

2934
echo "==> Finding all recipes in $REPO_ROOT"
3035

31-
mapfile -t RECIPE_DIRS < <("$SCRIPT_DIR"/list-recipe-folders.sh "$REPO_ROOT")
36+
# Use while read loop for better compatibility (mapfile requires bash 4+)
37+
RECIPE_DIRS=()
38+
while IFS= read -r line; do
39+
# Filter by recipe type if specified
40+
if [[ "$RECIPE_TYPE" == "all" ]]; then
41+
RECIPE_DIRS+=("$line")
42+
elif [[ "$RECIPE_TYPE" == "bicep" ]] && [[ "$line" == *"/bicep" ]] && ls "$line"/*.bicep &>/dev/null; then
43+
RECIPE_DIRS+=("$line")
44+
elif [[ "$RECIPE_TYPE" == "terraform" ]] && [[ "$line" == *"/terraform" ]] && [[ -f "$line/main.tf" ]]; then
45+
RECIPE_DIRS+=("$line")
46+
fi
47+
done < <("$SCRIPT_DIR"/list-recipe-folders.sh "$REPO_ROOT" "$RECIPE_TYPE")
3248

3349
if [[ ${#RECIPE_DIRS[@]} -eq 0 ]]; then
34-
echo "==> No recipes found"
50+
echo "==> No $RECIPE_TYPE recipes found"
3551
exit 0
3652
fi
3753

38-
echo "==> Found ${#RECIPE_DIRS[@]} recipe(s) to test"
54+
echo "==> Found ${#RECIPE_DIRS[@]} $RECIPE_TYPE recipe(s) to test"
3955

4056
FAILED_RECIPES=()
4157
PASSED_RECIPES=()
@@ -49,7 +65,7 @@ for recipe_dir in "${RECIPE_DIRS[@]}"; do
4965
echo "Testing: $RELATIVE_PATH"
5066
echo "================================================"
5167

52-
if ./.github/scripts/test-recipe.sh "$recipe_dir"; then
68+
if ./.github/scripts/test-recipe.sh "$recipe_dir" "$ENVIRONMENT"; then
5369
PASSED_RECIPES+=("$RELATIVE_PATH")
5470
else
5571
FAILED_RECIPES+=("$RELATIVE_PATH")

.github/workflows/validate-resource-types.yaml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ jobs:
1717
validate-resource-types:
1818
runs-on: ubuntu-latest
1919
name: Validate Resource Types and Recipes
20-
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
recipe: [bicep, terraform]
24+
env:
25+
RAD_ENVIRONMENT_NAME: default
26+
2127
steps:
2228
- name: Checkout code
2329
uses: actions/checkout@v5
@@ -37,7 +43,7 @@ jobs:
3743
run: make create-radius-cluster
3844
- name: Build
3945
run: make build
40-
- name: Register
41-
run: make register
42-
- name: Test
43-
run: make test
46+
- name: Register ${{ matrix.recipe }} recipes
47+
run: make register ENVIRONMENT=$RAD_ENVIRONMENT_NAME RECIPE_TYPE=${{ matrix.recipe }}
48+
- name: Test ${{ matrix.recipe }} recipes
49+
run: make test ENVIRONMENT=$RAD_ENVIRONMENT_NAME RECIPE_TYPE=${{ matrix.recipe }}

Compute/containers/recipes/kubernetes/terraform/main.tf

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,8 @@ locals {
2323
volumes = try(local.resource_properties.volumes, {})
2424
restart_policy = try(local.resource_properties.restartPolicy, null)
2525

26-
# Connections - Extract secret connections from Radius.Security/secrets resources
26+
# Connections - used for linked resources like persistent volumes
2727
connections = try(var.context.resource.connections, {})
28-
secret_connections = {
29-
for name, conn in local.connections : name => conn
30-
if try(conn.status.computedValues.secretName, null) != null
31-
}
32-
secret_names = [for name, conn in local.secret_connections : conn.status.computedValues.secretName]
3328

3429
# Replica count - use from properties or default to 1
3530
replica_count = try(local.resource_properties.replicas, 1)
@@ -94,10 +89,17 @@ locals {
9489

9590
# Volume mounts
9691
volume_mounts = [
97-
for vm in try(config.volumeMounts, []) : {
98-
name = vm.volumeName
99-
mount_path = vm.mountPath
100-
}
92+
for vm in try(config.volumeMounts, []) : merge(
93+
{
94+
name = vm.volumeName
95+
mount_path = vm.mountPath
96+
},
97+
try(vm.subPath, null) != null ? { sub_path = vm.subPath } : {},
98+
try(vm.readOnly, null) != null ? { read_only = vm.readOnly } : {},
99+
try(vm.readOnly, null) == null && try(local.volumes[vm.volumeName].persistentVolume.accessMode, "") != "" && lower(local.volumes[vm.volumeName].persistentVolume.accessMode) == "readonlymany" ? {
100+
read_only = true
101+
} : {}
102+
)
101103
]
102104

103105
# Resources - Transform memoryInMib to memory format
@@ -150,10 +152,17 @@ locals {
150152

151153
# Volume mounts
152154
volume_mounts = [
153-
for vm in try(config.volumeMounts, []) : {
154-
name = vm.volumeName
155-
mount_path = vm.mountPath
156-
}
155+
for vm in try(config.volumeMounts, []) : merge(
156+
{
157+
name = vm.volumeName
158+
mount_path = vm.mountPath
159+
},
160+
try(vm.subPath, null) != null ? { sub_path = vm.subPath } : {},
161+
try(vm.readOnly, null) != null ? { read_only = vm.readOnly } : {},
162+
try(vm.readOnly, null) == null && try(local.volumes[vm.volumeName].persistentVolume.accessMode, "") != "" && lower(local.volumes[vm.volumeName].persistentVolume.accessMode) == "readonlymany" ? {
163+
read_only = true
164+
} : {}
165+
)
157166
]
158167

159168
# Resources - Transform memoryInMib to memory format
@@ -180,9 +189,15 @@ locals {
180189
name = vol_name
181190

182191
# Persistent Volume Claim
183-
persistent_volume_claim = try(vol_config.persistentVolume, null) != null ? {
184-
claim_name = vol_config.persistentVolume.claimName
185-
} : null
192+
persistent_volume_claim = try(vol_config.persistentVolume, null) != null ? (
193+
try(vol_config.persistentVolume.claimName, "") != "" ? {
194+
claim_name = vol_config.persistentVolume.claimName
195+
} : (
196+
try(local.connections[vol_name].status.computedValues.claimName, "") != "" ? {
197+
claim_name = local.connections[vol_name].status.computedValues.claimName
198+
} : null
199+
)
200+
) : null
186201

187202
# Secret
188203
secret = try(vol_config.secret, null) != null ? {
@@ -326,22 +341,14 @@ resource "kubernetes_deployment" "deployment" {
326341
}
327342
}
328343

329-
# Environment variables from connected secrets (Radius.Security/secrets)
330-
dynamic "env_from" {
331-
for_each = local.secret_names
332-
content {
333-
secret_ref {
334-
name = env_from.value
335-
}
336-
}
337-
}
338-
339344
# Volume mounts
340345
dynamic "volume_mount" {
341346
for_each = init_container.value.volume_mounts
342347
content {
343348
name = volume_mount.value.name
344349
mount_path = volume_mount.value.mount_path
350+
sub_path = try(volume_mount.value.sub_path, null)
351+
read_only = try(volume_mount.value.read_only, null)
345352
}
346353
}
347354

@@ -407,22 +414,14 @@ resource "kubernetes_deployment" "deployment" {
407414
}
408415
}
409416

410-
# Environment variables from connected secrets (Radius.Security/secrets)
411-
dynamic "env_from" {
412-
for_each = local.secret_names
413-
content {
414-
secret_ref {
415-
name = env_from.value
416-
}
417-
}
418-
}
419-
420417
# Volume mounts
421418
dynamic "volume_mount" {
422419
for_each = container.value.volume_mounts
423420
content {
424421
name = volume_mount.value.name
425422
mount_path = volume_mount.value.mount_path
423+
sub_path = try(volume_mount.value.sub_path, null)
424+
read_only = try(volume_mount.value.read_only, null)
426425
}
427426
}
428427

Compute/containers/test/app.bicep

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
extension radius
22
extension containers
3-
extension volumes
3+
extension persistentVolumes
44

55
param environment string
66

0 commit comments

Comments
 (0)