Skip to main content

Custom Components

Custom components allow you to extend ImageFactory by running your own scripts or playbooks during the image build or test phases.

Basic Example​

resource "imagefactory_custom_component" "install_nginx" {
name = "install-nginx"
description = "Installs and configures Nginx"
stage = "BUILD"
cloud_providers = ["AWS", "AZURE"]
os_types = ["LINUX"]

content {
provisioner = "SHELL"
script = <<-EOT
#!/bin/bash
apt-get update
apt-get install -y nginx
systemctl enable nginx
EOT
}

rebuild_templates = true
}

Argument Reference​

ArgumentTypeRequired/OptionalDescription
nameStringRequiredUnique name for the component.
stageStringRequiredPhase where the component runs: BUILD or TEST.
cloud_providersListRequiredList of supported clouds (e.g., ["AWS", "AZURE"]).
os_typesListRequiredList of supported OS types: LINUX or WINDOWS.
contentBlockRequiredThe script or playbook content.
content.provisionerStringRequiredType of provisioner: SHELL, POWERSHELL, or ANSIBLE.
content.scriptStringRequiredThe actual script or playbook content.
descriptionStringOptionalA brief description of the component.
rebuild_templatesBooleanOptionalIf true, templates using this component will automatically rebuild when the content changes.

Provisioner Examples​

PowerShell (Windows)​

resource "imagefactory_custom_component" "windows_config" {
name = "windows-base-config"
stage = "BUILD"
cloud_providers = ["AWS"]
os_types = ["WINDOWS"]

content {
provisioner = "POWERSHELL"
script = <<-EOT
Write-Host "Configuring Windows..."
Set-ExecutionPolicy Bypass -Scope Process -Force
EOT
}
}

Ansible Playbook​

resource "imagefactory_custom_component" "ansible_setup" {
name = "ansible-web-setup"
stage = "BUILD"
cloud_providers = ["GCP"]
os_types = ["LINUX"]

content {
provisioner = "ANSIBLE"
script = <<-EOT
---
- name: Install packages
hosts: all
become: yes
tasks:
- name: Install git
apt:
name: git
state: present
EOT
}
}

Import​

terraform import imagefactory_custom_component.main <COMPONENT_ID>