Skip to main content
Version: 1.0.0

Deploying Terraform Modules Programmatically

Overview

This guide will show you how to deploy a Terraform module programmatically using the Zeet GraphQL API. You can use this guide to deploy any Terraform module from the Terraform Registry or your own git repo.

Prerequisites

Before making API requests, make sure that you have the Zeet GraphQL API ready and working. You can use the Getting Started guide for reference. Before deploying, you'll want to connect an AWS cloud account to Zeet. You will need your Team ID, and your Zeet AWS Account ID. You can grab those here:

# using v0 API endpoint:
# https://anchor.zeet.co/graphql
query {
currentUser {
teams {
team {
name
user {
id # This is $YOUR_TEAM_ID
}
awsAccounts {
id # This is $YOUR_AWS_ACCOUNT_ID
name
}
}
}
}
}

Creating a New Project

In order to deploy a Terraform Module using Zeet, you need to create a project. For this example, we'll use the api v1 endpoint. Ensure you are making requests to the correct GraphQL endpoint!

This is a two-step process. First we'll create a project, then we'll trigger a deployment:

# using v1 API endpoint:
# https://anchor.zeet.co/v1/graphql
mutation {
createProject(
input: {
teamId: $YOUR_TEAM_ID
name: "terraform-project"
groupName: "api-docs"
subGroupName: "example"
blueprintId: "0c2274e6-1a56-4692-96c8-0da1aac82aa6" # Official Terraform Module Blueprint ID
enabled: true
deploys: [
{
defaultWorkflowSteps: [DRIVER_PLAN, DRIVER_APPLY]
terraform: {
blueprint: {
source: {
terraformModule: {
source: "terraform-aws-modules/s3-bucket/aws" # example Terraform Module Source
version: "3.15.1"
integration: {}
}
}
}
target: {
moduleName: "example-terraform-module"
provider: {
awsAccountId: $YOUR_AWS_ACCOUNT_ID
region: "us-west-2"
}
stateBackend: {
s3Bucket: {
awsAccountId: $YOUR_AWS_ACCOUNT_ID
bucketName: "zeet-tf-state-4cf78b84-4db5-4496-adaf-f82bbc01c608"
region: "us-west-2"
key: "example-terraform-module"
}
}
}
}
variables: [
{ name: "bucket", value: "test-8e01db50-897e-4ac5-adf0-a0ae3b88bd25", type: STRING }
]
}
]
workflow: { steps: [{ action: ORCHESTRATION_DEPLOY }] }
}
) {
id
name
workflow {
id
}
}
}

If successful, you'll get a response like:

{
"data": {
"createProject": {
"id": "d32a73b4-5e1c-4478-947f-6f65b6852bc6", // This is $YOUR_PROJECT_ID
"name": "terraform-project",
"workflow": {
"id": "216e2aa9-2343-4ea8-927c-50d8dc7fc331" // This is $YOUR_WORKFLOW_ID
}
}
},
"extensions": {
"requestId": "9f212c26-feaf-418b-914e-079b5f721c55"
}
}

Deploy the Project

Finally, we'll trigger a deployment for our project. This will kick off the Terraform apply workflow and deploy the module:

mutation {
submitWorkflow(input: { workflowId: $YOUR_WORKFLOW_ID }) {
id
}
}

You can check the status of your deployment by querying the project:

query {
team(id: $YOUR_TEAM_ID) {
project(id: $YOUR_PROJECT_ID) {
status
}
}
}

Congrats! You've deployed a Terraform Module using the Zeet GraphQL API.