概述
根据目标云与资源(如云服务器、对象存储)生成 Terraform 配置 .tf,声明式管理基础设施。
触发词
Terraform、IaC、基础设施即代码、tf 配置、terraform 生成、云资源编排
工作流
- 确认云厂商(腾讯云/阿里云/AWS)与要建的资源。
- 生成 provider 配置 + resource 块(变量化参数)。
- 提示变量在 variables.tf / terraform.tfvars 填写。
- 输出 .tf,提示 terraform init / plan / apply。
产出物(生成即用·Terraform tf)
terraform {
required_providers {
tencentcloud = {
source = "tencentcloudstack/tencentcloud"
version = ">= 1.0"
}
}
}
variable "region" { default = "ap-beijing" }
resource "tencentcloud_instance" "web" {
instance_name = "demo-web"
availability_zone = "${var.region}-2"
image_id = "img-xxxxxx"
instance_type = "S5.MEDIUM2"
# 密钥/网络等敏感参数请在 terraform.tfvars 中填写,勿提交明文
}
使用示例
输入:腾讯云 + 一台云服务器 → 生成 provider+instance 的 main.tf,参数走 variables。
红线(必须遵守)
- Secret/密钥类参数一律走变量文件,禁止在 .tf 写明文。
- image_id 等用占位,不写真实资源 ID。
大白话说明
你说要在哪朵云建什么资源,我写一份 Terraform 配置,以后一键重建整套环境。