本文介绍如何使用Terraform添加云防火墙成员账号。
注意事项
Terraform运行环境:阿里云Cloud Shell
Terraform版本:0.12
alicloud版本:1.203.0
resource定义:cloud_firewall_instance_member
前提条件
已创建阿里云账号和访问密钥(AccessKey)。具体操作,请参见创建AccessKey。
已经安装并配置了Terraform。
添加云防火墙成员账号
在Terraform执行目录下的
terraform.tf
文件中,配置如下内容。代码示例如下:
provider "alicloud" { version = "~> 1.203.0" } resource "alicloud_cloud_firewall_instance_member" "default" { member_desc = "Added memberUid by Terraform" member_uid = 180998553943**** }
运行
terraform init
,对环境进行初始化。代码示例如下:
Initializing the backend... Initializing provider plugins... - Checking for available provider plugins... - Downloading plugin for provider "alicloud" (hashicorp/alicloud) 1.203.0... Warning: registry.terraform.io: For users on Terraform 0.13 or greater, this provider has moved to aliyun/alicloud. Please update your source in required_providers. 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.
运行
terraform apply
。出现如下配置信息后,确认配置信息并输入yes,开始创建。代码示例如下:
Terraform will perform the following actions: # alicloud_cloud_firewall_instance_member.default will be created + resource "alicloud_cloud_firewall_instance_member" "default" { + create_time = (known after apply) + id = (known after apply) + member_desc = "Added memberUid by Terraform" + member_display_name = (known after apply) + member_uid = "180998553943****" + modify_time = (known after apply) + status = (known after apply) } 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 alicloud_cloud_firewall_instance_member.default: Creating... alicloud_cloud_firewall_instance_member.default: Creation complete after 9s [id=180998553943****] Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
创建成功后,可以返回成员账号ID为180998553943****。
查看结果。
运行
terraform show
查看云防火墙成员账号详细信息。# alicloud_cloud_firewall_instance_member.default: resource "alicloud_cloud_firewall_instance_member" "default" { create_time = 1681899524 id = "180998553943****" member_desc = "Added memberUid by Terraform" member_display_name = "beaver_qa3" member_uid = "180998553943****" modify_time = 1681899524 status = "normal" }
登录云防火墙控制台,在系统设置>多账号统一管理页面,查看云防火墙成员账号详细信息。