Skip to content

Simplify Bicep infrastructure: flat module library replacing framework pattern#61

Draft
therealjohn wants to merge 5 commits into
Azure-Samples:mainfrom
therealjohn:simple-reusable-modules
Draft

Simplify Bicep infrastructure: flat module library replacing framework pattern#61
therealjohn wants to merge 5 commits into
Azure-Samples:mainfrom
therealjohn:simple-reusable-modules

Conversation

@therealjohn
Copy link
Copy Markdown
Contributor

Problem

The Bicep infra had become a generic framework with business logic — JSON array parameters parsed at deploy-time to dynamically decide which resources to create, filter()/map() operations, deeply nested ternary outputs, dual code
paths for new vs. existing projects, and outputs for resource types the template doesn't use. ~2,877 lines across 14 files for a "basic starter."

Changes

Architecture: framework → flat module library

Replace the core/ directory tree (deeply nested, interdependent modules with a 414-line "God module") with a flat modules/ directory where each module is self-contained: creates its resource + Foundry Project connection + RBAC.

Before After
infra/core/ai/ai-project.bicep (414 lines, creates everything conditionally) infra/modules/ai-project.bicep (216 lines, AI Account + Project + monitoring + RBAC)
infra/core/ai/existing-ai-project.bicep (70 lines, duplicate output shape) Merged into ai-project.bicep — single module handles both paths
infra/core/monitor/applicationinsights-dashboard.bicep (1,236 lines!) Removed — unused dead code
14 files, ~2,877 lines 8 files, ~819 lines

Modules (pick-and-choose per template):

  • ai-project.bicep — AI Account + Project + Capability Host + Log Analytics + App Insights + RBAC + connections
  • acr.bicep — Container Registry + connection + role assignments
  • connection.bicep — Generic Foundry Project connection creator
  • storage.bicep — Storage account + connection + RBAC
  • ai-search.bicep — AI Search + knowledge container + connection + RBAC
  • bing-grounding.bicep — Bing Search + connection + RBAC

Removed:

  • abbreviations.json (137 lines) — used once, inlined
  • applicationinsights-dashboard.bicep (1,236 lines) — dead code, never invoked
  • existing-ai-project.bicep — merged into ai-project.bicep
  • acr-role-assignment.bicep — inlined into acr.bicep
  • bing_custom_grounding.bicep — no current samples use it
  • dependentResourcesType and JSON array resource discovery pattern
  • enableHostedAgents, enableCapabilityHost, enableMonitoring toggle flags
  • @allowed location list (25 entries) — handled by azd extension via azure-dev#7930

Output variable renames to match platform-injected environment variables:

  • AZURE_AI_PROJECT_ENDPOINTFOUNDRY_PROJECT_ENDPOINT
  • AZURE_AI_PROJECT_ID / AZURE_AI_FOUNDRY_PROJECT_IDFOUNDRY_PROJECT_ARM_ID
  • APPLICATIONINSIGHTS_CONNECTION_STRING — already matches, unchanged

CI: Bicep validation workflow (.github/workflows/bicep-validate.yml)

  • Layer 1bicep lint + bicep build on all files (no Azure creds needed)
  • Layer 2az deployment sub validate against 4 scenario parameter files
  • Layer 3az deployment sub what-if preview for each scenario

Test scenarios:

Scenario Code paths exercised
new-project New account + project + ACR (default)
new-project-with-model Above + model deployment array
existing-project Existing project + existing ACR connection (skip creation)
existing-project-new-acr Existing project + new ACR creation

Summary

27 files changed, 949 insertions(+), 2,877 deletions(-)

Metric Before After
Files (basic template) 14 5
Lines (basic template) ~2,877 ~521
main.parameters.json params 21 15
Ternary outputs in main.bicep 18 2
JSON array parsing for resources 4 vars 0

- Remove storage.bicep and integrate storage logic into new modules.
- Update main.bicep to streamline resource group and AI project creation.
- Introduce new modules for ACR, AI project, AI search, and Bing grounding.
- Enhance connection management with a dedicated connection module.
- Adjust parameters and outputs for better clarity and usability.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant