# Create Run — Terraform

> Creates a new run in Terraform. See the documentation

- Key: `terraform-create-run`
- Type: Action (Write)
- Version: 0.0.2
- App: Terraform (`terraform`) — https://pipedream.com/apps/terraform.md
- This page (HTML): https://pipedream.com/apps/terraform/actions/create-run
- Hints: open-world
- Source: https://github.com/PipedreamHQ/pipedream/blob/master/components/terraform/actions/create-run/create-run.mjs

## Description

Creates a new run in Terraform. [See the documentation](https://developer.hashicorp.com/terraform/cloud-docs/api-docs/run#create-a-run)

## Props

| Prop | Type | Required | Description |
|---|---|---|---|
| `orgId` | `string` | Yes | Identifier of an organization Options are loaded from the connected account. |
| `workspaceId` | `string` | Yes | Identifier of a workspace Options are loaded from the connected account. |
| `configurationVersion` | `string` | Yes | Specifies the configuration version to use for this run. If the configuration-version object is omitted, the run will be created using the workspace's latest configuration version. Options are loaded from the connected account. |
| `message` | `string` | No | Specifies the message associated with this run. |
| `allowEmptyApply` | `boolean` | Yes | Specifies whether Terraform can apply the run even when the plan contains no changes. Often used to upgrade state after upgrading a workspace to a new terraform version. |
| `allowConfigGeneration` | `boolean` | No | Specifies whether Terraform can generate resource configuration when planning to import new resources. If false, import blocks without a corresponding resource block will error. |
| `autoApply` | `boolean` | No | Whether to automatically apply changes when a Terraform plan is successful. Defaults to the Auto Apply workspace setting. |
| `isDestroy` | `boolean` | No | Specifies whether this plan is a destroy plan that will destroy all provisioned resources. Mutually exclusive with refresh-only. |
| `refresh` | `boolean` | No | Specifies whether or not to refresh the state before a plan. |
| `refreshOnly` | `boolean` | No | Whether this run should refresh the state without modifying any resources. Mutually exclusive with is-destroy. |
| `planOnly` | `boolean` | No | Specifies if this is a speculative, plan-only run that Terraform cannot apply. Often used in conjunction with terraform-version in order to test whether an upgrade would succeed. |
| `savePlan` | `boolean` | No | Specifies if this should be a saved plan run. Terraform can apply saved plan runs, but they perform their plan and checks without becoming the workspace's current run (like a plan-only run), and will only become the current run if you confirm them for apply. When creating new configuration versions for saved plan runs, be sure to make them provisional |
| `terraformVersion` | `string` | No | Specifies the Terraform version to use in this run. Only valid for plan-only runs; must be a valid Terraform version available to the organization. |

## Run it

**MCP**

```ts
import { Client } from "@modelcontextprotocol/sdk/client/index.js"
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const accessToken = await pd.rawAccessToken

const transport = new StreamableHTTPClientTransport(
  new URL("https://remote.mcp.pipedream.net/v3"),
  {
    requestInit: {
      headers: {
        Authorization: `Bearer ${accessToken}`,
        "x-pd-project-id": process.env.PIPEDREAM_PROJECT_ID!,
        "x-pd-environment": "production",
        "x-pd-external-user-id": "{external_user_id}", // any stable ID for this user in your system
        "x-pd-app-slug": "terraform",
      },
    },
  },
)

const mcp = new Client({ name: "my-agent", version: "1.0.0" })
await mcp.connect(transport)

const { tools } = await mcp.listTools()

// listTools() hands your model this tool's input schema, so it can
// fill the arguments itself:
const result = await mcp.callTool({
  name: "terraform-create-run",
  arguments: {
    orgId: "Organization",
    workspaceId: "Workspace",
  },
})
```

**TypeScript**

```ts
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const result = await pd.actions.run({
  id: "terraform-create-run",
  externalUserId: "{external_user_id}", // any stable ID for this user in your system
  configuredProps: {
    terraform: { authProvisionId: "apn_xxxxxxx" },
    orgId: "Organization",
    workspaceId: "Workspace",
  },
})

console.log(result)
```

**cURL**

```bash
curl -X POST https://api.pipedream.com/v1/connect/{project_id}/actions/run \
  -H "Content-Type: application/json" \
  -H "X-PD-Environment: production" \
  -H "Authorization: Bearer {access_token}" \
  -d '{
    "external_user_id": "{external_user_id}",
    "id": "terraform-create-run",
    "configured_props": {
      "terraform": { "authProvisionId": "apn_xxxxxxx" },
      "orgId": "Organization",
      "workspaceId": "Workspace"
    }
  }'
```

---

- App: https://pipedream.com/apps/terraform.md · All apps: https://pipedream.com/apps
