Terraform · Arazzo Workflow

Terraform Upsert a Workspace Variable

Version 1.0.0

Set a workspace variable to a value whether or not it already exists.

1 workflow 1 source API 1 provider
View Spec View on GitHub Infrastructure as CodeCloud InfrastructureDevOpsOpen-SourceHashiCorpArazzoWorkflows

Provider

terraform

Workflows

upsert-workspace-variable
Create or update a single workspace variable by key.
Lists the workspace variables, matches on the supplied key, updates the matched variable when one exists, otherwise creates it, and re-reads the list to confirm.
4 steps inputs: variableCategory, variableDescription, variableHcl, variableKey, variableSensitive, variableValue, workspaceId outputs: createdVariableId, updatedVariableId
1
listVariables
List every variable on the workspace so the target key can be matched against what is already configured.
2
updateVariable
Patch the existing variable with the new value. Only the supplied attributes change; the variable's category and identity are preserved.
3
createVariable
Create the variable on the workspace when no variable with the target key was found.
4
confirmVariables
Read the workspace variable list back to confirm the upsert landed and the workspace holds exactly one variable with the target key.

Source API Descriptions

Arazzo Workflow Specification

Raw ↑
arazzo: 1.0.1
info:
  title: Terraform Upsert a Workspace Variable
  summary: Set a workspace variable to a value whether or not it already exists.
  description: >-
    The idempotent configuration pattern every Terraform pipeline needs. The
    workflow lists the workspace's variables, branches on whether a variable with
    the target key is already present, and either patches the existing variable or
    creates a new one, then reads the variable list back to confirm the result.
    Every step spells out its request inline so the flow can be read and executed
    without opening the underlying OpenAPI description.
  version: 1.0.0
sourceDescriptions:
- name: variablesApi
  url: ../openapi/terraform-variables-api-openapi.yml
  type: openapi
workflows:
- workflowId: upsert-workspace-variable
  summary: Create or update a single workspace variable by key.
  description: >-
    Lists the workspace variables, matches on the supplied key, updates the
    matched variable when one exists, otherwise creates it, and re-reads the list
    to confirm.
  inputs:
    type: object
    required:
    - workspaceId
    - variableKey
    - variableValue
    - variableCategory
    properties:
      workspaceId:
        type: string
        description: The workspace identifier to write the variable to.
      variableKey:
        type: string
        description: The variable key to upsert (e.g. "instance_type").
      variableValue:
        type: string
        description: The value to write for the variable.
      variableCategory:
        type: string
        description: Whether this is a "terraform" input variable or an "env" variable.
      variableDescription:
        type: string
        description: A human readable description stored alongside the variable.
      variableHcl:
        type: boolean
        description: Whether the value should be parsed as HCL rather than a literal string.
      variableSensitive:
        type: boolean
        description: Whether the value should be write-only and hidden from reads.
  steps:
  - stepId: listVariables
    description: >-
      List every variable on the workspace so the target key can be matched
      against what is already configured.
    operationId: ListWorkspaceVariables
    parameters:
    - name: workspace_id
      in: path
      value: $inputs.workspaceId
    successCriteria:
    - condition: $statusCode == 200
    outputs:
      matchedVariableId: $response.body#/data/0/id
    onSuccess:
    - name: variableExists
      type: goto
      stepId: updateVariable
      criteria:
      - context: $response.body
        condition: $.data[?(@.attributes.key == "$inputs.variableKey")]
        type: jsonpath
    - name: variableMissing
      type: goto
      stepId: createVariable
      criteria:
      - context: $response.body
        condition: $.data[?(@.attributes.key == "$inputs.variableKey")].length == 0
        type: jsonpath
  - stepId: updateVariable
    description: >-
      Patch the existing variable with the new value. Only the supplied attributes
      change; the variable's category and identity are preserved.
    operationId: UpdateWorkspaceVariable
    parameters:
    - name: workspace_id
      in: path
      value: $inputs.workspaceId
    - name: variable_id
      in: path
      value: $steps.listVariables.outputs.matchedVariableId
    requestBody:
      contentType: application/vnd.api+json
      payload:
        data:
          type: vars
          attributes:
            key: $inputs.variableKey
            value: $inputs.variableValue
            description: $inputs.variableDescription
    successCriteria:
    - condition: $statusCode == 200
    outputs:
      variableId: $response.body#/data/id
      variableKey: $response.body#/data/attributes/key
    onSuccess:
    - name: updated
      type: goto
      stepId: confirmVariables
  - stepId: createVariable
    description: >-
      Create the variable on the workspace when no variable with the target key
      was found.
    operationId: CreateWorkspaceVariable
    parameters:
    - name: workspace_id
      in: path
      value: $inputs.workspaceId
    requestBody:
      contentType: application/vnd.api+json
      payload:
        data:
          type: vars
          attributes:
            key: $inputs.variableKey
            value: $inputs.variableValue
            description: $inputs.variableDescription
            category: $inputs.variableCategory
            hcl: $inputs.variableHcl
            sensitive: $inputs.variableSensitive
    successCriteria:
    - condition: $statusCode == 201
    outputs:
      variableId: $response.body#/data/id
      variableKey: $response.body#/data/attributes/key
  - stepId: confirmVariables
    description: >-
      Read the workspace variable list back to confirm the upsert landed and the
      workspace holds exactly one variable with the target key.
    operationId: ListWorkspaceVariables
    parameters:
    - name: workspace_id
      in: path
      value: $inputs.workspaceId
    successCriteria:
    - condition: $statusCode == 200
    outputs:
      variableCount: $response.body#/data
  outputs:
    updatedVariableId: $steps.updateVariable.outputs.variableId
    createdVariableId: $steps.createVariable.outputs.variableId

Work with this as data

Every workflow here is available over the APIs.io API and to AI agents over MCP.

MCP server

One button, every client — Claude, Cursor, VS Code and the rest.

https://apis.io/mcp

Tools for arazzo workflows

4 MCP tools reach this
  • find_arazzoBrowse and filter every workflow in the catalog.
  • apis_io_searchSTART HERE — APIs, providers and tags for one query, each with its total.
  • resolveTurn a domain, URL or GitHub org into the provider it belongs to.
  • find_cohortsEvery scored population of providers in the catalog.
All 92 tools →

Call it yourself

curl for this page
This workflow
curl "https://apis.io/api/v1/arazzo/terraform-upsert-workspace-variable-workflow"
All arazzo workflows
curl "https://apis.io/api/v1/arazzo?limit=25"

Discovery needs no key. Ratings and market analysis are Pro.

Get an API key

Free tier, no form to fill in. Signing in shares your email address with us — we store it to create your key and to recognise you if you sign in with another provider. See our Privacy Policy and Terms.

A second provider on the same verified email joins the account you already have.