Templates
The imagefactory_template resource is the core of your image automation. It defines the base OS, the components to apply, and the distribution settings for your images.
Basic Example
data "imagefactory_distribution" "ubuntu" {
name = "Ubuntu Server 18.04 LTS"
cloud_provider = "AWS"
}
data "imagefactory_system_component" "hardening" {
name = "Hardening level 1"
}
resource "imagefactory_template" "web_server" {
name = "ubuntu-web-server"
cloud_provider = "AWS"
distribution_id = data.imagefactory_distribution.ubuntu.id
config {
aws {
region = "eu-west-1"
}
build_components {
id = data.imagefactory_system_component.hardening.id
}
build_components {
id = imagefactory_custom_component.nginx.id
}
notifications {
type = "SNS"
uri = "arn:aws:sns:eu-west-1:123456789012:ImageBuildTopic"
}
tags {
key = "Environment"
value = "Production"
}
tags {
key = "Team"
value = "Platform"
}
cloud_account_ids = [imagefactory_aws_account.main.id]
}
}
note
All components, notifications, tags, and distribution targets are defined inside the config block, not at the top level of the resource.
Argument Reference
Top-Level Arguments
| Argument | Type | Required | Description |
|---|---|---|---|
name | String | Required | Unique name for the template. |
cloud_provider | String | Required | Target cloud: AWS, AZURE, GCP, EXOSCALE. |
distribution_id | String | Required | ID of the base OS distribution. Use the imagefactory_distribution data source to look it up. |
description | String | Optional | A description of the template. |
config | Block | Optional | Template configuration — see below. |
Config Block
All of the following are nested inside the config block:
| Argument | Type | Description |
|---|---|---|
aws | Block | AWS-specific settings. |
azure | Block | Azure-specific settings. |
gcp | Block | GCP-specific settings. |
exoscale | Block | Exoscale-specific settings. |
build_components | Block List | Components to run during the build phase. Each block has an id field. |
test_components | Block List | Components to run during the test phase. Each block has an id field. |
notifications | Block List | Notification targets. Each block has type (SNS or WEB_HOOK) and uri. |
tags | Block List | Image tags. Each block has key and value. |
cloud_account_ids | List of String | IDs of cloud accounts to distribute the image to. |
disable_cyclical_rebuilds | Boolean | Disable automatic rebuilds when the source image updates or security patches are available. Defaults to false. |
scope | String | Set to "CHINA" for AWS China or Azure China templates. |
AWS Config (config.aws)
| Argument | Type | Description |
|---|---|---|
region | String | Target AWS region (e.g., eu-west-1). |
ebs_volume_type | String | EBS volume type for the primary block device: gp2 or gp3. Defaults to the source image type. |
kms_key_id | String | AWS KMS key ID/ARN to encrypt the destination snapshot. The ImageFactoryMasterRole must have permission to use this key. |
custom_image_name | String | Custom name for the resulting AMI. |
additional_ebs_volumes | Block List | Up to 10 additional EBS volumes (see below). |
additional_ebs_volumes block:
| Argument | Type | Description |
|---|---|---|
device_name | String | Required. Linux: /dev/sd[b-z], Windows: xvd[b-z]. |
size | Number | Required. Volume size between 1 and 10 GB. |
volume_type | String | Optional. gp2 or gp3. Defaults to gp2. |
Azure Config (config.azure)
| Argument | Type | Description |
|---|---|---|
replica_regions | List of String | Regions to replicate the gallery image to. |
vm_image_definition | Block | Azure Compute Gallery image definition (requires name, offer, sku). |
exclude_from_latest | Boolean | Exclude this version from the latest tag in the gallery. |
eol_date_option | Boolean | Set end-of-life date. Defaults to true. |
trusted_launch | Boolean | Enable Trusted Launch for the image. |
create_managed_image | Boolean | Create a legacy managed image in addition to the gallery image. |
disable_vhd_cleanup | Boolean | Keep temporary VHD files after build. Defaults to false. |
additional_data_disks | Block List | Up to 10 additional data disks. Each block has a size field (1–10 GB). |
additional_signatures | Block List | Additional UEFI keys for boot loader validation. Each block has a variable_name field pointing to a customer variable storing the key. |
GCP Config (config.gcp)
| Argument | Type | Description |
|---|---|---|
custom_image_name | String | Custom name for the GCP image. Must start with a lowercase letter, contain only lowercase letters, digits, and dashes, and be 3–45 characters long. |
Exoscale Config (config.exoscale)
| Argument | Type | Description |
|---|---|---|
zone | String | Required. Target Exoscale zone (e.g., de-fra-1). |
Advanced Examples
Azure Template with VM Image Definition
resource "imagefactory_template" "azure_app" {
name = "azure-app-server"
cloud_provider = "AZURE"
distribution_id = data.imagefactory_distribution.ubuntu_azure.id
config {
azure {
exclude_from_latest = true
eol_date_option = true
replica_regions = ["westeurope", "northeurope"]
vm_image_definition {
name = "my-app-image"
offer = "ubuntu-22_04-lts"
sku = "v1"
}
}
cloud_account_ids = [imagefactory_azure_subscription.main.id]
notifications {
type = "WEB_HOOK"
uri = "https://hooks.slack.com/services/..."
}
tags {
key = "Environment"
value = "Production"
}
}
}
Azure Template with Additional Data Disks
resource "imagefactory_template" "azure_with_disks" {
name = "azure-with-data-disks"
cloud_provider = "AZURE"
distribution_id = data.imagefactory_distribution.ubuntu_azure.id
config {
azure {
additional_data_disks {
size = 1
}
}
}
}
Azure Template with UEFI Signatures
resource "imagefactory_variable" "uefi_key" {
name = "UEFI_KEY"
value = "MIIDQTCCAimgAwIBAgIQ..."
}
resource "imagefactory_template" "azure_signed" {
name = "azure-signed-image"
cloud_provider = "AZURE"
distribution_id = data.imagefactory_distribution.ubuntu_azure.id
config {
azure {
trusted_launch = true
additional_signatures {
variable_name = imagefactory_variable.uefi_key.name
}
}
}
}
AWS Template with KMS Encryption and EBS Volumes
resource "imagefactory_template" "aws_encrypted" {
name = "aws-encrypted-image"
cloud_provider = "AWS"
distribution_id = data.imagefactory_distribution.ubuntu.id
config {
aws {
region = "eu-west-1"
ebs_volume_type = "gp3"
kms_key_id = "arn:aws:kms:eu-west-1:123456789012:key/example-key-id"
additional_ebs_volumes {
size = 1
device_name = "/dev/sdb"
}
}
build_components {
id = data.imagefactory_system_component.hardening.id
}
}
}
Template with Notifications
resource "imagefactory_template" "notified" {
name = "notified-template"
cloud_provider = "AWS"
distribution_id = data.imagefactory_distribution.amazon_linux.id
config {
aws {
region = "us-east-1"
}
notifications {
type = "WEB_HOOK"
uri = "https://hooks.slack.com/services/..."
}
notifications {
type = "SNS"
uri = "arn:aws:sns:us-east-1:123456789012:my-topic"
}
}
}
Exoscale Template
data "imagefactory_distribution" "ubuntu22_exoscale" {
name = "Ubuntu Server 22.04 LTS"
cloud_provider = "EXOSCALE"
}
resource "imagefactory_template" "exoscale" {
name = "ubuntu-2204-exoscale"
cloud_provider = "EXOSCALE"
distribution_id = data.imagefactory_distribution.ubuntu22_exoscale.id
config {
exoscale {
zone = "de-fra-1"
}
notifications {
type = "WEB_HOOK"
uri = "https://hooks.example.com/imagefactory"
}
}
}
GCP Template
data "imagefactory_distribution" "ubuntu22_gcp" {
name = "Ubuntu Server 22.04 LTS"
cloud_provider = "GCP"
}
resource "imagefactory_template" "gcp" {
name = "ubuntu-2204-gcp"
cloud_provider = "GCP"
distribution_id = data.imagefactory_distribution.ubuntu22_gcp.id
config {
gcp {
custom_image_name = "ubuntu-22-04-prod-1-3"
}
notifications {
type = "WEB_HOOK"
uri = "https://hooks.example.com/imagefactory"
}
}
}
AWS China Template
resource "imagefactory_template" "aws_china" {
name = "ubuntu-china"
cloud_provider = "AWS"
distribution_id = data.imagefactory_distribution.ubuntu.id
config {
scope = "CHINA"
}
}
Import
terraform import imagefactory_template.main <TEMPLATE_ID>