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
resource "azurerm_image" "this" {
count = 1
name = var.image_name
resource_group_name = var.resource_group_name
location = var.location
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
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"
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"
resource "azurerm_image" "example" {
name = var.name
location = var.location
resource_group_name = module.resource_group.azurerm_resource_group.example.name
os_disk {
resource "azurerm_image" "example2" {
name = "acctest2"
location = data.azurerm_resource_group.default.location
resource_group_name = data.azurerm_resource_group.default.name
os_disk {
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")
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
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
Parameters
-
hyper_v_generation
optional - string -
id
optional computed - string -
location
required - string -
name
required - string -
resource_group_name
required - string -
source_virtual_machine_id
optional - string -
tags
optional - map from string to string -
zone_resilient
optional - bool -
data_disk
list block-
blob_uri
optional computed - string -
caching
optional - string -
lun
optional - number -
managed_disk_id
optional - string -
size_gb
optional computed - number
-
-
os_disk
list block -
timeouts
single block
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.
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.
azurerm_managed_disk
Ensure to enable the encryption on managed disks
It is better to enable the encryption on managed disks.
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.
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.