How to add a connectivity profile to a VPC via API
search cancel

How to add a connectivity profile to a VPC via API

book

Article ID: 442530

calendar_today

Updated On:

Products

VMware NSX

Issue/Introduction

Environment

  • VMware NSX 9.0.x

Resolution

Creation of a VPC via REST API is a two-stage process:

  1. Create a new VPC with no connectivity-profile:
    PATCH https://<nsx-manager-IP>/policy/api/v1/orgs/<org>/projects/<project>/vpcs/<vpc>
    {
        "display_name": "<vpc_display_name>",
        "private_ips": [
            "<IP_CIDR>"
        ]
    }

    ref. PATCH /policy/api/v1/orgs/{org-id}/projects/{project-id}/vpcs/{vpc-id}
     
  2. Confirm the path to the default connectivity-profile:
    GET https://<nsx-manager-IP>/policy/api/v1/orgs/<org>/projects/<project>/vpc-connectivity-profiles/default
     
     
  3. Use the path to the default connectivity profile returned in step (2.), and attach it to the new VPC:
    PATCH https://<nsx-manager-IP>/policy/api/v1/orgs/<org>/projects/<project>/vpcs/<project-name>/attachments/1
    {
        "vpc_connectivity_profile": "/orgs/<org>/projects/<project>/vpc-connectivity-profiles/default"
    }

Alternatively, you can create a VPC using Hierarchical API:

PATCH https://<nsx-manager-IP>/policy/api/v1/orgs/<org>/projects/<project>/infra?enforce_revision_check=true
{
    "resource_type": "OrgRoot",
    "children": [
        {
            "resource_type": "ChildResourceReference",
            "id": "default",
            "target_type": "Org",
            "children": [
                {
                    "resource_type": "ChildResourceReference",
                    "id": "<project>",
                    "target_type": "Project",
                    "children": [
                        {
                            "Vpc": {
                                "vpc_service_profile": "/orgs/<org>/projects/<project_id>/vpc-service-profiles/default",
                                "private_ips": [
                                    "<IP_CIDR>"
                                ],
                                "description": null,
                                "tags": null,
                                "load_balancer_vpc_endpoint": {
                                    "enabled": false
                                },
                                "resource_type": "Vpc",
                                "id": "<vpc-name>",
                                "children": [
                                    {
                                        "VpcAttachment": {
                                            "vpc_connectivity_profile": "/orgs/<org>/projects/<project>/vpc-connectivity-profiles/default",
                                            "resource_type": "VpcAttachment",
                                            "id": "default"
                                        },
                                        "resource_type": "ChildVpcAttachment"
                                    }
                                ]
                            },
                            "resource_type": "ChildVpc"
                        }
                    ]
                }
            ]
        }
    ]
}

Ref. PATCH /policy/api/v1/orgs/{org-id}/projects/{project-id}/infra

Additional Information

VMware NSX REST API guide