This Terraform provider allows you to manage ZenML resources using Infrastructure as Code. It provides the ability to manage:
- ZenML Stacks
- Stack Components
- Service Connectors
- Terraform >= 1.0
- Go >= 1.20
- ZenML Server >= 0.70.0
- Clone the repository
git clone [email protected]:zenml-io/terraform-provider-zenml.git
- Build the provider
make build
To use the provider in your Terraform configuration:
terraform {
required_providers {
zenml = {
source = "zenml-io/zenml"
}
}
}
Configure the provider with your ZenML server URL and API key:
provider "zenml" {
server_url = "https://your-zenml-server.com"
api_key = "your-api-key"
}
You can also use environment variables:
export ZENML_SERVER_URL="https://your-zenml-server.com"
export ZENML_API_KEY="your-api-key"
To generate a ZENML_API_KEY, follow these steps:
- Install ZenML:
pip install zenml
- Connect to your ZenML server:
zenml connect --url <API_URL>
- Create a service account and get the API key:
zenml service-account create <MYSERVICEACCOUNTNAME>
This command will print out the ZENML_API_KEY that you can use with this provider.
Alternatively, you can use an API token for authentication:
provider "zenml" {
server_url = "https://your-zenml-server.com"
api_token = "your-api-token"
}
You can also use environment variables:
export ZENML_SERVER_URL="https://your-zenml-server.com"
export ZENML_API_TOKEN="your-api-token"
Hint: The ZenML Terraform provider is being heavily used in all our Terraform modules. Their code is available on GitHub and can be used as a reference:
Here's a basic example of creating a stack with components:
# Create a service connector for GCP
resource "zenml_service_connector" "gcp" {
name = "gcp-connector"
type = "gcp"
auth_method = "service-account"
# workspace defaults to "default" if not specified
configuration = {
project_id = "my-project"
location = "us-central1"
service_account_json = file("service-account.json")
}
labels = {
environment = "production"
}
}
# Create an artifact store component
resource "zenml_stack_component" "artifact_store" {
name = "gcs-store"
type = "artifact_store"
flavor = "gcp"
# workspace defaults to "default" if not specified
configuration = {
path = "gs://my-bucket/artifacts"
}
connector_id = zenml_service_connector.gcp.id
labels = {
environment = "production"
}
}
# Create a stack using the components
resource "zenml_stack" "ml_stack" {
name = "production-stack"
# workspace defaults to "default" if not specified
components = {
artifact_store = zenml_stack_component.artifact_store.id
}
labels = {
environment = "production"
}
}
Note: All resources support an optional
workspace
parameter that defaults to "default" if not specified. You can override this by settingworkspace = "your-workspace-name"
in any resource.
See the examples directory for more complete examples.
- Clone the repository
git clone [email protected]:zenml-io/terraform-provider-zenml.git
cd terraform-provider-zenml
- Build the provider
make build
Run unit tests:
make test
Run acceptance tests (requires a running ZenML server):
make testacc
To install the provider locally for testing:
make install
This will build and install the provider to your local Terraform plugins directory.
Generate provider documentation:
make docs
See CONTRIBUTING.md for guidelines on contributing to this provider.