AZ-400 Infrastructure as Code 4 — Questions and Answers
Question 1: What is the purpose of Terraform's `lifecycle` block with `prevent_destroy = true`?
- Prevents the resource from being updated in-place
- Causes Terraform to throw an error if a plan would destroy the resource (Correct answer)
- Ignores changes to the resource after initial creation
- Prevents concurrent applies from modifying the resource
Correct answer: Causes Terraform to throw an error if a plan would destroy the resource
`prevent_destroy = true` makes Terraform fail with an error if any plan includes destruction of that resource, acting as a safety guard for critical infrastructure.
Question 2: In Azure Bicep, how do you reference an output from a deployed module within the same Bicep file?
- Using `reference(moduleName).outputs.outputName`
- Using `moduleName.outputs.outputName` (Correct answer)
- Using `output(moduleName, 'outputName')`
- Using `parameters('moduleName').outputName`
Correct answer: Using `moduleName.outputs.outputName`
After deploying a module with a symbolic name, you access its outputs using the dot notation `moduleName.outputs.outputName`.
Question 3: Which Azure service provides a centralized registry for sharing and versioning private Bicep modules across an organization?
- Azure Artifacts
- Azure Container Registry (ACR) (Correct answer)
- Azure Key Vault
- GitHub Packages
Correct answer: Azure Container Registry (ACR)
Azure Container Registry supports Bicep module registries, allowing teams to publish and consume versioned private modules using `br:` references.
Question 4: What happens when you run `terraform apply` and the actual Azure resource state differs from the Terraform state file (state drift)?
- Terraform errors out and requires manual state file correction
- Terraform detects the drift, shows the differences in the plan, and corrects it on apply (Correct answer)
- Terraform ignores drift and only processes explicit configuration changes
- Terraform automatically runs `terraform refresh` and aborts if drift is found
Correct answer: Terraform detects the drift, shows the differences in the plan, and corrects it on apply
Terraform refreshes the state before planning, detects any drift between real infrastructure and the state file, and includes corrections in the apply plan.
Question 5: In an Azure Pipelines YAML file, what is the effect of setting `condition: always()` on a pipeline step?
- The step runs even if previous steps failed or were cancelled (Correct answer)
- The step runs only when all previous steps succeeded
- The step runs in a separate parallel job
- The step is skipped unless explicitly triggered by a manual approval
Correct answer: The step runs even if previous steps failed or were cancelled
`condition: always()` causes the step to execute regardless of whether previous steps succeeded, failed, or were cancelled—useful for cleanup steps.
Question 6: When using Azure Policy with IaC deployments, what is the `DeployIfNotExists` effect used for?
- Blocking deployments that violate policy
- Automatically remediating non-compliant resources by deploying required configurations (Correct answer)
- Auditing resources without making any changes
- Denying creation of resources missing required tags
Correct answer: Automatically remediating non-compliant resources by deploying required configurations
`DeployIfNotExists` triggers a remediation deployment to bring non-compliant resources into compliance by deploying required child resources or configurations.
Question 7: What is the purpose of the `templateLink` property in an ARM template's linked template deployment?
- Links a parameter file to the main template
- Specifies a URI to an external ARM template to deploy as a nested resource (Correct answer)
- References an Azure Blueprints definition for the deployment
- Provides a link to the Azure documentation for the resource type
Correct answer: Specifies a URI to an external ARM template to deploy as a nested resource
`templateLink` specifies the URI of an external ARM template (typically in Azure Blob Storage or GitHub) to be deployed as part of a modular linked template pattern.
What is the purpose of Terraform's `lifecycle` block with `prevent_destroy = true`?