上云无忧 > 文档中心 > 腾讯云弹性微服务 TEM Terraform 管理 - 环境资源管理
弹性微服务 TEM
腾讯云弹性微服务 TEM Terraform 管理 - 环境资源管理

文档简介:
操作场景: 在弹性微服务中,环境是一组计算、网络、存储等资源的集合。TEM 提供多环境管理的功能,您可根据自身业务需要,创建开发、测试、预发、生产等多个环境,分别部署应用,达成环境隔离的目的。不同环境中的应用彼此隔离。 本文介绍如何使用 Terraform 创建、编辑和删除 TEM 环境资源。
*此产品及展示信息均由腾讯云官方提供。免费试用 咨询热线:400-826-7010,为您提供专业的售前咨询,让您快速了解云产品,助您轻松上云! 微信咨询
  免费试用、价格特惠

操作场景

在弹性微服务中,环境是一组计算、网络、存储等资源的集合。TEM 提供多环境管理的功能,您可根据自身业务需要,创建开发、测试、预发、生产等多个环境,分别部署应用,达成环境隔离的目的。不同环境中的应用彼此隔离。 本文介绍如何使用 Terraform 创建、编辑和删除 TEM 环境资源。

前提条件

请参见 Terraform 快速开始 安装 Terraform 并配置腾讯云鉴权。

TEM 环境资源

Terraform 的 tencentcloud_tem_environment 资源提供了以下参数:
必填:environment_name 环境名称。
必填:vpc 指定私有网络。
必填:subnet_ids 指定子网,
可选:description 环境描述信息。 详细信息请参见 terraform_tem_environment

创建环境

此处以在广州地域下创建一个命名为 tf-test 的环境为示例:
1. 创建 provider.tf 文件,指定 provider 配置信息。文件内容如下:
		
terraform {
required_providers {
tencentcloud = {
source = "tencentcloudstack/tencentcloud"
# 通过version指定版本
# version = ">=1.60.18"
}
}
}
provider "tencentcloud" {
region = "ap-guangzhou"
# secret_id = "my-secret-id"
# secret_key = "my-secret-key"
}
region:填写地域 ID。
获取凭证:在 API 密钥管理 面中创建并复制 SecretId 和 SecretKey。
2. 创建 main.tf 文件,配置腾讯云 Provider 并创建弹性微服务环境。文件内容如下:
		
resource "tencentcloud_tem_environment" "environment" {
environment_name = "test_tf"
description = "demo for terraform"
vpc = "my-vpc-id"
subnet_ids = ["my-subnet-1-id", "my-subnet-2-id"]
}
3. 执行以下命令,初始化工作目录并下载插件。
		
terraform init
返回信息如下:
		
Initializing the backend...
Initializing provider plugins...
- Finding latest version of tencentcloudstack/tencentcloud...
- Installing tencentcloudstack/tencentcloud v1.77.4...
- Installed tencentcloudstack/tencentcloud v1.77.4 (signed by a HashiCorp partner, key ID 84F69E1C1BECF459)
Partner and community providers are signed by their developers.
If you'd like to know more about provider signing, you can read about it here:
https://www.terraform.io/docs/cli/plugins/signing.html
Terraform has created a lock file .terraform.lock.hcl to record the provider
selections it made above. Include this file in your version control repository
so that Terraform can guarantee to make the same selections by default when
you run "terraform init" in the future.
Terraform has been successfully initialized!
You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.
If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
4. 执行以下命令,创建资源。
		
terraform apply
返回信息如下:

		

Terraform used the selected providers to generate the following execution plan.

Resource actions are indicated with the following symbols:

+ create
Terraform will perform the following actions:
# tencentcloud_tem_environment.environment will be created
+ resource "tencentcloud_tem_environment" "environment" {
+ description = "demo for terraform"
+ environment_name = "test_tf"
+ id = (known after apply)
+ subnet_ids = [
+ "subnet-5ob92rbm",
+ "subnet-dwpro9ni",
]
+ vpc = "vpc-dd5m94px"
}
Plan: 1 to add, 0 to change, 0 to destroy.
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
tencentcloud_tem_environment.environment: Creating...
tencentcloud_tem_environment.environment: Creation complete after 2m37s [id=en-853agv3j]

5. 执行完毕后,您可以在 弹性微服务控制台 查看创建的资源。

编辑环境

以编辑上面所创建的环境名称为示例。
1. main.tf 文件中编辑环境资源信息:
		
resource "tencentcloud_tem_environment" "environment" {
environment_name = "test_tf_renamed"
description = "demo for terraform"
vpc = "my-vpc-id"
subnet_ids = ["my-subnet-1-id", "my-subnet-2-id"]
}
2. 执行 terraform plan 命令更新计划,应返回如下信息:

		
tencentcloud_tem_environment.environment: Refreshing state... [id=en-853agv3j]

Terraform used the selected providers to generate the following execution plan.

Resource actions are indicated with the following symbols:

~ update in-place
Terraform will perform the following actions:
# tencentcloud_tem_environment.environment will be updated in-place
~ resource "tencentcloud_tem_environment" "environment" {
~ environment_name = "test_tf" -> "test_tf_renamed"
id = "my-env-id"
# (3 unchanged attributes hidden)
}
Plan: 0 to add, 1 to change, 0 to destroy.

3. 执行 terraform apply 执行更新了的计划,返回信息如下:

		
tencentcloud_tem_environment.environment: Refreshing state... [id=en-853agv3j]

Terraform used the selected providers to generate the following execution plan.

Resource actions are indicated with the following symbols:

~ update in-place
Terraform will perform the following actions:
# tencentcloud_tem_environment.environment will be updated in-place
~ resource "tencentcloud_tem_environment" "environment" {
~ environment_name = "test_tf" -> "test_tf_renamed"
id = "en-853agv3j"
# (3 unchanged attributes hidden)
}
Plan: 0 to add, 1 to change, 0 to destroy.
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
tencentcloud_tem_environment.environment: Modifying... [id=en-853agv3j]
tencentcloud_tem_environment.environment: Modifications complete after 1s [id=en-853agv3j]
Apply complete! Resources: 0 added, 1 changed, 0 destroyed.

销毁环境

以销毁上面所创建的环境资源为例。
1. 执行以下命令。
		
terraform destroy
2. 销毁成功后返回以下信息。

		

Terraform used the selected providers to generate the following execution plan.

Resource actions are indicated with the following symbols:

- destroy
Terraform will perform the following actions:
# tencentcloud_tem_environment.environment will be destroyed
- resource "tencentcloud_tem_environment" "environment" {
- description = "demo for terraform" -> null
- environment_name = "test_tf_renamed" -> null
- id = "en-853agv3j" -> null
- subnet_ids = [
- "subnet-5ob92rbm",
- "subnet-dwpro9ni",
] -> null
- vpc = "vpc-dd5m94px" -> null
}
Plan: 0 to add, 0 to change, 1 to destroy.
Do you really want to destroy all resources?
Terraform will destroy all your managed infrastructure, as shown above.
There is no undo. Only 'yes' will be accepted to confirm.
Enter a value: yes
tencentcloud_tem_environment.environment: Destroying... [id=en-853agv3j]
tencentcloud_tem_environment.environment: Destruction complete after 2s
Destroy complete! Resources: 1 destroyed.

相似文档
  • 操作场景: 在弹性微服务中,为了帮助您聚焦设计与部署业务应用程序,省去对集群与服务器的考虑,抽象出了应用的概念。 本文介绍如何使用 Terraform 创建应用、部署和删除应用。
  • 操作场景: 若您在使用 Terraform 管理云资源之前,已经通过腾讯云控制台创建了资源,则可参考本文进行操作,将现存资源使用 Terraform 管理。
  • 弹性微服务支持哪些语言? 弹性微服务目前支持 Java 语言的微服务应用,针对非微服务应用,您可以通过制作 Docker 镜像并上传至弹性微服务,助您部署任何语言的应用。
  • 日志中出现乱码,如何解决? 问题描述: 部署至弹性微服务中的业务,如果在日志中显示乱码,一般是由于 locale 的错误配置导致。 遇到这种情况时,可以通过以下方案解决,设置与您应用部署地域相应的编码配置。
  • 为使用腾讯云微服务引擎-弹性微服务(以下简称“本服务”),您应当阅读并遵守《腾讯云微服务引擎-弹性微服务服务等级协议》(以下简称“本协议”或“SLA”),以及《腾讯云服务协议》。本协议包含本服务的术语和定义、服务可用性/服务成功率等级指标、赔偿方案、免责条款等相关内容。除非另有约定,本协议不适用于本服务正在内测的功能,腾讯云对本服务的内测功能不作可用性、服务质量等任何承诺。请您务必审慎阅读、充分理解各条款内容,限制、免责条款或者其他涉及您重大权益的条款可能会以加粗、加下划线等形式提示您重点注意。
官方微信
联系客服
400-826-7010
7x24小时客服热线
分享
  • QQ好友
  • QQ空间
  • 微信
  • 微博
返回顶部