domains / cloud-infra / Azure/azure-cli
Configuration Contract Enforcement
When behavior depends on configuration (files/flags/subscriptions), do three things: (1) derive values from the active runtime context (including any overrides), (2) gate feature behavior on validated completeness of required config inputs, and (3) eliminate hidden defaults/implicit selections.
When behavior depends on configuration (files/flags/subscriptions), do three things: (1) derive values from the active runtime context (including any overrides), (2) gate feature behavior on validated completeness of required config inputs, and (3) eliminate hidden defaults/implicit selections.
Apply as follows:
- Config paths/files: never build config locations from global constants if
config_dircan be overridden. Use the resolved runtimeconfig_dirfrom the CLI context. - Feature flags / multi-flag options: if enabling a mode requires multiple inputs (e.g., a “BYO trio”), only set
enabled=truewhen all required inputs are present and validation has been run; reject/avoid partial configurations. - Explicit configuration: when creating clients/resources, pass required scoping explicitly (e.g., subscription id) rather than relying on implicit/default selection.
- Avoid brittle CLI side effects: only remove/override defaults that the CLI itself synthesized; preserve user-provided configuration.
Example pattern (flag gating):
# after validate_byo_trio completeness
system_node_subnet_id = ctx.get_system_node_subnet_id()
node_subnet_id = ctx.get_node_subnet_id()
enable_mode = ctx.get_enable_hosted_system() # true only when full trio is present
if enable_mode:
mc.hosted_system_profile.enabled = True
mc.hosted_system_profile.system_node_subnet_id = system_node_subnet_id
mc.hosted_system_profile.node_subnet_id = node_subnet_id