Author : MD TAREQ HASSAN | Updated : 2023/07/25

Scenario

Let’s say we want to create a devcontainer as an alternative to Azure CloudShell (why? you may ask, well Azure CloudShell is slow).

First, see what are the tools pre-installed in Azure CloudShell.

We need subset of those tools, for example, I want to create PowerShell scripts as IaC (infrastructure-as-code).

Image selection

We are gonna use Azure PowerShell docker image provided by Microsoft (mcr.microsoft.com/azure-powershell).

devcontainer.json

{
	"name": "Azure PowerShell IaC Env",
	
	"image": "mcr.microsoft.com/azure-powershell",
	
	"features": {

	}

}

Links:

Feature selection

Other than Azure PowerShell, the rest of the tools, runtime, languages etc. will be selected as feature.

devcontainer.json

{
	
	"features": {
		"ghcr.io/devcontainers/features/azure-cli:1": {},
		"ghcr.io/devcontainers/features/dotnet:1": {},
		"ghcr.io/devcontainers/features/git:1": {},
		"ghcr.io/devcontainers/features/github-cli:1": {},
		"ghcr.io/devcontainers/features/kubectl-helm-minikube:1": {},
		"ghcr.io/devcontainers/features/node:1": {},
		"ghcr.io/devcontainers/features/common-utils:2": {}
	}

}

See: list of devcontainer features

Final devcontainer.json

.devcontainer/devcontainer.json

{
    "name": "Azure PowerShell IaC",
    "image": "mcr.microsoft.com/azure-powershell",
    "features": {
        "ghcr.io/devcontainers/features/azure-cli:1": {},
        "ghcr.io/devcontainers/features/dotnet:1": {},
        "ghcr.io/devcontainers/features/git:1": {},
        "ghcr.io/devcontainers/features/github-cli:1": {},
        "ghcr.io/devcontainers/features/kubectl-helm-minikube:1": {},
        "ghcr.io/devcontainers/features/node:1": {},
        "ghcr.io/devcontainers/features/common-utils:2": {}
    },
    "customizations": {
        "vscode": {
            "settings": {
                "terminal.integrated.defaultProfile.linux": "pwsh"
            },
            "extensions": [
                "ms-vscode.powershell",
                "ms-vscode.azurecli",
                "editorconfig.editorconfig",
                "oderwat.indent-rainbow"
            ]
        }
    }
}

Create repository

Create a repository named “azure-powershell-iac”.

Add “.gitignore” file (https://github.com/PowerShell/vscode-powershell/blob/main/.gitignore)

.vscode-test/
logs/
modules
modules/
node_modules/
obj/
bin/
out/
sessions/
test-results.xml
*.vsix
*.DS_Store

Add “.editorconfig” file (https://github.com/microsoft/vscode/blob/main/.editorconfig)

# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

# Tab indentation
[*]
indent_style = tab
trim_trailing_whitespace = true

# The indent size used in the `package.json` file cannot be changed
# https://github.com/npm/npm/pull/3180#issuecomment-16336516
[{*.yml,*.yaml,package.json}]
indent_style = space
indent_size = 2

Add “.devcontainer/devcontainer.json

Create codespace

Codespace with custom config

Codespace from repository (default config: 2-core • 4GB RAM)

Tools version check

# PowerShell
$PSVersionTable.PSVersion

# Azure cli
az --version

# Git
git --version

# Kubectl
kubectl version -o json

# Helm
helm version

Rename codespace