Infrastructure as Code: Terraform and Bicep Interview Questions
261 multiple-choice tech interview questions on Infrastructure as Code: Terraform and Bicep: declarative vs imperative, Terraform language and state, modules and providers, Bicep and ARM, policy scanning, pipelines, Pulumi and Ansible. Written for technical phone screens and interview prep, organized by subtopic, with a short explanation for every answer. Learn the 239 key terms with the flashcards first, then test yourself.
Take the practice test · Flashcards · All study tools
What it covers
- 8.1 IaC concepts and tool landscape
- 8.2 Terraform language essentials
- 8.3 Terraform state and workflow
- 8.4 Terraform modules and providers
- 8.5 Bicep language
- 8.6 ARM deployments, scopes and stacks
- 8.7 Testing, policy and security scanning
- 8.8 Pipelines, environments and secrets
- 8.9 Pulumi, Ansible and other tools
Key terms
8.1 IaC concepts and tool landscape
- Infrastructure as code
- Managing infrastructure through version-controlled definition files
- Declarative
- Describing the desired end state rather than the steps
- Drift
- Differences between deployed infrastructure and its code
- Immutable properties
- Settings that can't change in place
- Pets vs cattle
- Hand-cared servers versus disposable ones
- Push vs pull
- Who initiates configuration changes
- Reconciliation
- Constantly converging to desired state
- ClickOps
- Manual portal-driven changes
- Bicep vs Terraform
- Azure-native versus multi-provider IaC
- Dependency graph
- Order derived from references between resources
- Blast radius
- How much one change can break
- Lifecycle layering
- Grouping resources by change frequency
- Day 0/1/2
- Design, build and operate phases
- Greenfield vs brownfield
- New versus existing infrastructure
- Packer
- Tool for building machine images as code
- Self-service platforms
- Paved paths built from IaC templates
- Shared ownership
- Two systems managing one setting
- Drift remediation
- Codify or revert manual changes
- Declarative limits
- Weakness with procedural tasks
- DSL vs general language
- HCL/Bicep versus TypeScript, Python, etc.
- aztfexport
- Exporting Azure resources to Terraform
- IaC repo layout
- Where infrastructure code lives
- Living documentation
- Code as the record of infrastructure
- Unique naming
- Avoiding global name clashes
- Single owner
- One stack per resource
- Infra rollback
- Limits of reverting infrastructure
- Imperative scripts
- CLI scripts that create resources
8.2 Terraform language essentials
- Resource address
- type.name used to reference a resource
- Input variables
- Parameters for a configuration
- Variable precedence
- Order in which variable values override
- Variable validation
- Custom rules for input values
- sensitive
- Hiding values in CLI output
- Outputs
- Values exported by a configuration
- Locals
- Named values computed inside a module
- Data sources
- Read-only lookups of existing objects
- depends_on
- Explicit dependency between resources
- count index shift
- Removing list items renumbers instances
- dynamic blocks
- Generating nested blocks with for_each
- Conditional expression
- condition ? true_val : false_val
- for expressions
- Transforming collections in HCL
- Splat expression
- [*] to collect an attribute from many instances
- templatefile
- Rendering a template file with values
- prevent_destroy
- Guarding a resource against deletion by Terraform
- create_before_destroy
- Creating the replacement first
- ignore_changes
- Letting other systems own an attribute
- replace_triggered_by
- Forcing replacement tied to other changes
- moved block
- Refactoring addresses without replacement
- Ephemeral values
- Values never saved to plan or state
- for_each types
- Maps and sets for for_each
- null arguments
- Omitting an argument conditionally
- try()
- Fallbacks for expressions that may fail
- each object
- Key and value in for_each
- jsonencode
- Converting HCL values to JSON
- Provisioners
- Running scripts from Terraform
- terraform_data
- Built-in resource for triggers and values
8.3 Terraform state and workflow
- Terraform state
- File mapping configuration to real resources
- Provider
- Terraform plugin that manages one platform's API
- Module
- Reusable, parameterized group of IaC resources
- terraform init
- Preparing a working directory
- fmt and validate
- Style formatting and static checks
- fmt -check
- Formatting gate in CI
- Saved plans
- Applying a reviewed plan file
- Plan symbols
- +, -, ~ and -/+ in plans
- Forces replacement
- Changes that require recreating a resource
- state rm
- Forgetting a resource without destroying it
- removed block
- Declarative state removal
- -replace
- Forcing replacement of one resource
- -target
- Planning only selected resources
- refresh-only
- Updating state to match reality
- Workspaces
- Multiple states for one configuration
- force-unlock
- Releasing a stuck state lock
- Partial backend config
- Supplying backend settings at init
- S3 native locking
- Lock files in the state bucket
- terraform_remote_state
- Reading another config's outputs from its state
- State protection
- Versioning and access controls for state
- terraform console
- Interactive expression evaluation
- TF_LOG
- Debug logging for Terraform
- detailed-exitcode
- Plan exit codes for automation
- Stale plan
- Saved plan no longer matching state
- Generated import config
- Auto-writing HCL for imports
8.4 Terraform modules and providers
- required_providers
- Declaring provider sources and versions
- Pessimistic constraint
- ~> allows only the rightmost part to grow
- Dependency lock file
- Exact provider versions and checksums
- init -upgrade
- Updating providers within constraints
- Provider aliases
- Multiple configurations of one provider
- Passing providers
- Handing provider configs to modules
- Module sources
- Registry, Git and local paths
- Git ref pinning
- Locking a module to a tag or commit
- Module outputs
- Reading values from a child module
- Root module
- Top-level configuration directory
- Module composition
- Combining modules at the root
- Azure Verified Modules
- Official, standardized IaC modules for Azure
- Private registry
- Internal catalog of approved modules
- Module for_each
- Repeating whole modules
- azapi
- Thin provider over ARM REST APIs
- required_version
- Minimum Terraform CLI version
- azurerm features
- Required provider block for azurerm
- Provider functions
- Extra functions from providers
- Thin wrapper modules
- Pass-through modules with no added value
- terraform-docs
- Generating module documentation
- OpenTofu state encryption
- Encrypting state on the client
- OpenTofu compatibility
- Using existing providers and configs
- Module refactoring
- Using moved blocks inside modules
- Provider upgrades
- Handling breaking provider changes
- Providers in modules
- Keep provider config at the root
- Plugin cache
- Shared provider download cache
8.5 Bicep language
- @allowed
- Restricting a parameter to listed values
- @secure
- Marking parameters as secret
- Decorators
- Metadata and validation on Bicep declarations
- param vs var
- Inputs versus internal values
- Bicep outputs
- Values returned from a deployment
- Symbolic names
- Referring to Bicep resources in code
- existing
- Referencing already deployed resources
- parent property
- Declaring child resources
- Module scope
- Deploying a module elsewhere
- Bicep loops
- for expressions to repeat resources
- Conditional deployment
- Deploying resources based on a condition
- resourceGroup()
- Function returning the target group
- uniqueString
- Deterministic hash for names
- API versions
- Versioned resource schemas in ARM
- Bicep linter
- Static checks for Bicep
- bicep build
- Compiling Bicep to ARM JSON
- Secret outputs
- Linter rule against secrets in outputs
- User-defined types
- Custom types in Bicep
- Bicep registry
- Modules from a container registry
- targetScope
- Deployment scope of a Bicep file
- Implicit dependencies
- Ordering from references in Bicep
- getSecret
- Pulling Key Vault secrets at deployment
- Compile-time imports
- Sharing types and variables across Bicep files
- Safe dereference
- .? and ?? operators
- @batchSize
- Limiting parallelism in Bicep loops
- Lambda functions
- filter, map and more in Bicep
8.6 ARM deployments, scopes and stacks
- Bicep
- Azure-native IaC language that compiles to ARM templates
- What-if
- Azure preview of the changes a deployment would make
- Deployment scopes
- Resource group, subscription, management group, tenant
- az deployment group create
- Deploying a template to a resource group
- Deployment history
- Records of past ARM deployments
- Deployment names
- Naming ARM deployments
- Validate
- Pre-flight validation of a deployment
- What-if noise
- False positives in previews
- Incremental gotcha
- Resources' properties are fully re-sent
- Complete mode alternative
- Stacks for managed deletion
- actionOnUnmanage
- What a stack does with dropped resources
- Stack deny settings
- Protecting stack resources from outside changes
- Subscription stacks
- Stacks managing several resource groups
- ARM template structure
- Sections of an ARM template
- Nested deployments
- How modules execute in ARM
- ARM expressions
- Bracketed template functions
- confirm-with-what-if
- Preview then prompt before deploying
- Export template
- Generating ARM from deployed resources
- PowerShell deployments
- Az PowerShell deployment cmdlets
- Deployment location
- Where deployment metadata lives
- Locks vs deny settings
- Two ways to protect resources
- copy loops
- Iteration in ARM JSON
- ARM dependsOn
- Explicit dependencies in JSON templates
- What-if change types
- Categories in what-if output
- Reading outputs
- Querying deployment outputs via CLI
- Deployment scripts
- Script steps inside ARM deployments
- Rollback on error
- Falling back to the last good deployment
8.7 Testing, policy and security scanning
- terraform test
- Native testing framework for Terraform
- Plan-only tests
- Fast tests that don't create resources
- Mock providers
- Fake providers for Terraform tests
- Terratest
- Go library for integration-testing IaC
- Layered IaC testing
- Static checks first, real deployments later
- TFLint
- Pluggable linter for Terraform
- Pre/postconditions
- Custom assertions on resources and outputs
- check blocks
- Non-blocking assertions
- Conftest
- OPA policies against config files
- Plan-based policy
- Checking resolved planned values
- Sentinel
- HashiCorp policy-as-code language
- Enforcement levels
- Advisory, soft and hard mandatory
- Scanner suppressions
- Documented exceptions to findings
- arm-ttk
- Static tests for ARM templates
- Shift-left policy
- Checking rules before deployment
- Module examples
- Runnable usage samples
- Test cleanup
- Always destroying test infrastructure
- Destructive change gate
- Extra approval for deletions
- Open management ports
- SSH or RDP open to the internet
- pre-commit hooks
- Local checks before commit
- Idempotency test
- Second plan should be empty
- Module allow-lists
- Restricting module sources
- expect_failures
- Testing that checks fail as expected
- Unknown values
- Values only known after creation
- CODEOWNERS
- Required reviewers by path
- Custom scanner rules
- Org-specific checks in Checkov
- Test accounts
- Isolated cloud space for IaC tests
- Severity thresholds
- Gradual adoption of scanning
8.8 Pipelines, environments and secrets
- OIDC federation
- Short-lived, secretless authentication from a CI system to a cloud
- Plan-on-PR
- Plan in review, apply after merge
- Plan comments
- Showing plans in pull requests
- Atlantis
- PR-driven Terraform automation
- VCS-driven runs
- Remote runs triggered by Git
- Split identities
- Read-only plan, write apply
- Plan artifacts
- Plan files may hold secrets
- Serialized applies
- One run per state at a time
- azurerm OIDC
- Provider settings for federated login
- Federated subjects
- Matching OIDC claims to credentials
- TACOS
- Platforms that run and govern IaC
- Break-glass changes
- Emergency manual access with follow-up
- HCP workspaces
- Full units of state and settings
- Stage dependencies
- Ordering stacks in a pipeline
- State layout
- One state per environment and component
- Pipeline permissions
- Least privilege for IaC identities
- Private runners
- Agents with network access to private resources
- Keyless state access
- Entra ID auth for azurerm backend
- Partial applies
- State after a failed apply
- Path filters
- Running only affected stacks
- Dependency bots
- Automated version-bump PRs
- tfvars per environment
- Environment-specific values files
- Variable sets
- Reusable variables across workspaces
- lock-timeout
- Waiting for a state lock
- Plan exposure
- Secrets leaking via plan output
8.9 Pulumi, Ansible and other tools
- Pulumi stack
- Configured instance of a Pulumi project
- Pulumi backends
- Where Pulumi keeps state
- pulumi up
- Deploying a Pulumi stack
- Pulumi Outputs
- Values resolved during deployment
- Pulumi secrets
- Encrypted config values
- Pulumi ESC
- Environments, secrets and configuration service
- Automation API
- Pulumi as a library
- Component resources
- Grouping resources into reusable units
- pulumi convert
- Migrating code from other IaC tools
- Playbook
- YAML file of plays and tasks
- Ansible idempotency
- Using modules that check state first
- Check mode
- Ansible dry run
- Roles and collections
- Reusable Ansible content
- Ansible Vault
- Encrypting secrets in Ansible content
- Handlers
- Tasks triggered by changes
- Dynamic inventory
- Host lists from live sources
- serial
- Batching hosts in an Ansible play
- Crossplane
- Kubernetes-based control plane for cloud resources
- Azure Service Operator
- Kubernetes operator for Azure resources
- Terragrunt
- Wrapper for managing many Terraform units
- Provider bootstrapping
- Providers depending on resources from the same apply
- Ansible facts
- Host data collected automatically
- become
- Privilege escalation in Ansible
- CrossGuard
- Pulumi's policy-as-code framework
- Crossplane compositions
- Higher-level APIs over cloud resources
- Terragrunt dependency
- Linking units' outputs
- pulumi import
- Adopting existing resources into Pulumi
Sample practice questions
What is infrastructure as code (IaC)?
- Provisioning infrastructure from version-controlled files, not clicks
- Writing the application code that runs on the servers
- Documenting the infrastructure's setup in a team wiki
- Generating application code automatically from diagrams
Answer: A. Provisioning infrastructure from version-controlled files, not clicks IaC makes environments repeatable, reviewable and easy to recreate.
What does the `count` or `for_each` meta-argument do?
- Creates many instances of a resource or module from one block
- Counts how many resources are currently tracked in the state
- Repeats `terraform apply` several times in a row for reliability
- Limits how many API calls Terraform makes to the provider
Answer: A. Creates many instances of a resource or module from one block `for_each` keyed by name is usually safer than count, since removing an item does not shift indexes.
What does `terraform plan` do?
- Applies all pending changes to the infrastructure immediately
- Downloads the configured providers, and does nothing else
- Previews the changes Terraform would make, without applying
- Deletes every resource tracked in the current state
Answer: C. Previews the changes Terraform would make, without applying Review the plan (often in a pull request) before running `terraform apply`.
What is a Terraform provider?
- A plugin that manages a platform's resources via its API, like azurerm
- A cloud account that Terraform deploys all resources into
- A Terraform module published by a cloud vendor for reuse
- The backend where Terraform stores its state file
Answer: A. A plugin that manages a platform's resources via its API, like azurerm Pin provider versions with `required_providers` to avoid surprise upgrades.
What is Bicep?
- A Terraform provider for deploying resources to Microsoft Azure
- A container runtime that Azure uses for running workloads
- A declarative Azure language that compiles to ARM JSON templates
- A YAML-based pipeline language for Azure DevOps builds
Answer: C. A declarative Azure language that compiles to ARM JSON templates Bicep is more concise than ARM JSON and supports modules, loops and type checking.
Does Bicep need a state file like Terraform?
- Yes; it's kept in a storage account that Bicep creates
- Yes; it's committed to Git next to the template files
- No; Azure Resource Manager itself is the source of truth
- Only for production deployments, never for dev or test
Answer: C. No; Azure Resource Manager itself is the source of truth This is a key difference from Terraform.
Which tools scan IaC for security misconfigurations before deployment?
- Prettier and ESLint, with security plugins
- JUnit and xUnit, with IaC test adapters
- Docker Compose, with a scan profile
- Checkov, tfsec/Trivy and PSRule for Azure
Answer: D. Checkov, tfsec/Trivy and PSRule for Azure Policy as code (OPA, Sentinel, Azure Policy) can block non-compliant resources.
Why should IaC changes go through pull requests and a pipeline instead of being applied from laptops?
- Developer laptops aren't able to run Terraform or Bicep at all
- Running through a pipeline makes the cloud resources cheaper
- Cloud providers require every change to come from a pull request
- Changes get reviewed, plans are visible, credentials stay in CI, all audited
Answer: D. Changes get reviewed, plans are visible, credentials stay in CI, all audited A common flow: plan on pull request, apply on merge with approval for production.
Which tool is mainly a configuration management tool for configuring software on existing servers, rather than provisioning cloud resources?
- Ansible
- Terraform
- Bicep
- CloudFormation
Answer: A. Ansible Ansible, Chef and Puppet configure machines; Terraform and Bicep provision infrastructure. The lines blur, but this is the typical split.
What is the difference between declarative and imperative IaC?
- Declarative tools only work on Azure; imperative tools only on AWS
- Imperative tools can't create resources, only modify existing ones
- Declarative states the end state; imperative lists the steps to run
- There's no difference; the terms describe the same approach
Answer: C. Declarative states the end state; imperative lists the steps to run Terraform, Bicep and CloudFormation are declarative. Scripts with the az or aws CLI are imperative.
More Cloud and DevOps
- Cloud Fundamentals: IaaS, PaaS, SaaS and Shared Responsibility
- Azure Core Services
- AWS Core Services
- Google Cloud Basics
- Serverless: Azure Functions and AWS Lambda
- Containers and Docker
- Kubernetes
- CI/CD Pipelines: GitHub Actions and Azure DevOps
- Networking: DNS, TCP/IP, Load Balancers and VPNs
- Cloud Identity and Access: Entra ID, IAM and RBAC
- Secrets Management and Key Vault
- Monitoring and Alerting: Application Insights and CloudWatch
- Cloud Cost Management