# Terraform Provider

### Overview

The TeraSwitch Terraform provider enables you to manage your infrastructure as code. Define cloud instances, bare metal servers, networks, and storage volumes in declarative configuration files that can be versioned, shared, and reused.

**Provider Source**: `TeraSwitch/teraswitch` **Latest Version**: `~> 0.0.7` **Registry**: [Terraform Registry](https://registry.terraform.io/providers/TeraSwitch/teraswitch/latest) **Source Code**: [GitHub](https://github.com/TeraSwitch/terraform-provider-teraswitch)

### Requirements

* **Terraform**: Version 1.0 or later
* **TeraSwitch Account**: Access to the [TeraSwitch Console](https://console.tsw.io)
* **API Token**: [Create an API token](/account/api-tokens.md) for authentication

### Quick Start

#### 1. Configure the Provider

Create a `main.tf` file with the provider configuration:

```hcl
terraform {
  required_providers {
    teraswitch = {
      source  = "TeraSwitch/teraswitch"
      version = "~> 0.0.7"
    }
  }
}

provider "teraswitch" {
  api_key    = var.teraswitch_api_key
  project_id = var.teraswitch_project_id
}
```

#### 2. Define Variables

Create a `variables.tf` file:

```hcl
variable "teraswitch_api_key" {
  description = "TeraSwitch API key"
  type        = string
  sensitive   = true
}

variable "teraswitch_project_id" {
  description = "TeraSwitch project ID"
  type        = number
}
```

#### 3. Create a Resource

Add a cloud instance to your `main.tf`:

```hcl
resource "teraswitch_cloud_compute" "web" {
  hostname     = "web-server-01"
  region       = "PIT1"
  machine_type = "c1.medium"
  image        = "ubuntu-22.04"
}

output "server_ip" {
  value = teraswitch_cloud_compute.web.ip_addresses
}
```

#### 4. Deploy

```bash
# Initialize the provider
terraform init

# Preview changes
terraform plan

# Apply configuration
terraform apply
```

{% hint style="success" %}
Use environment variables `TERASWITCH_API_KEY` and `TERASWITCH_PROJECT_ID` to avoid passing credentials on the command line.
{% endhint %}

\## Documentation

#### [Configuration](/integrations/terraform/configuration.md)

Detailed provider configuration options, authentication methods, and best practices.

#### [Resources](/integrations/terraform/resources.md)

Reference documentation for all managed resources:

* [teraswitch\_metal](/integrations/terraform/metal.md) - Bare metal servers

#### [Data Sources](/integrations/terraform/data-sources.md)

Query existing infrastructure:

* [teraswitch\_metal](/integrations/terraform/metal-1.md) - Query bare metal servers

#### [Examples](/integrations/terraform/examples.md)

Practical deployment examples:

* [Import Existing Resources](/integrations/terraform/import-existing.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.teraswitch.com/integrations/terraform.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
