Skip to main content

Getting Started

What is the Tharsis Terraform Provider?​

Tharsis Terraform Provider provides a way to represent some of Tharsis' functionalities using Terraform.

Using the provider​

To use this provider, you must add the provider definition to your configuration. You can use either a static token or service account for authentication.

Static token​

provider "tharsis" {}
Expand for explanation
NameTypeDefinition
hoststringHostname for the Tharsis API (e.g. https://api.tharsis.example.com).
static_tokenstringStatic token for authenticating with the Tharsis API.
note

host and static_token are set automatically by the job executor. However, they are required when running outside Tharsis.

Alternatively, you can provide these values by environment variables.

Environment VariableDefinition
THARSIS_ENDPOINTThe host for Tharsis.
THARSIS_STATIC_TOKENThe static token to use with the provider.
important

The provider block values take precedence over environment variables. It is recommended to use configuration values to define the provider over environment variables, especially if you are defining the provider more than once.

Retrieving workspace outputs​

tharsis_workspace_outputs data source is used to retrieve outputs from workspace under a given path.

Terraform module for retrieving outputs from another workspace
terraform {
required_providers {
tharsis = {
source = "registry.terraform.io/martian-cloud/tharsis"
}
}
}

provider "tharsis" {}

data "tharsis_workspace_outputs" "this" {
path = "group/sub-group/workspace"
}

# When running via a Tharsis executor, in a workspace,
# the path can be relative to the workspace.
#
# For instance, if you had the following structure where
# you are operating from myworkspace:
# group
# |- sub-group
# |--|- workspace
# |--my-group
# |--|- myworkspace <- this is the current workspace
#
# You can access `workspace` relative to your `myworkspace`
# by using the relative path `../sub-group/workspace`
#
# data "tharsis_workspace_outputs" "this" {
# path = "../sub-group/workspace"
# }

output "str" {
value = data.tharsis_workspace_outputs.this.outputs.output_name
}
Expand for explanation
NameRead-OnlyTypeRequiredDescription
path-StringYesThe path of the workspace to retrieve outputs.
full_pathYesString-The full path of the workspace.
outputsYesMap of String-The outputs of the workspace specified by the path.
state_version_idYesString-The ID of the workspace's current state version.
workspace_idYesString-The ID of the workspace.
Terraform module for retrieving JSON outputs from another workspace
terraform {
required_providers {
tharsis = {
source = "registry.terraform.io/martian-cloud/tharsis"
}
}
}

provider "tharsis" {}

data "tharsis_workspace_outputs_json" "this" {
path = "group/sub-group/workspace"
}

# When running via a Tharsis executor, in a workspace,
# the path can be relative to the workspace.
#
# For instance, if you had the following structure where
# you are operating from myworkspace:
# group
# |- sub-group
# |--|- workspace
# |--my-group
# |--|- myworkspace <- this is the current workspace
#
# You can access `workspace` relative to your `myworkspace`
# by using the relative path `../sub-group/workspace`
#
# data "tharsis_workspace_outputs" "this" {
# path = "../sub-group/workspace"
# }

output "object" {
value = jsondecode(data.tharsis_workspace_outputs_json.this.outputs.object)
}
Expand for explanation

jsondecode maps JSON values to Terraform language values.

NameRead-OnlyTypeRequiredDescription
path-StringYesThe path of the workspace to retrieve outputs.
full_pathYesString-The full path of the workspace.
outputsYesMap of String-The outputs of the workspace specified by the path.
state_version_idYesString-The ID of the workspace's current state version.
workspace_idYesString-The ID of the workspace.