hashicorp/hcp-terraform-operator该Kubernetes Operator旨在通过Kubernetes自定义资源(CR)实现对Terraform Cloud资源的声明式管理。它作为Kubernetes与Terraform Cloud之间的桥梁,允许用户直接通过Kubernetes API定义、部署和维护Terraform Cloud资源(如工作区、运行、变量等),简化多云环境下基础设施即代码(IaC)的管理流程。
bashkubectl apply -f [***][operator-repo]/main/config/crd/bases/terraformcloud.example.com_terraformworkspaces.yaml kubectl apply -f [***][operator-repo]/main/config/crd/bases/terraformcloud.example.com_terraformruns.yaml
bash# 创建命名空间 kubectl create namespace terraform-operator # 配置Terraform Cloud访问令牌(需替换为实际令牌) kubectl create secret generic terraform-cloud-token -n terraform-operator \ --from-literal=token=your-terraform-cloud-api-token # 部署Operator(示例使用默认配置) kubectl apply -f [***][operator-repo]/main/config/manager/manager.yaml -n terraform-operator
yamlapiVersion: terraformcloud.example.com/v1alpha1 kind: TerraformWorkspace metadata: name: example-workspace namespace: terraform-operator spec: name: example-workspace organization: my-terraform-org description: "Example workspace managed by Kubernetes Operator" terraformVersion: "1.6.0" workingDirectory: "path/to/terraform/code" tags: ["k8s-managed", "example"]
yamlapiVersion: terraformcloud.example.com/v1alpha1 kind: TerraformRun metadata: name: example-run namespace: terraform-operator spec: workspaceRef: example-workspace runType: planAndApply message: "Triggered by Kubernetes Operator" variables: - name: instance_count value: "3" sensitive: false
| 环境变量名 | 说明 | 必需 | 默认值 |
|---|---|---|---|
TERRAFORM_CLOUD_TOKEN | Terraform Cloud API访问令牌 | 是 | 无 |
TERRAFORM_CLOUD_HOST | Terraform Cloud API主机地址 | 否 | app.terraform.io |
SYNC_INTERVAL | 资源状态同步间隔(秒) | 否 | 30 |
LOG_LEVEL | 日志级别(debug/info/warn/error) | 否 | info |
| 字段名 | 说明 | 类型 | 必需 |
|---|---|---|---|
name | Terraform Cloud工作区名称 | string | 是 |
organization | Terraform Cloud组织名称 | string | 是 |
description | 工作区描述 | string | 否 |
terraformVersion | Terraform版本 | string | 否 |
workingDirectory | Terraform代码工作目录 | string | 否 |
tags | 工作区标签列表 | []string | 否 |
vcsRepo | VCS仓库配置(如GitHub、GitLab) | object | 否 |
| 字段名 | 说明 | 类型 | 必需 |
|---|---|---|---|
workspaceRef | 关联的TerraformWorkspace名称 | string | 是 |
runType | 运行类型(plan/planAndApply/destroy) | string | 是 |
message | 运行描述信息 | string | 否 |
variables | 运行时变量列表 | []object | 否 |
refresh | 是否在运行前刷新状态 | bool | 否 |

manifest unknown 错误
TLS 证书验证失败
DNS 解析超时
410 错误:版本过低
402 错误:流量耗尽
身份认证失败错误
429 限流错误
凭证保存错误
来自真实用户的反馈,见证轩辕镜像的优质服务