> 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 提供程序

VergeOS Terraform 提供程序支持通过 Terraform 和 OpenTofu 配置，以基础设施即代码的方式管理 VergeOS 资源，包括 VM、网络和用户。

## 概述

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

## 主要功能

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

## 安装与配置

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

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

provider "vergeio" {
  host     = "your-vergeos-ip-or-hostname"
  username = "your-username"
  password = "your-password"
}
```

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

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

## 可用资源

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

* `vergeio_vm` - 创建和管理虚拟机
* `vergeio_network` - 配置和管理虚拟网络
* `vergeio_user` - 配置和管理用户
* `vergeio_member` - 管理组成员关系
* `vergeio_tag_member` - 为 VergeOS 对象分配标签

## 使用示例

### 创建虚拟机

```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      = "192.168.1.0/24"
  dhcp_enabled = true
  dhcp_start   = "192.168.1.100"
  dhcp_stop    = "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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
