Terraform 是一种开源基础架构即代码软件工具,可让您管理 Access Approval 请求。借助 Terraform,您可以执行使用 Access Approval API 执行的所有操作。
本页面介绍如何使用 Terraform 启用 Access Approval。本教程使用 Google Cloud Terraform 提供程序。
目标
本教程介绍了如何创建 Terraform 配置文件,以便:
- 设置 Access Approval 请求通知的电子邮件地址。
- 为所有受支持的 Google Cloud 产品启用 Access Approval。如需查看 Access Approval 支持的 Google Cloud 产品的完整列表,请参阅支持的服务。
准备工作
- 如需使用 Access Approval 和 Access Transparency,您的组织必须满足特定的支持要求。如需了解详情,请参阅使用 Access Approval 的要求。
- 为您的组织启用 Access Transparency。如需了解详情,请参阅启用 Access Transparency。
- 确保您具有 Access Approval Config Editor (
roles/accessapproval.configEditor
) Identity and Access Management (IAM) 角色。如需详细了解 Access Approval 的 IAM 角色,请参阅 Access Approval 角色。
创建 Google Cloud 项目
- 登录您的 Google Cloud 账号。如果您是 Google Cloud 新手,请创建一个账号来评估我们的产品在实际场景中的表现。新客户还可获享 $300 赠金,用于运行、测试和部署工作负载。
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Enable the Access Approval API.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Enable the Access Approval API.
安装 Google Cloud CLI
Install the Google Cloud CLI, then initialize it by running the following command:
gcloud init
出现提示时,请选择您之前选择或创建的项目。
如果您已安装 Google Cloud CLI,请使用以下命令进行更新:
gcloud components update
创建 Terraform 配置文件
- 打开 Cloud Shell 以启动独立的 Cloud Shell 会话。
- 打开工作区。
- 创建新文件夹。
- 将名为
main.tf
的 Terraform 配置文件添加到此文件夹。 复制以下资源,并将其粘贴到
main.tf
文件中。main.tf
variable "parent_value" { type = string } variable "email_1" { type = string } variable "email_2" { type = string } resource "google_folder" "my_folder" { display_name = "my-folder" parent = var.parent_value # parent = "organizations/123456789" } resource "google_folder_access_approval_settings" "folder_access_approval" { folder_id = google_folder.my_folder.folder_id notification_emails = [var.email_1, var.email_2] enrolled_services { cloud_product = "all" } }
为以下变量输入值:
email_1
和email_2
:提供您要设为此项目的访问请求审核者的用户的电子邮件地址。
parent_value
:您要在其中创建my_folder
文件夹的文件夹的名称。如需详细了解文件夹,请参阅创建和管理文件夹。
执行 Terraform 配置文件
在 Cloud Shell 中执行以下命令。
在目录中初始化 Terraform。
terraform init
执行创建的 Terraform 配置文件。
terraform apply
当系统提示您确认执行配置文件时,请输入 yes。
如需详细了解如何使用 Terraform 运行 Access Approval,请参阅此 Terraform 文档:google_folder_access_approval_settings。
后续步骤
- 将 Terraform 与 Google Cloud 搭配使用
- 将 Terraform 与 Access Approval 搭配使用
- Terraform on Google Cloud 使用入门
- 使用 Cloud Shell 在 Google Cloud 上快速启动 Terraform