# Examples

### Overview

These examples demonstrate common deployment patterns using the TeraSwitch Terraform provider. Each example includes complete, working configurations that you can adapt for your own use.

### Available Examples

| Example                                                                 | Description                                              |
| ----------------------------------------------------------------------- | -------------------------------------------------------- |
| [Import Existing Resources](/integrations/terraform/import-existing.md) | Bring existing infrastructure under Terraform management |

### Prerequisites

Before using these examples, ensure you have:

1. **Terraform installed** (version 1.0 or later)

   ```bash
   terraform -version
   ```
2. **TeraSwitch API credentials**
   * [Create an API token](/account/api-tokens.md)
   * Note your project ID
3. **SSH key uploaded** to TeraSwitch
   * [Manage SSH keys](/account/ssh-keys.md)

### Using the Examples

#### 1. Clone the Example

Copy the example code into a new directory:

```bash
mkdir my-infrastructure
cd my-infrastructure
```

#### 2. Configure Credentials

Set environment variables:

```bash
export TERASWITCH_API_KEY="your-api-key"
export TERASWITCH_PROJECT_ID="12345"
```

Or create a `terraform.tfvars` file (don't commit this to version control):

```hcl
teraswitch_api_key    = "your-api-key"
teraswitch_project_id = 12345
```

#### 3. Initialize and Apply

```bash
terraform init
terraform plan
terraform apply
```

#### 4. Clean Up

When finished, destroy the resources:

```bash
terraform destroy
```

{% hint style="warning" %}
Running `terraform destroy` will permanently delete all resources created by the configuration. Ensure you have backups of any important data.
{% endhint %}

\## Best Practices

#### Version Control

* Always commit your Terraform configurations
* Never commit credentials or `.tfvars` files containing secrets
* Use a `.gitignore` file:

```
# .gitignore
*.tfvars
*.tfstate
*.tfstate.backup
.terraform/
```

#### State Management

For team environments, use remote state storage:

```hcl
terraform {
  backend "s3" {
    bucket = "my-terraform-state"
    key    = "teraswitch/terraform.tfstate"
    region = "us-east-1"
  }
}
```

#### Modular Configuration

As your infrastructure grows, organize configurations into modules:

```
infrastructure/
├── modules/
│   ├── web-tier/
│   ├── app-tier/
│   └── database/
├── environments/
│   ├── production/
│   └── staging/
└── main.tf
```


---

# 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/examples.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.
