Skip to content

Add Relationship Base Type - #4892

Open
alexchro93 wants to merge 12 commits into
mainfrom
chrostow/base-rel
Open

Add Relationship Base Type#4892
alexchro93 wants to merge 12 commits into
mainfrom
chrostow/base-rel

Conversation

@alexchro93

Copy link
Copy Markdown
Member

This PR introduces a base type for namespace Microsoft.Relationships. Relationships are extension resources used to establish a connection between a source ARM resource and target ARM resource.

Notably, two relationship types exist in a public preview state in ARM today: serviceGroupMember and dependencyOf.

The implementation of the Microsoft.Relationships base type is heavily inspired by the only other existing base type current: agent.

The relationship type is meant to be a lightweight ARM resources (meaning the resource payload has minimal properties and only really carries references to other ARM resources), however implementations of the relationship base type can new metadata about a relationship through extending the RelationshipMetadata model

Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com

Copilot-Session: 8a6e07d6-3bd4-4373-b9a2-88ad69127fcf

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 8a6e07d6-3bd4-4373-b9a2-88ad69127fcf
@microsoft-github-policy-service microsoft-github-policy-service Bot added int:azure-specs Run integration tests against azure-rest-api-specs lib:azure-resource-manager Issues for @azure-tools/typespec-azure-core library meta:website TypeSpec.io updates linter Issues related to linter rules labels Jul 14, 2026
Comment thread packages/typespec-azure-resource-manager/lib/base-types/relationship.tsp Outdated
Comment thread packages/typespec-azure-resource-manager/lib/base-types/relationship.tsp Outdated
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: bd00581e-a610-4edb-8426-dfc6dd89cedb
@alexchro93
alexchro93 marked this pull request as ready for review July 14, 2026 19:54
@azure-sdk-automation

azure-sdk-automation Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • @azure-tools/typespec-azure-resource-manager
  • @azure-tools/typespec-azure-rulesets
Show changes

@azure-tools/typespec-azure-resource-manager - feature ✏️

Add the experimental Relationship base type for Azure Resource Manager extension resources. RelationshipProperties provides the baseTypes descriptor, source and target resource and tenant identifiers, and provisioning state. Resource providers can extend this property bag with relationship-specific information and expose the relationship against any ARM resource scope.,> ,> Example of creating a dependency relationship with RP-specific metadata and operations:,> ,> typespec,> using Azure.ResourceManager;,> using Azure.ResourceManager.BaseTypes.Relationships;,> ,> model DependencyOfMetadata {,> sourceType: string;,> targetType: string;,> description?: string;,> },> ,> model DependencyOfProperties is RelationshipProperties {,> metadata: DependencyOfMetadata;,> },> ,> #suppress "@azure-tools/typespec-azure-resource-manager/basetypes-experimental" "Experimental BaseTypes",> model DependencyOf is Relationship<DependencyOfProperties> {,> ...ResourceNameParameter<,> Resource = DependencyOf,,> KeyName = "relationshipName",,> SegmentName = "dependencyOf",,> NamePattern = "^[a-zA-Z0-9_.-]{1,64}$",> >;,> },> ,> 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>;,> },>

@azure-tools/typespec-azure-rulesets - feature ✏️

Add the experimental Relationship base type for Azure Resource Manager extension resources. RelationshipProperties provides the baseTypes descriptor, source and target resource and tenant identifiers, and provisioning state. Resource providers can extend this property bag with relationship-specific information and expose the relationship against any ARM resource scope.,> ,> Example of creating a dependency relationship with RP-specific metadata and operations:,> ,> typespec,> using Azure.ResourceManager;,> using Azure.ResourceManager.BaseTypes.Relationships;,> ,> model DependencyOfMetadata {,> sourceType: string;,> targetType: string;,> description?: string;,> },> ,> model DependencyOfProperties is RelationshipProperties {,> metadata: DependencyOfMetadata;,> },> ,> #suppress "@azure-tools/typespec-azure-resource-manager/basetypes-experimental" "Experimental BaseTypes",> model DependencyOf is Relationship<DependencyOfProperties> {,> ...ResourceNameParameter<,> Resource = DependencyOf,,> KeyName = "relationshipName",,> SegmentName = "dependencyOf",,> NamePattern = "^[a-zA-Z0-9_.-]{1,64}$",> >;,> },> ,> 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>;,> },>

@pkg-pr-new

pkg-pr-new Bot commented Jul 14, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@azure-tools/typespec-azure-resource-manager@4892
npm i https://pkg.pr.new/@azure-tools/typespec-azure-rulesets@4892

commit: a0c3467

@azure-sdk-automation

Copy link
Copy Markdown
Contributor

You can try these changes here

🛝 Playground 🌐 Website

@markcowl markcowl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also wonder if we want a resource type for this, especially if it is required to be an extension.

Comment thread packages/samples/specs/resource-manager/resource-types/relationship/main.tsp Outdated
Comment thread packages/samples/specs/resource-manager/resource-types/relationship/main.tsp Outdated
Comment thread packages/samples/specs/resource-manager/resource-types/relationship/main.tsp Outdated
Comment thread packages/typespec-azure-resource-manager/lib/base-types/relationship.tsp Outdated
Comment thread packages/typespec-azure-resource-manager/lib/base-types/relationship.tsp Outdated
}

const missing = [
"sourceId",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should either create templates for these types, or we should have a type that defines the required properties and a decorator that indicates what is required (property exists, optionality, etc.) and use this to drive the linting rule

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Essentially, if we have a `@baseTypeProperty decorator, which took a base type kind and version, we could have an internal-only type (or a set of them) that defined the required properties.

@alexchro93

Copy link
Copy Markdown
Member Author

I also wonder if we want a resource type for this, especially if it is required to be an extension.

@markcowl, can you please explain what you mean by this?

Comment thread packages/typespec-azure-resource-manager/lib/base-types/relationship.tsp Outdated
Comment thread packages/typespec-azure-resource-manager/lib/base-types/relationship.tsp Outdated
Comment thread .chronus/changes/add-relationship-base-type-2026-7-10-17-13-0.md Outdated
sourceTenant: string;

/** The relationship target identifier. */
targetId: string;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the Agent types, we split these into Appliance and UserDefined templates, with the appliance type having readOnly properties. If we are considering making some of these readOnly, it is easiest to make this part of the Appliance template

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some relationship types should mark targetId and targetTenant as readonly while other relationship types mark sourceId and sourceTenant as readonly. For this reason, I didn't specify either set of properties as readonly in this single base class.

Do you think it's better to have a split like agent into a base relationship with readonly source id/tenant and another with readonly target id/tenant?

@alexchro93
alexchro93 requested a review from xirzec as a code owner July 28, 2026 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

int:azure-specs Run integration tests against azure-rest-api-specs lib:azure-resource-manager Issues for @azure-tools/typespec-azure-core library linter Issues related to linter rules meta:website TypeSpec.io updates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants