Azure Compute Image

This page shows how to write Terraform for Compute Image and write them securely.

azurerm_image (Terraform)

The Image in Compute can be configured in Terraform with the resource name azurerm_image. The following sections describe 9 examples of how to use the resource and its parameters.

Example Usage from GitHub

main.tf#L41
resource "azurerm_image" "this" {
  count               = 1
  name                = var.image_name
  resource_group_name = var.resource_group_name
  location            = var.location

image_create.tf#L1
resource "azurerm_image" "image" {
  name     = var.imagename
  location = "East US"
  resource_group_name = azurerm_resource_group.devops_rg.name
  #source_virtual_machine_id = "/subscriptions/5a8d2bcf-85f4-4625-a08e-162fcb039c1a/resourceGroups/devops_rg/providers/Microsoft.Compute/virtualMachines/Devops_VM"
  source_virtual_machine_id = azurerm_virtual_machine.Devops_VM.id
main.tf#L16
resource "azurerm_image" "image" {
  name     = "Devops_VM-image-20210511173856"
  location = "East US"
  resource_group_name = azurerm_resource_group.devops_rg.name
  source_virtual_machine_id = "/subscriptions/5a8d2bcf-85f4-4625-a08e-162fcb039c1a/resourceGroups/devops_rg/providers/Microsoft.Compute/virtualMachines/Devops_VM"

main.tf#L16
resource "azurerm_image" "image" {
  name     = "Devops_VM-image-20210511173856"
  location = "East US"
  resource_group_name = azurerm_resource_group.devops_rg.name
  source_virtual_machine_id = "/subscriptions/5a8d2bcf-85f4-4625-a08e-162fcb039c1a/resourceGroups/devops_rg/providers/Microsoft.Compute/virtualMachines/Devops_VM"

main.tf#L1
resource "azurerm_image" "example" {
  name                = var.name
  location            = var.location
  resource_group_name = module.resource_group.azurerm_resource_group.example.name

  os_disk {
terraform.tf#L31
resource "azurerm_image" "example2" {
  name                = "acctest2"
  location            = data.azurerm_resource_group.default.location
  resource_group_name = data.azurerm_resource_group.default.name

  os_disk {
main.tf#L1
resource "azurerm_image" "image" {
  count               = length(var.image)
  location            = element(var.location, lookup(var.image[count.index], "location_id"))
  name                = lookup(var.image[count.index], "name")
  resource_group_name = element(var.resource_group_name, lookup(var.image[count.index], "resource_group_id"))
  zone_resilient      = lookup(var.image[count.index], "zone_resilient")
main.tf#L7
resource "azurerm_image" "this" {
  hyper_v_generation        = var.hyper_v_generation
  location                  = var.location
  name                      = var.name
  resource_group_name       = var.resource_group_name
  source_virtual_machine_id = var.source_virtual_machine_id
main.tf#L7
resource "azurerm_image" "this" {
  hyper_v_generation        = var.hyper_v_generation
  location                  = var.location
  name                      = var.name
  resource_group_name       = var.resource_group_name
  source_virtual_machine_id = var.source_virtual_machine_id

Review your Terraform file for Azure best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

Explanation in Terraform Registry

Manages a custom virtual machine image that can be used to create virtual machines.

Tips: Best Practices for The Other Azure Compute Resources

In addition to the azurerm_linux_virtual_machine, Azure Compute has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.

risk-label

azurerm_linux_virtual_machine

Ensure to use SSH authentication for virtual machines

It is better to use SSH authentication for virtual machines instead of password authentication to enforce more secure ways.

risk-label

azurerm_managed_disk

Ensure to enable the encryption on managed disks

It is better to enable the encryption on managed disks.

risk-label

azurerm_virtual_machine

Ensure to use SSH authentication for virtual machines

It is better to use SSH authentication for virtual machines instead of password authentication to enforce more secure ways.

Review your Azure Compute settings

In addition to the above, there are other security points you should be aware of making sure that your .tf files are protected in Shisho Cloud.

Azure Resource Manager Example

Azure Resource Manager code does not have the related resource.

Frequently asked questions

What is Azure Compute Image?

Azure Compute Image is a resource for Compute of Microsoft Azure. Settings can be wrote in Terraform.

Where can I find the example code for the Azure Compute Image?

For Terraform, the RichBrumpton/terraform-azure-rubrik-cloud-cluster, ramboisahero/vmsswithimageandvm and anandraju/vmss-for-ado source code examples are useful. See the Terraform Example section for further details.

security-icon

Automate config file reviews on your commits

Fix issues in your infrastructure as code with auto-generated patches.