"""Tag category + tag via pulumi-vsphere."""

from __future__ import annotations

import os
import uuid

import pulumi
import pulumi_vsphere as vsphere

user = os.environ.get("VSPHERE_USER", "administrator@vsphere.local")
password = os.environ.get("VSPHERE_PASSWORD", "VMware1!")
server = os.environ.get("VSPHERE_SERVER", "api-gateway")
run_id = os.environ.get("TEST_RUN_ID") or uuid.uuid4().hex[:8]

provider = vsphere.Provider(
    "vsphere",
    user=user,
    password=password,
    vsphere_server=server,
    allow_unverified_ssl=True,
)
opts = pulumi.ResourceOptions(provider=provider)

category = vsphere.TagCategory(
    "lab-category",
    name=f"pulumi-cat-{run_id}",
    description="pulumi-tests",
    cardinality="MULTIPLE",
    associable_types=["VirtualMachine"],
    opts=opts,
)

tag = vsphere.Tag(
    "lab-tag",
    name=f"pulumi-tag-{run_id}",
    description="pulumi-tests",
    category_id=category.id,
    opts=opts,
)

pulumi.export("category_id", category.id)
pulumi.export("category_name", category.name)
pulumi.export("tag_id", tag.id)
pulumi.export("tag_name", tag.name)
