Virtual Private Clouds

Overview

You can use this guide to better understand how to create and manage a VPC via the StackPath API.

This guide complements the corresponding API reference for Virtual Private Clouds.

StackPath offers the following API calls:

  • Get all VPCs
  • Create a VPC
  • Get a VPC
  • Delete a VPC (patch)
  • Delete a VPC (delete)
  • Create a network route
  • Get all network routes
  • Update a network route
  • Get a network route
  • Delete a network route
  • Get all subnets
  • Get a subnet
  • Delete a subnet
  • Create a subnet
  • Update a subnet

📘

Note

To learn more , see Create and Manage a VPC Network.

Before you get started

Creating new VPC networks via the API (assuming no previous networks exist on your Stack) will produce a Dual-Stack network that supports IPv4/IPv6. Please use caution when updating your networks because they may inadvertently enable Dual-Stack (IPv4/IPv6).

Due to this behavior, we highly recommend verifying that your workloads are properly configured to handle IPv4/IPv6 network traffic before creating a new workload with the API.

If you do not want to create a workload that supports IPv6 network traffic, then you can manually create an IPv4-only network using within the parameter.

curl -s -X POST https://gateway.stackpath.com/workload/v1/stacks/STACK_ID/workloads \
-H "Authorization: bearer BEARER_TOKEN" \
-H "Content-Type: application/json" \
-d '{
   "workload": {
      "name": "test workload",
      "metadata": {
        "version": "1",
        "annotations": {
          "anycast.platform.stackpath.net": "true"
        }
      },
      "spec": {
        "networkInterfaces": [
          {
            "network": "default",
            "ipFamilies”: [“IPv4”, “IPv6"]
          }
        ],
        "containers": {
          "webserver": {
            "image": "nginx:latest",
            "command": [],
            "ports": {
              "http": {
                "port": 80
              },
              "https": {
                "port": 443
              }
            },
            "resources": {
              "requests": {
                "cpu": "1",
                "memory": "2Gi"
              }
            }
          }
        }
      },
      "targets": {
        "north-america": {
          "spec": {
            "deploymentScope": "cityCode",
            "deployments": {
              "minReplicas": 1,
              "selectors": [
                {
                  "key": "cityCode",
                  "operator": "in",
                  "values": [
                    "DFW","ORD"
                  ]
                }
              ]
            }
          }
        },
        "europe": {
          "spec": {
            "deploymentScope": "cityCode",
            "deployments": {
              "minReplicas": 1,
              "selectors": [
                {
                  "key": "cityCode",
                  "operator": "in",
                  "values": [
                    "FRA","AMS"
                  ]
                }
              ]
            }
          }
        }
      },
      "slug": "test-workload"
    }
}'

Create a workload will also automatically change a VPC network to be Dual-Stack (IPv4/IPv6) when a workload is requested with IPv6 support. Create a workload and Update a VPC network will “update” the network on the IPAM service in these cases.

Understand input parameters

Review the following table to understand how to make each API call.

API callDescriptionInput parameters
(GET) Get all VPCsThis call returns all VPCs for a specific stack.

You can use this call to obtain the network_id for a specific VPC, which you will need for other VPC-related API calls.
To use this call, you must enter a stack_id.

To obtain a stack_id, run the Get all stacks call.
(POST) Create a VPCThis call creates a new VPC.To use this call, you must enter a stack_id.

To obtain a stack_id, run the Get all stacks call.
(GET) Get a VPCThis call returns a specific VPC.To use this call, you enter a:
- stack_id
- network_id

To obtain a stack_id, run the (GET) Get all stacks call.

To obtain a network_id, run the (GET) Get all VPC networks call.
(PATCH) Delete a VPCThis call updates the name of a specific VPC.To use this call, you must enter a:
- stack_id
- network_id

To obtain a stack_id, run the (GET) Get all stacks call.

To obtain a network_id, run the (GET) Get all VPC networks call.
(DELETE) Delete a VPCThis call deletes a specific VPC.

You cannot delete a VPC that is assigned to a workload; you must first delete the workload, and then you can delete the VPC.
To use this call, you must enter a:
- stack_id
- network_id

To obtain a stack_id, run the (GET) Get all stacks call.

To obtain a network_id, run the (GET) Get all VPC networks call.
(POST) Create a network routeThis call creates a route between an existing source workload and an existing target workload.

To use this call, you must have at least 2 existing workloads.
To use this call, you must enter a:

- stack_id
- network_id

To obtain a stack_id, run the (GET) Get all stacks call.

To obtain a network_id, run the (GET) Get all VPC networks call.
(GET) Get all network routesThis call returns all routes associated with a specific VPC.To use this call, you must enter a:

- stack_id
- network_id

To obtain a stack_id, run the (GET) Get all stacks call.

To obtain a network_id, run the (GET) Get all VPC networks call.
(PUT) Update a network routeThis call updates a specific component of a specific route.To use this call, you must enter a:

- stack_id
- network_id
- route_id

To obtain a stack_id, run the (GET) Get all stacks call.

To obtain a network_id, run the (GET) Get all VPC networks call.

To obtain a route_id, run the (GET) Get all network routes call. n
(GET) Get a network routeThis call returns a specific route.To use this call, you must enter a:

- stack_id
- network_id
- route_id

To obtain a stack_id, run the (GET) Get all stacks call.

To obtain a network_id, run the (GET) Get all VPC networks call.

To obtain a route_id, run the (GET) Get all network routes call.
(DELETE) Delete a network routeThis call deletes a specific route.To use this call, you must enter a:

- stack_id
- network_id
- route_id

To obtain a stack_id, run the (GET) Get all stacks call.

To obtain a network_id, run the (GET) Get all VPC networks call.

To obtain a route_id, run the (GET) Get all network routes call.
(GET) Get all subnetsThis call retrieves all subnets for a specified network.To use this call, you must enter a:

- stack_id
- network_id

To obtain a stack_id, run the (GET) Get all stacks call.

To obtain a network_id, run the (GET) Get all VPC networks call.
(GET) Get a subnetThis call retrieves a specified subnet.To use this call, you must enter a:

- stack_id
- network_id
- subnet_id

To obtain a stack_id, run the (GET) Get all stacks call.

To obtain a network_id, run the (GET) Get all VPC networks call.

To obtain a subnet_id, run the (GET) Get all subnets in a network call.
(DELETE) Delete a subnetThis call deletes a specified subnet.To use this call, you must enter a:

- stack_id
- network_id
- subnet_id

To obtain a stack_id, run the (GET) Get all stacks call.

To obtain a network_id, run the (GET) Get all VPC networks call.

To obtain a subnet_id, run the (GET) Get all subnets in a network call.
(POST) Create a subnetThis call creates a subnet for a specific VPC.To use this call, you must enter a:

- stack_id
- network_id

To obtain a stack_id, run the (GET) Get all stacks call.

To obtain a network_id, run the (GET) Get all VPC networks call.
(PUT) Update a subnetThis call updates an existing subnet.To use this call, you must enter a:

- stack_id
- network_id
- subnet_id

To obtain a stack_id, run the (GET) Get all stacks call.

To obtain a network_id, run the (GET) Get all VPC networks call.

To obtain a subnet_id, run the (GET) Get all subnets in a network call.

Understand return values

Review the following table to understand specific data in the return.

API callDescription
(GET) Get all VPC networksThe return will display the network_id and slug_id for all VPC networks, which you will need for other VPC network-related API calls.
(POST) Create a VPC networkThe return will display the network_id and slug_id for the newly created VPC network, which you will need for other VPC network-related API calls.
(GET) Get all subnetsThe return will display the id for a specific subnet, which you will need for other subnet-related API calls.

Related documentation

To view API calls for VPC in the StackPath Developer Portal, see Virtual Private Cloud.

To view documentation regarding VPC in the StackPath Control Portal, see Create and Manage VPCs.