As a Automation Assembler admin, you can use APIs to create a new tag and add it to a Kubernetes zone.

In the following procedure, you use the IaaS API to create a new tag. Then using the CMX API, you create a Kubernetes zone with a supervisor namespace on vSphere and assign the tag to the zone.
Note: To create a Kubernetes zone with a vSphere cloud account, the account must be Tanzu-enabled. When you open a Tanzu-enabled vSphere cloud account in the UI, the cloud account appears with the label Available for Kubernetes deployment.

For information on Tanzu-enabled vSphere integration, see Use Tanzu supervisor clusters and namespaces in Automation Assembler.

Prerequisites

Procedure

  1. Create a new tag with a key/value pair.
    curl -X POST \
      $url/iaas/api/tags?apiVersion=$api_version \
      -H 'Content-Type: application/json' \
      -H "Authorization: Bearer $access_token" \
      -d '{
        "key": "'<your_tag_key>'",
        "value": "'<your_tag_value>'" 
      }' | jq "."
    The response includes a tag ID.
  2. Assign the tag ID variable.
    tag_id='<example-tagID-alphanumeric-string>'
  3. Assign your vSphere cloud account ID to the cloud account ID variable.
    cloud_account_id='<vsphere_cloud_account_ID>'
  4. Use the cloud account ID to create the Kubernetes zone with the tag.
    To associate the Kubernetes zone with a vSphere cloud account you specify "providerType": "VSPHERE_NAMESPACES".
    curl -X POST \
      "$url/cmx/api/resources/k8s-zones" \
      -H 'Content-Type: application/json' \
      -H "Authorization: Bearer $access_token" \
      -d '{
        "name": "<your_k8s_zone_name>",
        "providerId": "'$cloud_account_id'",
        "providerType": "VSPHERE_NAMESPACES",
        "tagIds": [
            "'$tag_id'"
        ]
    }' | jq "."

Example: Create a Kubernetes Zone with a Tag

Create a new tag with key example_tag_key and value example_tag_value. Create a Kubernetes zone named K8s-test-zone with the tag. To create a Kubernetes zone, you must associate it with a cloud account configured for Automation Assembler such as a vSphere cloud account with ID 8d4646bd-d629-4526-9009-10e3d4b66e44.

Assign variables.
Note: If your organization uses an API service that is hosted outside of the United States, your URL variable must include a country abbreviation. See Regional Endpoints for VMware Aria Automation APIs.
$ url='https://api.mgmt.cloud.vmware.com'
$ api_version='2021-07-15'

Create a new tag with the key/value.

$ curl -X POST \
  "$url/iaas/api/tags?apiVersion=$api_version" \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $access_token" \
  -d '{
    "key": "example_tag_key",
    "value": "example_tag_value" 
  }' | jq "."

Examine the response for the tag ID.

{
    "key": "example_tag_key",
    "value": "example_tag_value",
    "id": "a6f324e4-101c-33f6-ac51-d9aaaa020123"
}

Assign a value to the tag ID variable.

$ tag_id1= 'a6f324e4-101c-33f6-ac51-d9aaaa020123'

Assign your vSphere cloud account ID to the cloud account ID variable.

$ cloud_account_id='8d4646bd-d629-4526-9009-10e3d4b66e44'

Create the Kubernetes zone with the tag and the cloud account ID.

$ curl -X POST \
  "$url/cmx/api/resources/k8s-zones" \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $access_token" \
  -d '{
    "name": "k8s-test-zone",
    "providerId": "'$cloud_account_id'",
    "providerType": "VSPHERE_NAMESPACES",
    "tagIds": [
        "'$tag_id1'"
    ]
}' | jq "."

The response shows the Kubernetes zone.

{
    "id": "220a81ba-c8ca-4f01-97bc-6f497576d564",
    "createdMillis": 1674847375758,
    "updatedMillis": 1674847375758,
    "orgId": "20451685-2bf6-4ba4-9ea4-87ee61bd32f8",
    "name": "k8s-test-zone",
    "providerId": "8d4646bd-d629-4526-9009-10e3d4b66e44",
    "providerType": "VSPHERE_NAMESPACES",
    "tagIds": [
        "a6f324e4-101c-33f6-ac51-d9aaaa020123"
    ]
}

If you want to update the Kubernetes zone, assign the Kubernetes zone ID variable.

$ k8s_zone_id='220a81ba-c8ca-4f01-97bc-6f497576d564'

If you want to add another tag, assign another tag ID variable.

$ tag_id2='21ccbdd6-c849-37f3-a784-1f2452cf802d'

Update the Kubernetes zone to add the tag.

Note: When updating the zone, the update deletes any tags that are not included in the request payload. So when making the request, you must include all the tags that will remain assigned to the zone after the update.
$ curl -X PUT \
  "$url/cmx/api/resources/k8s-zones/$k8s_zone_id" \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $access_token" \
  -d '{
    "id": "220a81ba-c8ca-4f01-97bc-6f497576d564",
    "createdMillis": 1674847375758,
    "updatedMillis": 1674847375758,
    "orgId": "20451685-2bf6-4ba4-9ea4-87ee61bd32f8",
    "name": "k8s-test-zone",
    "providerId": "'$cloud_account_id'",
    "providerType": "VSPHERE_NAMESPACES",
    "tagIds": [
        "'$tag_id1'",
        "'$tag_id2'"
    ]
}' | jq "."