Tutorial 1 - Build an Ephemeral Developer Testing Environment
Set up a self-service ephemeral environment system that automatically provisions isolated test environments for PRs and deletes them after a stipulated time period.
Overview
This tutorial shows you how to eliminate PR testing bottlenecks by building a self-service ephemeral environment system. Instead of developers struggling over shared staging environments and manual cleanups, you will create automated environments that provision in 5 minutes and delete themselves after 24 hours.
The problem scenario
Your development team of 12 engineers ships a web application with 30+ pull requests per week. Currently, PR testing is painful:
2 shared "staging" environments → developers wait 2-4 hours for availability
Manual environment creation takes 30-45 minutes (create namespace, deploy services, configure DNS)
No cleanup process → 15+ old test namespaces consuming resources and cost
Inconsistent setup → each developer configures differently ("works on my machine")
QA bottleneck → QA team can only test 1-2 PRs at a time
The end result
A complete self-service environment system where developers can:
Click a button to get an isolated test environment (namespace + frontend + backend)
Test their PR without waiting or manual setup
Have the environment automatically deleted after 24 hours (TTL)
What you will build
IaCM workspace templates for Kubernetes namespace provisioning
Provision and destroy pipelines for infrastructure lifecycle
CD services for a web application (frontend + backend)
Environment Blueprints combining infrastructure and services
TTL based Ephemeral Environments

Before you begin
MAKE SURE YOU FULFILL THE REQUIREMENTS
Before proceeding with the tutorial steps, ensure you have completed the prerequisites outlined in the Get Started with Environment Management guide:
☑ Required modules and feature flags enabled
☑ Connector and delegate configured
☑ Infrastructure requirements met
☑ Permissions set across IDP, CD, and platform resources
Knowledge prerequisites
☑ Basic understanding of Kubernetes concepts (namespaces, deployments)
☑ Familiarity with Harness CD services and pipelines
☑ Basic knowledge of Helm charts
Component breakdown
IaCM Workspace Template - Defines reusable infrastructure patterns. Here we use it for Kubernetes namespaces, in principle this can be used for any infrastructure resource using Terraform/OpenTofu
CD Services - Define the applications to deploy (frontend + backend)
Pipelines - Create/destroy the namespaces, frontend, backend. This can be used to deploy any infrastructure resources, services
Environment Blueprint - Orchestrates all components with proper dependencies
TTL Configuration in Blueprint - Automatic environment cleanup after specified time period
Who benefits
Developers - Focus completely on coding instant test environments, no manual cleanup
Platform Team - Consistent environment configurations with clear audit trail (who created what, when)
QA Engineers - Test multiple PRs in parallel with predictable, consistent testing conditions
Finance Team - Reduction in test environment costs
Step-by-step walkthrough
Step 1: Create the namespace Terraform module
Create the Terraform code that the workspace will use. You can use an existing git repository or create a new one. Here we will use an existing repository in Harness Code Repository. In your Git repository at terraform/k8s-namespace/, create the following files:
Commit and push these files to your Git repository.
Step 2: Create the IaCM workspace template
The workspace template defines the infrastructure pattern for creating Kubernetes namespaces.
Go to Project Settings and under Project-level Resources, choose Templates. You can also use templates at Account and Org level.
Create a new Template of type Infra Workspace.
Configure the template:
Name:
k8s-namespace-templateVersion:
v1Description:
Creates a Kubernetes namespace for ephemeral environmentsTerraform/OpenTofu Version:
1.5.6(or your preferred version)

In the Repository section, choose Harness Code Repository and:
Repository: Your infrastructure repository.
Branch:
mainFolder Path:
terraform/k8s-namespace(where your Terraform code resides)
In the Variables section, add:
An overridable Terraform variable:
name(string, no default) - The namespace to create
Your GCP connector with the required permission to create/update namespaces in your cluster
Click Save to create the template
Note the identifiers:
Template Name:
k8s-namespace-templateTemplate Version:
v1
You will need these in Step 10 when creating the Environment Blueprint.
Step 3: Create the IaCM provision pipeline
This pipeline creates the namespace when an environment is provisioned. In principle, you can use the pipeline to create workspaces for any resource, so long as the template has its terraform code.
Navigate to Infrastructure as Code module, go to Pipelines and hit Create new pipeline with name
provision-namespace-pipelineSelect Inline storage type

Switch to YAML view and paste the following. Note that you can update the infrastructure, stages or even use existing pipelines here.
Click Save to create the pipeline

Note the identifier:
Pipeline identifier:
provision_namespace_pipeline
Step 4: Create the destroy pipeline
This pipeline cleans up the namespace when the environment is deleted or TTL expires.
Create a new pipeline named
destroy-namespace-pipelineUse this YAML:
Click Save to create the destroy pipeline
Note the identifier:
Pipeline identifier:
destroy_namespace_pipeline
Step 5: Create CD services
Now we will create two CD services for our sample application with the help of 2 toy nginx helm charts available here.
Frontend service
Navigate to Continuous Delivery → Services
Click + New Service
Configure:
Name:
ephemeral-frontendDescription:
React frontend for ephemeral testing
Select Inline storage type

In the Service Definition:
Deployment Type:
Native HelmManifests: Click Add Manifest
Manifest Type:
Helm ChartManifest Source:
Githuband select your Git connector or create a new one.Manifest Identifier:
helm-frontendRepository Name:
Git Fetch Type:
Latest from BranchBranch:
mainChart Path:
/frontendHelm Version:
V3
Click Save to create the frontend service
Backend service
Create another service named
ephemeral-backendand follow the same steps as above.Service Definition:
Deployment Type:
Native HelmManifests: Click Add Manifest
Manifest Type:
Helm ChartManifest Source:
Githuband select your Git connector or create a new one.Manifest Identifier:
helm-backendRepository Name:
<your-repository-name>(e.g.,demo)Git Fetch Type:
Latest from BranchBranch:
mainChart Path:
/backendHelm Version:
V3
Click Save to create the backend service
Note the identifiers:
Frontend service:
ephemeral-frontendBackend service:
ephemeral-backend
Step 6: Create a CD environment and infrastructure definition
The CD environment defines where your services will be deployed. We will create an environment with an infrastructure definition pointing to your Kubernetes cluster.
Create the environment
Navigate to Continuous Delivery → Environments
Click + New Environment
Configure the environment:
Name:
ephemeral-envDescription:
Environment for ephemeral testing deploymentsEnvironment Type: Select
Pre-Production
Choose Inline as the store type
Click Save to create the environment
Create the infrastructure definition
In the newly created environment, switch to the Infrastructure Definitions tab
Click + Infrastructure Definition
Configure the infrastructure:
Name:
ephemeral-infraDeployment Type: Select
Native Helm
Under Infrastructure Type, choose based on your cloud provider. In our example, we will use Direct Connection for vendor-agnostic Kubernetes
Configure the cluster details:
Connector: Select your Kubernetes or cloud provider connector (or create a new one)
Namespace: Mark as runtime input.
Release Name: Set to
<+service.name>(this ensures each service gets a unique Helm release name)
Click Save to create the infrastructure definition
Note the identifiers:
Environment identifier:
ephemeral_envInfrastructure definition identifier:
ephemeral_infra
You will need these identifiers in Step 10 when creating the Environment Blueprint.
Step 7: Create service deployment and delete pipelines
Create deployment and delete pipelines for both services. Note that you can update this pipeline based on your needs or even use your existing pipelines here.
Note the identifiers:
Deploy pipeline:
deploy_serviceDelete pipeline:
delete_service
You will need these in Step 9 when updating the Catalog entities.
Step 8: Enable CD auto-discovery to register catalog entities
CD Auto-discovery will automatically discover and import CD services as Catalog components in IDP. For more information on how to do this, go to Catalog Auto-Discovery with Harness CD Services
Step 9: Update catalog entities with deployment pipelines
Catalog entities should have the necessary deployment pipelines in the Catalog Info YAML.
Navigate to Internal Developer Portal → Catalog
Search for the entities
ephemeral-frontendandephemeral-backendClick to Edit, switch to YAML and paste the following under
spec:
Step 10: Create the environment blueprint
Now we will assemble all components into an environment blueprint that developers can use.
Navigate to Internal Developer Portal → Environments
Click Create → Environment Blueprint
Name:
ephemeral-testing-blueprint, Version:1.0.0, Owner:<Your team>Click Configure Environment Blueprint and paste YAML:

Click Save Blueprint
Step 11: Provision an ephemeral environment
Now let us create an environment instance from the blueprint.
Navigate to Internal Developer Portal → Environments
Click Create → Environment
Select Ephemeral Testing Environment blueprint

Fill in the configuration:
Name:
pr-456For each service:
Replicas:
2Version:
1.0.0

Click Create Environment and then Start Environment
The provisioning process will begin:
Namespace Creation: IaCM runs the provision pipeline
Frontend Deployment: CD deploys the frontend service
Backend Deployment: CD deploys the backend service
Once complete, you will see the environment dashboard with Environment status:
Online
Congratulations! You have successfully created an ephemeral environment system.
Recommended reading
Last updated
Was this helpful?