vscode-dev-containers/containers/azure-terraform
Gergő Rubint 11922dead7
Fix "Add add sudo support.." typo (#1569)
Signed-off-by: Gergő Rubint <gergo@grubint.com>

Signed-off-by: Gergő Rubint <gergo@grubint.com>
2022-08-12 12:54:45 -04:00
..
.devcontainer Fix "Add add sudo support.." typo (#1569) 2022-08-12 12:54:45 -04:00
.vscode Update the tasks to remove duplicates from the azure terraform extension 2021-02-18 14:33:50 -06:00
test-project Update the tasks to remove duplicates from the azure terraform extension 2021-02-18 14:33:50 -06:00
.npmignore Update azure-ansible to use common scripts 2020-08-05 19:47:03 +00:00
README.md tool to convert README metadata to json. (#1332) 2022-03-02 15:09:24 -05:00

README.md

Azure Terraform (Community)

build, change, and version Azure infrastructure with terraform

Summary

Terraform is an open-source tool that provides the ability to build, change, and version infrastructure as code using declarative configuration files with HashiCorp Configuration Language (HCL).

This recipe allows you to get going quickly with Terraform in Azure. Includes Terraform, the Azure CLI, the Docker CLI (for testing locally), Node.js for Cloud Shell, and related extensions and dependencies.

Metadata Value
Contributors Carlos Mendible, Charles Zipp, Lila Molyva, Tas Devani
Categories Community, Azure, Other
Definition type Dockerfile
Supported architecture(s) x86-64, arm64/aarch64 for bullseye based images
Works in Codespaces Yes
Container host OS support Linux, macOS, Windows
Container OS Debian
Languages, platforms Azure, Terraform

Using this definition

While technically optional, this definition includes the Azure Terraform extension which requires a few pre-requisites:

You can also choose the specific version of Terraform installed by updating the following line in .devcontainer/devcontainer.json:

"arg": {
   "TERRAFORM_VERSION": "0.14.5"
   "TFLINT_VERSION": "0.24.1",
   "TERRAGRUNT_VERSION": "0.28.1"
   "INSTALL_AZURE_CLI": "true",
   "INSTALL_DOCKER": "true",
   "NODE_VERSION": "lts"
}

If you plan to use the Azure Cloud Shell for all of your Terraform operations, you can set "INSTALL_DOCKER": "false". Conversely, if you do not plan to use Cloud Shell, you can set "NODE_VERSION": "none". By default, both are installed so you can decide later.

Beyond git, this Dockerfile includes zsh, Oh My Zsh!, a non-root vscode user with sudo access, and a set of common dependencies for development.

Adding the definition to a project or codespace

  1. If this is your first time using a development container, please see getting started information on setting up Remote-Containers or creating a codespace using GitHub Codespaces.

  2. Start VS Code and open your project folder or connect to a codespace.

  3. Press F1 select and Add Development Container Configuration Files... command for Remote-Containers or Codespaces.

    Note: If needed, you can drag-and-drop the .devcontainer folder from this sub-folder in a locally cloned copy of this repository into the VS Code file explorer instead of using the command.

  4. Select this definition. You may also need to select Show All Definitions... for it to appear.

  5. Finally, press F1 and run Remote-Containers: Reopen Folder in Container or Codespaces: Rebuild Container to start using the definition.

Testing the Definition

This definition includes some test code that will help you verify it is working as expected on your system. Follow these steps:

  1. Follow steps 1-4 from the above section.

  2. Fill in the values for the environment variables in the .devcontainer/devcontainer.env file

    • This file allows customization of the environment variables and the values needed for the terraform tasks.
  3. Open the Command Palette with Ctrl/CMD+Shift+P or press F1 and run Remote-Containers: Reopen Folder in Container to start using the definition.

  4. VS Code tasks have been configured to run commonly used Terraform commands. The test-project folder includes a Terraform template that provisions a new Azure Resource Group and the commands can be run via Ctrl/CMD+Shift+P > Tasks: Run Tasks. Run Terraform Tasks

A more detailed explanation of the tasks can be found in the next section.

Running the Tasks

Once the environment settings are configured with the .devcontainer/devcontainer.env, you can begin executing terraform commands. VS Code tasks have been configured to run each of the commonly used terraform commands.

  • az login: login to Azure and set your default subscription
  • terraform create backend: create (if it does not exists) a remote azurerm backend (storage account)
  • terraform init: installs plugins and connect to terraform remote backend
  • terraform format: fix formatting issues
  • terraform lint: fix linting issues

For additional terraform commands, you can use the Azure Terraform extension.

  • Navigate to the directory where the templates are located (test-project/templates)
  • Open the Command Palette with Ctrl/CMD+Shift+P or press F1 and run the following:
    • Azure Terraform: Validate: check templates for syntax errors
    • Azure Terraform: Plan: report what would be done with apply without actually deploying any resources
    • Azure Terraform: Apply: deploy the terraform templates
    • Azure Terraform: Destroy: destroy resources deployed with the templates

For a complete list of all the available commands as part of the Azure Terraform extension, please visit this page

References

License

Copyright (c) Microsoft Corporation. All rights reserved.

Licensed under the MIT License. See LICENSE.