腾讯云配置
方法一:CLI方式
在系统界面下方的搜索框中输入Windows Powershell,然后选中对应程序右键,在弹出的菜单栏中选择“以管理员身份运行”即可以管理员权限运行Windows Powershell


2.安装Chocolatey
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

验证Chocolatey是否安装成功
choco -v
3.安装terraform
输入命令
choco install terraform
验证
terraform version
安装WSL
以管理员身份运行powerShell
输入命令
wsl --install
腾讯云配置
本地创建provider.tf文件,配置如下:
XXX1、XXX2需分别替换为在腾讯云上创建的SecretId和SecretKey
provider "tencentcloud" {
secret_id = "XXX1"
secret_key = "XXX2"
}
terraform {
required_providers {
tencentcloud = {
source = "tencentcloudstack/tencentcloud"
# 通过version指定版本
# version = ">=1.60.18"
}
}
}
另在本地创建main.tf文件,配置如下:
resource "tencentcloud_vpc" "foo" {
name = "ci-temp-test-updated"
cidr_block = "10.0.0.0/16"
dns_servers = ["119.29.29.30", "8.8.8.8"]
is_multicast = false
tags = {
"test" = "test"
}
}
本地环境变量配置
需配置TENCENTCLOUD_SECRET_ID和TENCENTCLOUD_SECRET_KEY


进入provider.tf和main.tf所在文件夹,依次执行命令terraform init、 terraform plan、 terraform apply




可以ping通即创建成功,然后去腾讯云上查看创建的子网
控制台-私有网络


方法二:vs code插件方式
1、在左侧插件 菜单,输入Tencent Cloud Terraform搜索插件。如下图所示:

2、单击安装
3、在侧边栏找到Tencent Cloud Terraform插件,单击登录 (Sign in)

选择 Login with Secret Id/Secret Key 方式,使用 AKSK 登录腾讯云。
根据输入框,依次输入账号的 Secret Id, Secret Key 和地域 (Region) 等信息。
- 使用插件创建腾讯云 VPC
现在,以创建一个 VPC 资源为例,编写 Terraform 代码。
配置 Provider
-
在 Explorer 中创建或选择一个文件夹,该文件夹将作为 Terraform 项目的工作空间。如下图所示:
image.png
terraform {
required_providers {
tencentcloud = {
source = "tencentcloudstack/tencentcloud"
# 通过version指定版本;若不指定,默认为最新版本
# version = ">=1.81.60"
}
}
}
provider "tencentcloud" {
region = "ap-guangzhou"
# AKSK已通过插件设置,无需在这里配置
}
2、初始化 Provider 配置。
通过调用 VS Code 命令面板(快捷键:Shift + Command + P (Mac) / Ctrl + Shift + P (Windows/Linux)),选择TencentCloud Terraform: Init,执行初始化操作。如下图所示:
网友评论