Skip to main content

Getting Started

The Tharsis Terraform Provider allows you to interact with Tharsis resources directly from your Terraform configuration. The primary use case is reading workspace outputs to share data between workspaces. Full documentation is available on the Terraform Registry.

Provider configuration​

Add the provider to your required_providers block:

main.tf
terraform {
required_providers {
tharsis = {
source = "registry.terraform.io/martian-cloud/tharsis"
version = "0.15.1"
}
}
}

provider "tharsis" {}

When running inside a Tharsis workspace, the provider is automatically configured by the job executor — no host or static_token needed.

Running outside Tharsis​

When running outside of Tharsis (e.g. locally), you must provide the API endpoint and a token:

Provider with explicit configuration
provider "tharsis" {
host = "https://api.tharsis.example.com"
static_token = var.tharsis_token
}

These can also be set via environment variables:

Environment VariableDescription
THARSIS_ENDPOINTThe Tharsis API URL.
THARSIS_STATIC_TOKENThe static token to use with the provider.
note

Provider block values take precedence over environment variables.

Retrieving workspace outputs​

The most common use case is sharing outputs between workspaces. Tharsis provides two data sources for this:

  • tharsis_workspace_outputs — returns outputs as strings
  • tharsis_workspace_outputs_json — returns outputs as JSON strings (for complex types)
Visibility restrictions apply

The target workspace's output visibility setting controls which workspaces can read its outputs. If access is denied, Terraform will return an authorization error during plan or apply.

String outputs​

Read outputs from another workspace
data "tharsis_workspace_outputs" "network" {
path = "infrastructure/networking/vpc"
}

resource "aws_instance" "app" {
subnet_id = data.tharsis_workspace_outputs.network.outputs.subnet_id
}

JSON outputs​

For outputs that contain objects, lists, or maps, use the JSON data source with jsondecode:

Read JSON outputs from another workspace
data "tharsis_workspace_outputs_json" "network" {
path = "infrastructure/networking/vpc"
}

locals {
subnets = jsondecode(data.tharsis_workspace_outputs_json.network.outputs.subnet_ids)
}

Relative paths​

When running inside a Tharsis workspace, you can use relative paths to reference sibling workspaces:

group/
├── networking/
│ └── vpc ← source workspace
└── compute/
└── app ← current workspace
Relative path from app to vpc
data "tharsis_workspace_outputs" "network" {
path = "../networking/vpc"
}

Data source attributes​

NameTypeRequiredDescription
pathStringYesPath of the workspace to retrieve outputs from.
full_pathStringRead-onlyFull path of the resolved workspace.
outputsMap of StringRead-onlyThe workspace outputs.
state_version_idStringRead-onlyID of the workspace's current state version.
workspace_idStringRead-onlyID of the workspace.