# Data Sources: Metal

### Description

The `teraswitch_metal` data source retrieves information about an existing bare metal server. Use this data source to reference servers that were created outside of Terraform or are managed by a separate Terraform configuration.

### Example Usage

#### Basic Query

```hcl
data "teraswitch_metal" "existing" {
  id = 12345
}

output "server_hostname" {
  value = data.teraswitch_metal.existing.hostname
}

output "server_ip" {
  value = data.teraswitch_metal.existing.ip_addresses
}
```

#### Using Server Details in Configuration

```hcl
data "teraswitch_metal" "database" {
  id = var.database_server_id
}

# Use the database server's IP in application configuration
resource "teraswitch_cloud_compute" "app" {
  hostname     = "app-server"
  region       = "PIT1"
  machine_type = "c1.medium"
  image        = "ubuntu-22.04"

  user_data = <<-EOF
    #!/bin/bash
    echo "DATABASE_HOST=${data.teraswitch_metal.database.ip_addresses[0].address}" >> /etc/environment
  EOF
}
```

#### Conditional Logic Based on Server Status

```hcl
data "teraswitch_metal" "server" {
  id = 12345
}

resource "teraswitch_cloud_compute" "backup" {
  count = data.teraswitch_metal.server.status == "active" ? 1 : 0

  hostname     = "backup-server"
  region       = "PIT1"
  machine_type = "c1.small"
  image        = "ubuntu-22.04"
}
```

### Argument Reference

| Argument | Type   | Required | Description                                    |
| -------- | ------ | -------- | ---------------------------------------------- |
| `id`     | number | Yes      | The unique identifier of the bare metal server |

### Attribute Reference

The following attributes are exported:

| Attribute          | Type         | Description                    |
| ------------------ | ------------ | ------------------------------ |
| `id`               | number       | The server identifier          |
| `hostname`         | string       | The server's hostname          |
| `region`           | string       | The datacenter region          |
| `operating_system` | string       | The installed operating system |
| `status`           | string       | Current server status          |
| `ip_addresses`     | list(object) | List of IP addresses           |
| `specs`            | object       | Hardware specifications        |
| `tags`             | map(string)  | Server tags                    |
| `created_at`       | string       | Creation timestamp             |

#### IP Address Object

Each item in `ip_addresses` contains:

| Attribute | Type   | Description                          |
| --------- | ------ | ------------------------------------ |
| `address` | string | The IP address                       |
| `version` | number | IP version (4 or 6)                  |
| `type`    | string | Address type (`public` or `private`) |

#### Specs Object

The `specs` object contains:

| Attribute   | Type   | Description                  |
| ----------- | ------ | ---------------------------- |
| `cpu`       | string | CPU model and specifications |
| `memory_gb` | number | RAM capacity in gigabytes    |
| `storage`   | string | Storage configuration        |

### Finding the Server ID

You can find a server's ID in the TeraSwitch console:

1. Navigate to **Compute** > **Bare Metal**
2. Click on the server
3. The ID is shown in the URL: `https://console.tsw.io/projects/xxx/metal/12345`

Or use the [API](/account/api-tokens.md) to list servers and their IDs.

### Data Source vs Resource

| Use Case                   | Use                                      |
| -------------------------- | ---------------------------------------- |
| Query existing server info | Data source (`data "teraswitch_metal"`)  |
| Create new server          | Resource (`resource "teraswitch_metal"`) |
| Manage existing server     | Import into resource                     |

To bring an existing server under Terraform management, use the [import](/integrations/terraform/metal.md#import) feature with the `teraswitch_metal` resource.

### See Also

* [teraswitch\_metal resource](/integrations/terraform/metal.md)
* [Import Existing Resources](/integrations/terraform/import-existing.md)
* [Managing Bare Metal Services](/compute/metal/managing-services.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/metal-1.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.
