Automate with Terraform
Create and manage Harness Artifacts registries, upstream proxies, filtering rules, and Dependency Firewall as code with the Terraform provider.
The Harness Terraform provider lets you create and manage registries, upstream proxies, artifact filtering rules, and Dependency Firewall configuration as code. This page provides ready-to-use HCL for the most common automation patterns.
Provider setup
terraform {
required_version = ">= 1.5.0"
required_providers {
harness = {
source = "harness/harness"
version = ">= 0.30.0"
}
}
}
provider "harness" {
endpoint = "https://app.harness.io/gateway"
account_id = var.harness_account_id
platform_api_key = var.harness_platform_api_key
}Always use platform_api_key (not the legacy api_key); Artifact Registry is a Harness NextGen feature.
Credentials via environment variables: never hardcode them.
Standard variables.tf for all configs:
Virtual registry
A virtual registry is the client-facing endpoint your team uses to push and pull artifacts.
Supported package_type values: DOCKER, HELM, MAVEN, NPM, PYTHON, GO, NUGET, CARGO, GENERIC, RPM, DEBIAN, ALPINE, WOLFI, SWIFT, COMPOSER, DART, RUBYGEMS, CRAN, CONAN, CONDA, PUPPET, HUGGING_FACE, TERRAFORM_MODULE.
Upstream proxy
An upstream proxy caches artifacts from a public or private source registry. Attach it to a virtual registry to serve cached content.
Virtual registry wired to an upstream proxy
The full pattern: create both resources and wire them together in a single config. This is the recommended approach for new infrastructure.
The depends_on ensures the proxy is created before the virtual registry references its identifier.
Artifact filtering rules
Add allowed_pattern and blocked_pattern to restrict which artifacts can be pushed to or pulled from a registry. Each pattern is a full regex match against the artifact name.
Dependency Firewall
Dependency Firewall evaluates artifacts fetched through an upstream proxy against security policies before caching them. Configure it on the upstream proxy registry, not the virtual registry.
firewall_mode value
Behavior
Omitted / "ALLOW"
Firewall disabled
"ENABLED"
Firewall on; artifacts that trigger a Warn policy are cached and usable (violation logged)
"QUARANTINE"
Firewall on; artifacts that trigger a Warn policy are cached but blocked until manually unquarantined
Import an existing registry
If a registry was created through the Harness UI, bring it under Terraform management.
The import path is always account_id/org_id/project_id/registry_identifier, with no leading slash, no https://, and no . separators.
HCL import block (Terraform ≥ 1.5, recommended):
Run terraform plan; Terraform shows what would change without applying. Run terraform apply to complete the import.
CLI import (all Terraform versions):
After importing, run terraform plan to confirm the existing state matches your configuration before applying any changes.
Remote state for teams and CI/CD
Local state (terraform.tfstate) only works on a single workstation. For shared infrastructure, configure a remote backend.
Never commit *.tfstate or *.tfstate.* files to source control. Add this .gitignore:
Run Terraform in CI/CD
GitHub Actions
Store HARNESS_API_KEY as a repository secret. Use a service account token scoped to the Artifact Registry Admin role, not a personal access token.
Harness CI pipeline
Troubleshooting
Next steps
Terraform provider reference: full
harness_platform_har_registryargument and attribute referenceAuthentication for agents: create service account tokens for Terraform automation
RBAC and permissions: minimum permissions for provisioning agents
Using Artifacts with AI agents: URL patterns and REST API for agents that consume provisioned registries
Last updated
Was this helpful?