使用Terraform管理Hologres资源,无需手动操作,确保了一致性和可重复性,简化了基础设施的配置和维护过程,减少了潜在的人为错误,提供了更高效、可靠的基础设施管理体验。
背景信息
Terraform是一种基础设施即代码(Infrastructure as Code)工具,旨在帮助开发人员和运维团队自动化基础设施的创建、管理和部署。更多信息,请参见什么是Terraform。
Terraform是一个管理IT资源的客户端工具,您可以使用Terraform提供的命令来实现对所有资源的管理。关于资源和状态管理常用命令详情,请参见基础知识。
安装与配置Terraform
使用Terraform创建Hologres实例
本文以创建8核32 GB规格的通用型Hologres实例为例,介绍Terraform的应用。关于更多alicloud_hologres_instance参数介绍详情和操作,请参见Terraform教程。
在Terraform执行目录下,创建并配置
terraform.tf
文件。配置内容示例如下:需要创建VPC和交换机
resource "alicloud_vpc" "defaultVpc" { cidr_block = "172.16.0.0/12" vpc_name = var.name region = "cn-hangzhou" } resource "alicloud_vswitch" "defaultVSwitch" { vpc_id = alicloud_vpc.defaultVpc.id zone_id = "cn-hangzhou-j" cidr_block = "172.16.53.0/24" vswitch_name = var.name } resource "alicloud_hologram_instance" "default" { instance_type = "Standard" pricing_cycle = "Hour" cpu = "8" endpoints { type = "Intranet" } endpoints { type = "VPCSingleTunnel" vswitch_id = alicloud_vswitch.defaultVSwitch.id vpc_id = alicloud_vswitch.defaultVSwitch.vpc_id } zone_id = alicloud_vswitch.defaultVSwitch.zone_id instance_name = holoname payment_type = "PayAsYouGo" }
使用已有的VPC和交换机
resource "alicloud_hologram_instance" "default" { instance_type = "Standard" pricing_cycle = "Hour" cpu = "8" endpoints { type = "Intranet" } endpoints { type = "VPCSingleTunnel" vswitch_id = "vsw-bp17jg7wr6s3pzbfe****" vpc_id = "vpc-bp1s37ltnbvxgcqf****" } zone_id = "cn-hangzhou-j" instance_name = "holoname" payment_type = "PayAsYouGo" }
执行
terraform apply
,创建实例。出现如下配置信息后,确认配置信息并输入yes,开始创建。
alicloud_hologram_instance.holoname: Refreshing state... [id=hgpostcn-cn-lbj3irszm00h] 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: # alicloud_hologram_instance.holoname will be updated in-place ~ resource "alicloud_hologram_instance" "holoname" { ~ cpu = 8 -> 1 id = "hgpostcn-cn-lbj3irsz****" ~ instance_name = "create-by-ros" -> "holoname" tags = {} # (10 unchanged attributes hidden) - endpoints { - enabled = true -> null - endpoint = "hgpostcn-cn-lbj3irsz****-cn-hangzhou-internal.hologres.aliyuncs.com:80" -> null - type = "Intranet" -> null } # (1 unchanged block 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:
返回类似如下日志时,表示创建成功。
alicloud_hologram_instance.holoname: Modifying... [id=hgpostcn-cn-lbj3irsz****] alicloud_hologram_instance.holoname: Still modifying... [id=hgpostcn-cn-lbj3irsz****, 10s elapsed] ... alicloud_hologram_instance.holoname: Modifications complete after 3m13s [id=hgpostcn-cn-lbj3irsz****] Apply complete! Resources: 0 added, 1 changed, 0 destroyed.
查看结果。
执行
terraform show
查看Hologres实例信息。# alicloud_hologram_instance.holoname: resource "alicloud_hologram_instance" "holoname" { cold_storage_size = 0 cpu = 8 create_time = "2023-12-13T02:55:00.721Z" gateway_count = 0 id = "hgpostcn-cn-lbj3irsz****" instance_name = "holoname" instance_type = "Standard" payment_type = "PayAsYouGo" pricing_cycle = "Hour" resource_group_id = "rg-acfmygmtrce****" status = "Running" storage_size = 0 tags = {} zone_id = "cn-hangzhou-j" endpoints { enabled = true endpoint = "hgpostcn-cn-lbj3irsz****-cn-hangzhou-vpc-st.hologres.aliyuncs.com:80" type = "VPCSingleTunnel" vpc_id = "vpc-bp1s37ltnbvxgcqfc****" vpc_instance_id = "hgpostcn-cn-lbj3irsz****-frontend-st" vswitch_id = "vsw-bp17jg7wr6s3pzbfe****" } }
访问Hologres实例列表,查看Hologres实例信息。
文档内容是否对您有帮助?