Specifying a cloud network to host an API gateway
You can specify a cloud network to host an API gateway.
A cloud network must have:
- Subnets in all availability zones.
- At least one resource with an IP address in the specified cloud network.
Note
If the network does not meet the conditions above, the service does not guarantee it will function properly.
- In the management console
, navigate to the folder containing the API gateway. - Navigate
to API Gateway. - Select the API gateway.
- Click
Edit. - In the Network field, specify a cloud network to host your API gateway.
- Click Save.
If you do not have the Yandex Cloud CLI yet, install and initialize it.
The folder used by default is the one specified when creating the CLI profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also specify a different folder for any command using --folder-name or --folder-id. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.
-
View the description of the CLI command for updating an API gateway:
yc serverless api-gateway update --help -
Get a list of API gateways in the default folder:
yc serverless api-gateway list -
Specify a cloud network for the API gateway:
yc serverless api-gateway update \ --id <API_gateway_ID> \ --network-name <cloud_network_name>Where:
--id: API gateway ID.--network-name: Name of the cloud network. You can specify the--network-idparameter instead of the network name.
To associate the API gateway with certain subnets, specify them in the
--subnet-idor--subnet-nameparameters instead of specifying a network.
With Terraform
Terraform is distributed under the Business Source License
For more information about the provider resources, see the guides on the Terraform
If you do not have Terraform yet, install it and configure the Yandex Cloud provider.
To manage infrastructure using Terraform under a service account or user accounts (a Yandex account, a federated account, or a local user), authenticate using the appropriate method.
-
Open the Terraform configuration file and add the
connectivitysection to theyandex_api_gatewayresource description:resource "yandex_api_gateway" "test-api-gateway" { name = "<API_gateway_name>" ... connectivity { network_id = "<cloud_network_ID>" } }Where
network_idis the ID of the cloud network to host the API gateway.For more information about the properties of the
yandex_api_gatewayresource, see this provider guide. -
Apply the changes:
-
In the terminal, navigate to the configuration file directory.
-
Make sure the configuration is correct using this command:
terraform validateIf the configuration is valid, you will get this message:
Success! The configuration is valid. -
Run this command:
terraform planYou will see a list of resources and their properties. No changes will be made at this step. Terraform will show any errors in the configuration.
-
Apply the configuration changes:
terraform apply -
Type
yesand press Enter to confirm the changes.
You can check the result using the management console
or this CLI command:yc serverless api-gateway get <API_gateway_ID> -
To specify a cloud network to host an API gateway, use the update REST API method for the ApiGateway resource or the ApiGatewayService/Update gRPC API call.
Set updateMask to connectivity, and connectivity.networkId, to the cloud network ID.