Skip to content

Relationship Base Type

A Relationship is an extension resource that records a connection from a source ARM resource to a target ARM resource. Import the Relationship base-type namespace:

using Azure.ResourceManager.BaseTypes.Relationships;

Derive your property bag from RelationshipProperties. It provides the ARM-managed base-type descriptor, source and target resource and tenant identifiers, and a read-only provisioning state. You can supply a service-specific provisioning-state union and add service-specific metadata:

@Azure.Core.lroStatus
union DependencyOfProvisioningState {
ResourceProvisioningState,
Accepted: "Accepted",
Provisioning: "Provisioning",
Deleting: "Deleting",
string,
}
model DependencyOfMetadata {
sourceType: string;
targetType: string;
description?: string;
}
model DependencyOfProperties
is RelationshipProperties<ProvisioningState = DependencyOfProvisioningState> {
/** Service-specific metadata about the relationship. */
metadata: DependencyOfMetadata;
}

The Relationship<Properties> template creates an extension resource and automatically applies @azureBaseType for the Relationship contract. Add the standard resource-name spread. Override its defaults only when your API requires a different key, path segment, or pattern:

#suppress "@azure-tools/typespec-azure-resource-manager/basetypes-experimental" "Experimental BaseTypes"
model DependencyOf is Relationship<DependencyOfProperties> {
...ResourceNameParameter<DependencyOf>;
}

The use-relationship-required-properties rule validates that Relationship base-type declarations are extension resources with the required Relationship schema.

Use the extension operation templates so the relationship can target the required source scope:

interface DependencyOfOps<Scope extends Azure.ResourceManager.Foundations.SimpleResource> {
get is Extension.Read<Scope, DependencyOf>;
create is Extension.CreateOrReplaceAsync<Scope, DependencyOf>;
update is Extension.CustomPatchAsync<
Scope,
DependencyOf,
Azure.ResourceManager.Foundations.ResourceUpdateModel<DependencyOf, DependencyOfProperties>
>;
delete is Extension.DeleteWithoutOkAsync<Scope, DependencyOf>;
list is Extension.ListByTarget<Scope, DependencyOf>;
}
@armResourceOperations
interface DependencyOfRelationships extends DependencyOfOps<Extension.ScopeParameter> {}

For a complete working specification, see the Relationship Base Type sample.