将 Terraform 与 Apigee 搭配使用

Terraform 是一种基础架构即代码 (IaC) 工具,可用于通过代码预配和配置 Apigee。

将 Terraform 与 Apigee 搭配使用时,您需要创建 Terraform 文件,其中描述了您希望在预配或功能方面实现的配置。当您应用配置时,Terraform 会创建执行计划并执行配置 Apigee 所需的操作。

本页总结了适用于 Apigee 的 Terraform 功能。如需了解有关将 Terraform 与 Google Cloud搭配使用的一般信息,请参阅 Terraform on Google Cloud 文档

准备工作

如需为 Apigee 项目设置 Terraform,请执行以下操作:

  1. 准备开发环境(Cloud Shell 或本地 shell):

    Cloud Shell

    如需使用已设置 gcloud CLI 和 Terraform 的在线终端,请激活 Cloud Shell。

    Cloud Shell 会话会在页面底部启动,并显示命令行提示符。该会话可能需要几秒钟来完成初始化。

    请注意,Cloud Shell 已集成 Terraform。

    本地 shell

    如需使用本地开发环境,请按照以下步骤操作:

    1. Install the Google Cloud CLI.

    2. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

    3. To initialize the gcloud CLI, run the following command:

      gcloud init
    4. 安装 Terraform
  2. Verify that billing is enabled for your Google Cloud project.

  3. Enable the Cloud Resource Manager and Identity, Access Management (IAM) APIs:

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    gcloud services enable cloudresourcemanager.googleapis.com  iam.googleapis.com
  4. 确保您的 Google Cloud 项目未添加 Google Cloud Platform - Resource Location Restriction 组织政策限制条件

适用于 Apigee 的 Terraform 资源

下表总结了您可以使用适用于 Apigee 的 Terraform 资源管理的功能。此列表可能并不详尽。您可以在 Apigee Terraform GitHub 代码库中找到适用于 Apigee 的所有 Terraform 资源。请务必查看 GitHub 代码库,了解最新功能。

Apigee 特性或功能 Terraform 支持摘要 更多信息
预配 Apigee 使用 Terraform 预配 Apigee 实例。 预配选项
预配 Apigee API Hub 使用 Terraform 配置和管理 API 中心。 使用 Terraform 预配 API Hub
配置 Advanced API Security 配置安全操作和风险评估 v2 的某些方面。 使用 Terraform 配置 Advanced API Security