> For the complete documentation index, see [llms.txt](https://docs.verge.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.verge.io/automate-protect-and-extend/zh/ji-cheng-yu-api/terraform-provider.md).

# VergeOS Terraform Provider

## 概述

VergeOS Terraform Provider 可实现对您的 VergeOS 环境进行基础设施即代码管理。该提供程序允许您使用 Terraform 配置来定义、部署和管理 VergeOS 资源，为您的虚拟基础设施管理提供自动化能力。

## 主要功能

* 对 VergeOS 虚拟机、网络、磁盘和用户进行自动化配置
* 适用于 VergeOS 环境的基础设施即代码工作流
* 受版本控制的基础设施部署
* 与现有 Terraform 和 OpenTofu 工作流集成
* 可重复的环境创建和管理

## 安装与配置

要使用 VergeOS Terraform Provider，请在您的 Terraform 配置中添加以下内容：

```hcl
terraform {
  required_providers {
    vergeio = {
      source = "verge-io/vergeio"
      version = "~> 0.1.0"
    }
  }
}

provider "vergeio" {
  host     = "你的-vergeos-IP-或主机名"
  username = "你的用户名"
  password = "你的密码"
}
```

对于 OpenTofu 用户，配置保持不变：

```hcl
terraform {
  required_providers {
    vergeio = {
      source = "verge-io/vergeio"
      version = "~> 0.1.0"
    }
  }
}
```

## 可用资源

该提供程序支持管理以下 VergeOS 资源：

* `vergeio_vm` - 创建和管理虚拟机
* `vergeio_network` - 配置和管理虚拟网络
* `vergeio_user` - 配置和管理存储资源

## 使用示例

### 创建虚拟机

```hcl
resource "vergeio_vm" "example" {
  name        = "example-vm"
  cpu_cores   = 2
  ram         = 4096  # MB
  description = "Terraform 创建的示例虚拟机"

  
  vergeio_drive {
    disksize            = 20  #GB
    interface           = "virtio-scsi"
    preferred_tier      = 2
  }
  
  vergeio_nic {
    vnet       = vergeio_network.example.id
    interface  = "virtio"
  }
}
```

### 配置网络

```hcl
resource "vergeio_network" "example" {
  name             = "example-internal-network"
  network_address  = "192.168.1.0/24"
  dns_server_list  = ["8.8.8.8", "8.8.4.4"]
  dhcp_enabled     = true
  dhcp_start       = "192.168.1.100"
  dhcp_end         = "192.168.1.200"
  }
}
```

## 文档和资源

如需完整文档，包括所有受支持的资源、数据源和详细使用示例，请访问官方提供程序文档：

* [Terraform Registry 文档](https://registry.terraform.io/providers/verge-io/vergeio/latest/docs)
* [OpenTofu Registry 文档](https://search.opentofu.org/provider/verge-io/vergeio/latest)
* [GitHub 仓库](https://github.com/verge-io/terraform-provider-vergeio)

## 支持

如果您遇到问题或有功能请求，请在 GitHub 仓库中提交 issue：

<https://github.com/verge-io/terraform-provider-vergeio/issues>

## 其他资源

* [Terraform 文档](https://developer.hashicorp.com/terraform/docs)
* [OpenTofu 文档](https://opentofu.org/docs/)
* [基础设施即代码最佳实践](https://www.hashicorp.com/resources/what-is-infrastructure-as-code)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.verge.io/automate-protect-and-extend/zh/ji-cheng-yu-api/terraform-provider.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
