Terraform
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:
NoteUse
V1.240.0or later.-
Use Terraform in Terraform Explorer: Alibaba Cloud provides an online Terraform runtime environment. You can try Terraform online without installing it.
-
Create resources with Terraform: Terraform components are pre-installed and identity credentials are pre-configured in Cloud Shell. You can run Terraform commands directly in Cloud Shell.
-
Install and configure Terraform locally: Use this method if you have limited network connectivity or need a custom developer environment.
-
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 |
|
|
Optional |
The name of the gateway. |
|
|
Optional, ForceNew |
The type of the gateway. Valid values:
Note
Supported in |
|
|
Optional, List |
Contains the following property:
|
|
|
Optional, List |
The following items are supported:
|
|
|
Required, ForceNew |
The billing method of the resource. Valid values:
|
|
|
Optional, Computed |
The ID of the resource group. |
|
|
Optional, ForceNew |
The instance type of the gateway. Valid values:
|
|
|
Optional, Map |
The tags of the resource. |
|
|
Optional, ForceNew, List |
The virtual switch associated with the gateway. It contains the following property:
|
|
|
Optional, ForceNew, List |
The VPC associated with the gateway. It contains the following property:
|
|
|
Required, List |
The zone configuration. It contains the following property:
|
|
|
Optional, ForceNew, List |
A list of zones associated with the gateway. It contains the following properties:
Note
Supported in |
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>