Terraform

Updated at:

Terraform is an open-source tool for previewing, configuring, and managing cloud infrastructure and resources. You can use Terraform to manage Cloud-native API Gateway resources as code.

Prerequisites

  • You have activated the Cloud-native API Gateway.

  • Prepare a Terraform runtime environment. You can use Terraform in one of the following ways:

    Note

    Use V1.240.0 or later.

Example usage

在阿里云中打开

Quick start

This example creates a pay-as-you-go Cloud-native API Gateway instance.

variable "name" {
  default = "terraform-example"
}

provider "alicloud" {
  region = "cn-hangzhou"
}

data "alicloud_resource_manager_resource_groups" "default" {}

data "alicloud_vpcs" "default" {
  name_regex = "^default-NODELETING$"
}
data "alicloud_vswitches" "default" {
  vpc_id = data.alicloud_vpcs.default.ids.0
}

resource "alicloud_apig_gateway" "default" {
  network_access_config {
    type = "Intranet"
  }

  log_config {
    sls {
      enable = "false"
    }
  }

  resource_group_id = data.alicloud_resource_manager_resource_groups.default.ids.1
  spec              = "apigw.small.x1"
  vpc {
    vpc_id = data.alicloud_vpcs.default.ids.0
  }

  zone_config {
    select_option = "Auto"
  }

  vswitch {
    vswitch_id = data.alicloud_vswitches.default.ids.0
  }
  payment_type = "PayAsYouGo"
  gateway_name = var.name
}

Parameter reference

Parameter

Property

Description

gateway_name

Optional

The name of the gateway.

gateway_type

Optional, ForceNew

The type of the gateway. Valid values:

  • API: API Gateway.

  • AI: AI Gateway.

Note

Supported in V1.260.1 and later.

log_config

Optional, List

Contains the following property:

  • sls: (Optional, List) Contains the following property:

    enable: (Optional) Specifies whether to enable Simple Log Service.

network_access_config

Optional, List

The following items are supported:

type: (Optional) The network access type. Valid values:

  • Internet

  • Intranet

  • InternetAndIntranet

payment_type

Required, ForceNew

The billing method of the resource. Valid values:

  • PayAsYouGo

  • Subscription

resource_group_id

Optional, Computed

The ID of the resource group.

spec

Optional, ForceNew

The instance type of the gateway. Valid values:

  • apigw.dev.x1

  • apigw.small.x1

  • apigw.small.x2

  • apigw.small.x4

  • apigw.medium.x1

  • apigw.medium.x2

  • apigw.medium.x3

  • apigw.large.x1

  • apigw.large.x2

  • apigw.large.x3

  • apigw.large.x4

tags

Optional, Map

The tags of the resource.

vswitch

Optional, ForceNew, List

The virtual switch associated with the gateway. It contains the following property:

vswitch_id: (Optional, ForceNew) The ID of the virtual switch.

vpc

Optional, ForceNew, List

The VPC associated with the gateway. It contains the following property:

vpc_id: (Required, ForceNew) The ID of the VPC network.

zone_config

Required, List

The zone configuration. It contains the following property:

select_option: (Required) The zone option.

zones

Optional, ForceNew, List

A list of zones associated with the gateway. It contains the following properties:

  • vswitch_id: (Optional, ForceNew) The ID of the virtual switch.

  • zone_id: (Optional, ForceNew) The ID of the zone.

Note

Supported in v1.260.1 and later.

Attribute reference

  • id: The unique ID of the resource, which is the gateway instance ID.

  • create_time: The UNIX timestamp when the instance was created, in milliseconds.

  • status: The status of the gateway.

  • vswitch: The virtual switch associated with the gateway.

    • name: The name of the virtual switch.

  • vpc: The virtual private cloud (VPC) associated with the gateway.

    • name: The name of the VPC.

  • zones: A list of zones associated with the gateway.

    • name: The name of the zone.

Timeouts

The timeouts block specifies timeouts for the following operations:

  • create: (Default: 11 minutes) Used when creating the gateway.

  • delete: (Default: 5 minutes) Used when deleting the gateway.

  • update: (Default: 5 minutes) Used when updating the gateway.

Import

Import an API Gateway instance by its instance ID.

$ terraform import alicloud_apig_gateway.example <id>