PowerShell and Admin AutomationReporting and AuditsIntermediate1 hourLab build

Build a Reproducible Devcontainer Environment for PowerShell, Terraform, and Azure CLI

Build a reproducible devcontainer for PowerShell, Terraform, and Azure CLI work so the toolchain is easy to rebuild.

Last reviewed4/30/2026
PowerShellTerraformAzure CLIDockerVisual Studio Code

Expected Outcome

A working devcontainer that allows you to develop and run PowerShell scripts, manage Terraform configurations, and interact with Azure CLI reliable.

Assumptions

  • Visual Studio Code installed
  • Docker installed
  • Basic understanding of PowerShell, Terraform, and Azure CLI

Bill of Materials

  • Docker
  • Visual Studio Code
  • PowerShell
  • Terraform
  • Azure CLI

Build Steps

  1. Create a new project directory

    Set up a new directory for your devcontainer project.

    Example pattern only. Adjust for your environment before running.

    mkdir devcontainer-project
    cd devcontainer-project
  2. Create a Dockerfile

    Create a Dockerfile that defines the environment for PowerShell, Terraform, and Azure CLI.

    Safe to run: read-only

    echo 'FROM mcr.microsoft.com/powershell:latest' > Dockerfile
    echo 'RUN apt-get update && apt-get install -y unzip curl' >> Dockerfile
    echo 'RUN curl -Lo terraform.zip https://releases.hashicorp.com/terraform/1.0.0/terraform_1.0.0_linux_amd64.zip' >> Dockerfile
    echo 'RUN unzip terraform.zip && mv terraform /usr/local/bin/ && rm terraform.zip' >> Dockerfile
    echo 'RUN curl -sL https://aka.ms/InstallAzureCLIDeb | bash' >> Dockerfile
  3. Create a devcontainer.json file

    Define the devcontainer configuration in a JSON file.

    Safe to run: read-only

    mkdir .devcontainer
    echo '{ "name": "PowerShell Terraform Azure CLI", "build": { "dockerfile": "../Dockerfile" }, "settings": { "terminal.integrated.shell.linux": "/usr/bin/pwsh" }, "extensions": [ "ms-azuretools.vscode-azurecli", "ms-azuretools.vscode-azurefunctions", "ms-azuretools.vscode-terraform" ] }' > .devcontainer/devcontainer.json
  4. Build and open the devcontainer

    Use Visual Studio Code to build and open the devcontainer. Manual action: Press Ctrl+Shift+P and select 'Remote-Containers: Reopen in Container'.

    Example pattern only. Adjust for your environment before running.

    code .
  5. Verify installation

    Check if PowerShell, Terraform, and Azure CLI are installed correctly.

    Safe to run: read-only

    pwsh -c 'Get-Command terraform'
    pwsh -c 'az --version'

Validation

  • Ensure that PowerShell, Terraform, and Azure CLI commands return the expected output.
  • Run a simple Terraform script to validate the environment.

Troubleshooting

  • Check service logs before changing the design.
  • Confirm ports, paths, credentials, DNS names, and container names match the guide assumptions.

Cleanup or Rollback

  • Stop test services you no longer need and keep a copy of working configuration before deleting volumes or data directories.

Next Improvements

  • Create a sample Terraform configuration to manage Azure resources.
  • Explore PowerShell scripting for automation tasks.
  • Integrate CI/CD pipelines with your devcontainer setup.