Azure Compute Shared Image
This page shows how to write Terraform and Azure Resource Manager for Compute Shared Image and write them securely.
azurerm_shared_image (Terraform)
The Shared Image in Compute can be configured in Terraform with the resource name azurerm_shared_image
. The following sections describe 10 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "azurerm_shared_image" "shared-images-MediaCentral" {
name = "MediaCentral"
gallery_name = azurerm_shared_image_gallery.avid-shared-images.name
resource_group_name = azurerm_resource_group.avid-shared-images.name
location = azurerm_resource_group.avid-shared-images.location
os_type = "Linux"
resource "azurerm_shared_image" "vault" {
name = "vault"
gallery_name = var.sig_name
resource_group_name = azurerm_resource_group.main.name
location = var.location
os_type = "Linux"
resource "azurerm_shared_image" "pkr-lab-win10" {
name = "Windows_10"
gallery_name = azurerm_shared_image_gallery.pkr_image_gallery_computing.name
resource_group_name = azurerm_resource_group.pkr_image_gallery_computing.name
location = azurerm_resource_group.pkr_image_gallery_computing.location
os_type = "Windows"
resource "azurerm_shared_image" "centos_7" {
name = "centos-7"
resource_group_name = azurerm_resource_group.packer_rg.name
gallery_name = azurerm_shared_image_gallery.demo.name
location = local.location
os_type = "Linux"
resource "azurerm_shared_image" "image" {
count = var.create ? 1 : 0
name = var.name
gallery_name = var.gallery_name
resource_group_name = var.resource_group_name
location = var.location
resource "azurerm_shared_image" "shared_image" {
name = "Clarium-image"
gallery_name = azurerm_shared_image_gallery.shared_image_gallery.name
resource_group_name = azurerm_resource_group.resource_group.name
location = azurerm_resource_group.resource_group.location
os_type = "Linux"
resource "azurerm_shared_image" "nginx" {
name = "nginx"
gallery_name = azurerm_shared_image_gallery.sig.name
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
os_type = "Linux"
resource "azurerm_shared_image" "image" {
name = azurecaf_name.image_name.result
gallery_name = var.gallery_name
resource_group_name = var.resource_group_name
location = var.location
os_type = var.settings.os_type
resource "azurerm_shared_image" "example" {
name = "win2016rodc"
gallery_name = azurerm_shared_image_gallery.rodc.name
resource_group_name = azurerm_resource_group.rodc.name
location = azurerm_resource_group.rodc.location
os_type = "Windows"
resource "azurerm_shared_image" "windows" {
name = var.azure_managed_image_name
gallery_name = azurerm_shared_image_gallery.windows.name
resource_group_name = azurerm_resource_group.windows.name
location = azurerm_resource_group.windows.location
os_type = var.azure_os_type
Parameters
-
description
optional - string -
eula
optional - string -
gallery_name
required - string -
hyper_v_generation
optional - string -
id
optional computed - string -
location
required - string -
name
required - string -
os_type
required - string -
privacy_statement_uri
optional - string -
release_note_uri
optional - string -
resource_group_name
required - string -
specialized
optional - bool -
tags
optional - map from string to string -
identifier
list block -
purchase_plan
list block -
timeouts
single block
Explanation in Terraform Registry
Manages a Shared Image within a Shared Image Gallery.
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.
Microsoft.Compute/galleries/images (Azure Resource Manager)
The galleries/images in Microsoft.Compute can be configured in Azure Resource Manager with the resource name Microsoft.Compute/galleries/images
. The following sections describe how to use the resource and its parameters.
Example Usage from GitHub
"type": "Microsoft.Compute/galleries/images",
"apiVersion": "2020-09-30",
"name": "[concat(parameters('galleries_SNowImageGallery_name'), '/ps-wus2-win2016-imgdef')]",
"location": "westus2",
"properties": {
"hyperVGeneration": "V1",
"type": "Microsoft.Compute/galleries/images",
"name": "myGalleryImage",
"apiVersion": "2018-06-01",
"location": "[variables('location')]",
"properties": {
"osType": "Linux",
"type": "Microsoft.Compute/galleries/images",
"name": "myGalleryImage",
"apiVersion": "2019-03-01",
"location": "[variables('location')]",
"properties": {
"osType": "Linux",
"type": "Microsoft.Compute/galleries/images",
"apiVersion": "2019-03-01",
"name": "[concat(parameters('galleries_testsharedgallery_name'), '/imagedefinition-linux')]",
"location": "eastus",
"dependsOn": [
"[resourceId('Microsoft.Compute/galleries', parameters('galleries_testsharedgallery_name'))]"
"type": "Microsoft.Compute/galleries/images",
"apiVersion": "2019-03-01",
"name": "[concat(parameters('galleries_testsharedgallery_name'), '/imagedefinition-linux')]",
"location": "eastus",
"dependsOn": [
"[resourceId('Microsoft.Compute/galleries', parameters('galleries_testsharedgallery_name'))]"
"type": "Microsoft.Compute/galleries/images",
"apiVersion": "2019-03-01",
"name": "[concat(parameters('galleries_testsharedgallery_name'), '/imagedefinition-linux')]",
"location": "eastus",
"dependsOn": [
"[resourceId('Microsoft.Compute/galleries', parameters('galleries_testsharedgallery_name'))]"
"type": "Microsoft.Compute/galleries/images",
"name": "[concat(parameters('galleryDefinition').galleries.Name, '/', parameters('galleryDefinition').galleries.images[copyIndex()].galleryImageDefinitionName)]",
"apiVersion": "2018-06-01",
"location": "[resourceGroup().location]",
"properties": "[parameters('galleryDefinition').galleries.images[copyIndex()].galleryImageDefinitionProperties]"
},
"type": "Microsoft.Compute/galleries/images",
"name": "[concat(parameters('galleryName'), '/', parameters('galleryImageDefinitionName'))]",
"apiVersion": "2019-12-01",
"location": "[parameters('location')]",
"dependsOn": [
"[resourceId('Microsoft.Compute/galleries', parameters('galleryName'))]"
"type": "Microsoft.Compute/galleries/images",
"name": "[concat(parameters('galleryName'), '/', parameters('galleryImageDefinitionName'))]",
"apiVersion": "2018-06-01",
"location": "[resourceGroup().location]",
"properties": {
"description": "My gallery image definition",
"type": "Microsoft.Compute/galleries/images",
"name": "[concat(parameters('galleryName'), '/', parameters('galleryImageDefinitionName'))]",
"apiVersion": "2018-06-01",
"location": "[resourceGroup().location]",
"properties": {
"description": "My gallery image definition",
Parameters
apiVersion
required - stringlocation
required - stringResource location
name
required - stringThe name of the gallery image definition to be created or updated. The allowed characters are alphabets and numbers with dots, dashes, and periods allowed in the middle. The maximum length is 80 characters.
properties
requireddescription
optional - stringThe description of this gallery image definition resource. This property is updatable.
disallowed
optionaldiskTypes
optional - arrayA list of disk types.
endOfLifeDate
optional - stringThe end of life date of the gallery image definition. This property can be used for decommissioning purposes. This property is updatable.
eula
optional - stringThe Eula agreement for the gallery image definition.
features
optional arrayname
optional - stringThe name of the gallery image feature.
value
optional - stringThe value of the gallery image feature.
hyperVGeneration
optional - stringThe hypervisor generation of the Virtual Machine. Applicable to OS disks only.
identifier
requiredoffer
required - stringThe name of the gallery image definition offer.
publisher
required - stringThe name of the gallery image definition publisher.
sku
required - stringThe name of the gallery image definition SKU.
osState
required - stringThis property allows the user to specify whether the virtual machines created under this image are 'Generalized' or 'Specialized'.
osType
required - stringThis property allows you to specify the type of the OS that is included in the disk when creating a VM from a managed image. Possible values are: Windows Linux.
privacyStatementUri
optional - stringThe privacy statement uri.
purchasePlan
optionalname
optional - stringThe plan ID.
product
optional - stringThe product ID.
publisher
optional - stringThe publisher ID.
recommended
optionalmemory
optionalmax
optional - integerThe maximum number of the resource.
min
optional - integerThe minimum number of the resource.
vCPUs
optionalmax
optional - integerThe maximum number of the resource.
min
optional - integerThe minimum number of the resource.
releaseNoteUri
optional - stringThe release note uri.
tags
optional - stringResource tags
type
required - string
Frequently asked questions
What is Azure Compute Shared Image?
Azure Compute Shared 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 Shared Image?
For Terraform, the sviera91/Avid-SharedImageGallery, drewmullen/infra-testing-demo and wrippin/uod_sharedimagegallery_creation source code examples are useful. See the Terraform Example section for further details.
For Azure Resource Manager, the mahi-linux/web, Azure/azure-resource-manager-schemas and Azure/azure-resource-manager-schemas source code examples are useful. See the Azure Resource Manager Example section for further details.