Terraform Modules
Deploy a cloud stack using Terraform
Last updated
Was this helpful?
Deploy a cloud stack using Terraform
Last updated
Was this helpful?
ZenML maintains a collection of designed to streamline the provisioning of cloud resources and seamlessly integrate them with ZenML Stacks. These modules simplify the setup process, allowing users to quickly provision cloud resources as well as configure and authorize ZenML to utilize them for running pipelines and other AI/ML operations.
By leveraging these Terraform modules, users can ensure a more efficient and scalable deployment of their machine learning infrastructure, ultimately enhancing their development and operational workflows. The modules' implementation can also be used as a reference for creating custom Terraform configurations tailored to specific cloud environments and requirements.
To use this feature, you need a deployed ZenML server instance that is reachable from the cloud provider where you wish to have the stack provisioned (this can't be a local server started via zenml login --local
). If you do not already have one set up, you can fast-track to trying out a ZenML Pro server by simply running zenml login --pro
or . If you prefer to host your own, you can learn about self-hosting a ZenML server .
Once you are connected to your deployed ZenML server, you need to create a service account and an API key for it. You will use the API key to give the Terraform module programmatic access to your ZenML server. You can find more about service accounts and API keys . But the process is as simple as running the following CLI command while connected to your ZenML server:
Example output:
Finally, you will need the following on the machine where you will be running Terraform:
the ZenML Terraform stack modules assume you are already locally authenticated with your cloud provider through the provider's CLI or SDK tool and have permissions to create the resources that the modules will provision. This is different depending on the cloud provider you are using and is covered in the following sections.
If you are already knowledgeable about using Terraform and the cloud provider where you want to deploy the stack, this process will be straightforward. The ZenML Terraform provider lets you manage your ZenML resources (stacks, stack components, etc.) as infrastructure-as-code. In a nutshell, you will need to:
Set up the ZenML Terraform provider with your ZenML server URL and API key. It is recommended to use environment variables for this rather than hardcoding the values in your Terraform configuration file:
Create a new Terraform configuration file (e.g., main.tf
), preferably in a new directory, with the content that looks like this (<cloud provider>
can beaws
, gcp
, or azure
):
Run the following commands in the directory where you have your Terraform configuration file:
The directory where you keep the Terraform configuration file and where you run the terraform
commands is important. This is where Terraform will store the state of your infrastructure. Make sure you do not delete this directory or the state file it contains unless you are sure you no longer need to manage these resources with Terraform or after you have deprovisioned them up withterraform destroy
.
Terraform will prompt you to confirm the changes it will make to your cloud infrastructure. If you are happy with the changes, type yes
and hit enter.
Terraform will then provision the resources you have specified in your configuration file. Once the process is complete, you will see a message indicating that the resources have been successfully created and printing out the ZenML stack ID and name:
At this point, a ZenML stack has also been created and registered with your ZenML server, and you can start using it to run your pipelines:
You can find more details specific to the cloud provider of your choice in the next section:
Authentication
Example Terraform Configuration
Here is an example Terraform configuration file for deploying a ZenML stack on AWS:
Stack Components
The Terraform module will create a ZenML stack configuration with the following components:
An S3 Artifact Store linked to an S3 bucket via an AWS Service Connector configured with IAM role credentials
An ECR Container Registry linked to an ECR repository via an AWS Service Connector configured with IAM role credentials
Depending on the orchestrator
input variable:
A local Orchestrator, if orchestrator
is set to local
. This can be used in combination with the SageMaker Step Operator to selectively run some steps locally and some on SageMaker.
If orchestrator
is set to sagemaker
(default): a SageMaker Orchestrator linked to the AWS account via an AWS Service Connector configured with IAM role credentials
If orchestrator
is set to skypilot
: a SkyPilot Orchestrator linked to the AWS account via an AWS Service Connector configured with IAM role credentials
An AWS CodeBuild Image Builder linked to the AWS account via an AWS Service Connector configured with IAM role credentials
a SageMaker Step Operator linked to the AWS account via an AWS Service Connector configured with IAM role credentials
To use the ZenML stack, you will need to install the required integrations:
For the local or SageMaker orchestrator:
For the SkyPilot orchestrator:
Cleaning up the resources provisioned by Terraform is as simple as running theterraform destroy
command in the directory where you have your Terraform configuration file. This will remove all the resources that were provisioned by the Terraform module and will also delete the ZenML stack that was registered with your ZenML server.
installed on your machine (version at least 1.9).
There might be a few additional required or optional inputs depending on the cloud provider you are using. You can find the full list of inputs for each module in the documentation for the relevant module, or you can read on in the following sections.
The contains extensive information about required permissions, inputs, outputs, and provisioned resources. This is a summary of the key points from that documentation.
To authenticate with AWS, you need to have installed on your machine, and you need to have run aws configure
to set up your credentials.
The contains extensive information about required permissions, inputs, outputs, and provisioned resources. This is a summary of the key points from that documentation.
To authenticate with GCP, you need to have installed on your machine, and you need to have run gcloud init
or gcloud auth application-default login
to set up your credentials.
To authenticate with Azure, you need to have installed on your machine, and you need to have run az login
to set up your credentials.