Custom Images
Create and use your own Terraform plugin images.
Harness provides the flexibility to use custom images in your IaCM stage, which applies to individual infrastructure provisioning steps, such as the init step in an OpenTofu or Terraform pipeline stage. This guide walks you through the process of creating a custom image and incorporating it into your Harness pipelines.
Create an image
Harness allows you to create custom images based on a provided base image. This enables you to tailor the image to your specific needs and use it in your workflows.
VERSION LOCK-IN & MITIGATING CHALLENGES
Custom images created from the base image are version-locked. They will not automatically update with releases. An outdated version might not cause pipeline failures. It could lack features, have security vulnerabilities, or face compatibility issues.
To keep your custom image current with our latest improvements, periodically check for updates to our base image and rebuild your custom image as needed. Proactively monitor our releases to fully benefit from the latest enhancements.
Harness will log a warning if your image version is five versions behind the latest release, helping you detect out-of-date versions.
Create a custom image
Create custom images with root-based and rootless custom containers for Harness Cloud and Kubernetes environments. The following examples demonstrate package installation via microdnf and direct binary installation for tools like kubectl.
Create a root-based custom container for use in Harness Cloud and Docker.
Once your image is created, build with: docker build -f Dockerfile --platform linux/amd64 --target custom-root -t harness_terraform_vm_custom.
FROM plugins/harness_terraform_vm AS custom-root
## Example of an installation using the in-built "microdnf" package manager <a href="#example-of-an-installation-using-the-in-built-microdnf-package-manager" id="example-of-an-installation-using-the-in-built-microdnf-package-manager"></a>
RUN microdnf install -y wget
RUN microdnf clean all
## Example of downloading and installing a binary directly <a href="#example-of-downloading-and-installing-a-binary-directly" id="example-of-downloading-and-installing-a-binary-directly"></a>
## Binaries need to be suitable for the amd64 architecture <a href="#binaries-need-to-be-suitable-for-the-amd64-architecture" id="binaries-need-to-be-suitable-for-the-amd64-architecture"></a>
RUN curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
RUN install -o root -g root -m 0755 kubectl /usr/local/bin/kubectlCreate a custom container for use in Kubernetes.
Once your image is created, build with: docker build -f Dockerfile --platform linux/amd64 --target custom-root -t harness_terraform_custom.
FROM plugins/harness_terraform AS custom-rootless
## Switch to root temporarily so that we can install extra tools <a href="#switch-to-root-temporarily-so-that-we-can-install-extra-tools" id="switch-to-root-temporarily-so-that-we-can-install-extra-tools"></a>
USER root
## Example of an installation using the in-built "microdnf" package manager <a href="#example-of-an-installation-using-the-in-built-microdnf-package-manager" id="example-of-an-installation-using-the-in-built-microdnf-package-manager"></a>
RUN microdnf install -y wget
RUN microdnf clean all
## Example of downloading and installing a binary directly <a href="#example-of-downloading-and-installing-a-binary-directly" id="example-of-downloading-and-installing-a-binary-directly"></a>
## Binaries need to be suitable for the amd64 architecture <a href="#binaries-need-to-be-suitable-for-the-amd64-architecture" id="binaries-need-to-be-suitable-for-the-amd64-architecture"></a>
RUN curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
RUN install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
## Switch back to the "harness" user now that all tools are installed <a href="#switch-back-to-the-harness-user-now-that-all-tools-are-installed" id="switch-back-to-the-harness-user-now-that-all-tools-are-installed"></a>
USER harness---
Use your own image
To use your custom image in a step, create a reference in the YAML configuration indicating that the step should use your image.
IaCM execution-config
To use images from your repository in an IACM stage, you can use the execution-config API endpoints.
Set your Images with the update-config endpoint:
Reset the Images back to the defaults with the reset-config endpoint:
View your custom Images via the get-customer-config endpoint:
View the default images via the get-default-config endpoint:
Conclusion
In conclusion, custom images provide a powerful way to optimize your IaCM pipelines. By staying proactive with updates and leveraging the flexibility of Harness, you can ensure robust, secure, and efficient infrastructure management. Ready to take the next step? Implement these strategies and watch your deployment processes transform!
Last updated
Was this helpful?