使用 Terraform 启用 Access Approval
Terraform 是一种开源的基础架构即代码软件工具,可让您管理访问权限审批请求。借助 Terraform,您可以执行使用 Access Approval API 可执行的所有操作。
本页介绍了如何使用 Terraform 启用 Access Approval。本教程使用 Google Cloud Terraform 提供程序。
目标
本教程介绍了如何创建一个 Terraform 配置文件,以便:
- 设置 Access Approvals 请求通知的电子邮件地址。
- 为所有受支持的 Google Cloud 产品启用 Access Approval。如需查看 Google Cloud 支持 Access Approval 的产品的完整列表,请参阅支持的服务。
准备工作
- 如需使用 Access Approval 和 Access Transparency,您的组织必须满足特定的支持要求。如需了解详情,请参阅使用访问权限审批功能的要求。
- 为您的组织启用 Access Transparency。如需了解详情,请参阅启用 Access Transparency。
- 确保您拥有 Access Approval Config Editor (
roles/accessapproval.configEditor
) Identity and Access Management (IAM) 角色。如需详细了解用于访问审批的 IAM 角色,请参阅访问审批角色。
创建 Google Cloud 项目
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
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 搭配使用
- Google Cloud上的 Terraform 使用入门
- Google Cloud 使用 Cloud Shell 开始使用 Terraform