Skip to main content
This page collects practical Terraform examples for common Phala Cloud deployment scenarios. Each example is self-contained and can be adapted to your use case.

Basic Deployment

The simplest deployment: one app, one replica, public endpoint.

Dynamic Discovery

Instead of hardcoding sizes, regions, and images, use data sources to discover valid values at plan time.

Multi-Replica Deployment

Scale an application horizontally by setting replicas. All replicas share the same compose file and environment.

Cross-App Wiring

Deploy one app and pass its outputs (app ID, endpoint) as environment variables to a second app. Terraform handles the dependency ordering automatically.

SSH Access

Inject SSH keys at deploy time for direct access into CVM instances. You can also manage account-level SSH keys separately with phala_ssh_key.
The ssh_authorized_keys attribute is force-new. Changing the key list after initial deployment requires recreating the app. For keys you want to manage independently, use phala_ssh_key at the account level.

GPU Deployment

For GPU workloads, use a size from the GPU family. Discover available GPU sizes with the family filter.

Node Pinning

Pin a deployment to a specific worker node when you need deterministic hardware placement.

Power Management

Use phala_cvm_power to stop and start CVMs independently of the app lifecycle. This is useful for cost control or scheduled maintenance.
To restart, change state to "running" and run terraform apply.

Attestation Verification

After deployment, fetch TEE attestation data to verify the CVM’s integrity.

Compose Runtime Settings

Control visibility and behavior flags at the compose level. Changing these triggers a compose update and CVM restart.