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
| Argument | Type | Required/Optional | Description |
|---|---|---|---|
name | String | Required | Unique name for the component. |
stage | String | Required | Phase where the component runs: BUILD or TEST. |
cloud_providers | List | Required | List of supported clouds (e.g., ["AWS", "AZURE"]). |
os_types | List | Required | List of supported OS types: LINUX or WINDOWS. |
content | Block | Required | The script or playbook content. |
content.provisioner | String | Required | Type of provisioner: SHELL, POWERSHELL, or ANSIBLE. |
content.script | String | Required | The actual script or playbook content. |
description | String | Optional | A brief description of the component. |
rebuild_templates | Boolean | Optional | If 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>