Your goal
Create a typed, validated interface for the sandbox and return the managed identity's resource ID, client ID, and principal ID as outputs.
Exercise 6 ยท 45 minutes
Replace embedded environment values with a clear configuration interface, query the assigned resource group, and expose identifiers that another module could consume.
Before you start
Create a typed, validated interface for the sandbox and return the managed identity's resource ID, client ID, and principal ID as outputs.
Participant task
List values that vary by participant or environment. Separate genuine inputs from values Terraform can derive.
Add variables for the subscription ID, resource-group name, naming prefix, environment, and required tags. Add descriptions, types, and validation for constrained values. Do not place environment values in defaults.
Use an azurerm_resource_group data source to obtain the resource group's location. Use locals to assemble the identity name and merged tags without repeating expressions.
Expose the managed identity's resource ID, client ID, and principal ID. Decide whether each output is sensitive and be prepared to justify the decision.
Test one invalid environment value, then restore the approved value. Format, validate, save a plan, and confirm that parameterization does not unexpectedly replace the identity.
terraform fmt
terraform validate
terraform plan -out main.tfplan
terraform apply main.tfplan
terraform outputExpected outcome
Replace separate tagging variables with a typed object and validation that requires the standard tag keys.
Finish
Commit the interface changes. Keep the identity and current state for the backend migration in Exercise 8.