Aspirerelease/17.0
Watch Aspire live streamsDocsTry Aspire

Resource

Interfacemarker
📦 Aspire.Hosting v17.0.0

Represents a resource that can be hosted by an application.

type Resource interface{}

Methods

A marker interface declares no methods of its own in Go. Its functions are declared on the concrete types they apply to.

Creates an execution configuration builder for the specified resource.
CreateExecutionConfiguration() ExecutionConfigurationBuilder
ExecutionConfigurationBuilder

The execution configuration builder.

Returns a handle; failures surface later via Err().

methodExcludeFromManifestbuilder
Excludes a resource from being published to the manifest.
ExcludeFromManifest() Resource
Resource

The resource builder.

Returns a handle; failures surface later via Err().

methodExcludeFromMcpbuilder
Exclude the resource from MCP operations using the Aspire MCP server. The resource is excluded from results that return resources, console logs and telemetry.
ExcludeFromMcp() Resource
Resource

The resource builder.

Returns a handle; failures surface later via Err().

Gets the name of the resource from a builder.
GetResourceName() (string, error)
(string, error)

The resource name.

Returns (string, error).

Gets a serialized ATS annotation payload from a resource.
GetSerializedAnnotation(annotationId string) (string, error)
annotationIdstringThe stable annotation identifier.
(string, error)

The serialized JSON payload.

Returns (string, error).

Determines whether a resource has a serialized ATS annotation with the specified ID.
HasSerializedAnnotation(annotationId string) (bool, error)
annotationIdstringThe stable annotation identifier.
(bool, error)

true if the annotation exists; otherwise, false.

Returns (bool, error).

Subscribes to the BeforeResourceStarted event.
OnBeforeResourceStarted(callback func(arg BeforeResourceStartedEvent)) Resource
callbackfunc(arg BeforeResourceStartedEvent)callbackThe callback to invoke when the event fires.
Resource

The resource builder.

Returns a handle; failures surface later via Err().

Subscribes to the InitializeResource event.
OnInitializeResource(callback func(arg InitializeResourceEvent)) Resource
callbackfunc(arg InitializeResourceEvent)callbackThe callback to invoke when the event fires.
Resource

The resource builder.

Returns a handle; failures surface later via Err().

methodOnResourceReadybuilder
Subscribes to the ResourceReady event.
OnResourceReady(callback func(arg ResourceReadyEvent)) Resource
callbackfunc(arg ResourceReadyEvent)callbackThe callback to invoke when the event fires.
Resource

The resource builder.

Returns a handle; failures surface later via Err().

methodOnResourceStoppedbuilder
Subscribes to the ResourceStopped event.
OnResourceStopped(callback func(arg ResourceStoppedEvent)) Resource
callbackfunc(arg ResourceStoppedEvent)callbackThe callback to invoke when the event fires.
Resource

The resource builder.

Returns a handle; failures surface later via Err().

Subscribes to the BeforeStartEvent and invokes the specified callback when an HTTPS certificate is determined to be available for the resource. This is used to conditionally update endpoint URI schemes or perform other HTTPS-related configuration at startup.
SubscribeHttpsEndpointsUpdate(callback func(obj HttpsEndpointUpdateCallbackContext)) Resource
callbackfunc(obj HttpsEndpointUpdateCallbackContext)callbackThe callback to invoke when HTTPS is enabled. Receives an HttpsEndpointUpdateCallbackContext providing access to the service provider, resource, and application model.
Resource

The updated resource builder.

Returns a handle; failures surface later via Err().

Sets a child relationship
WithChildRelationship(child Resource) Resource
childResourceThe child of builder.
Resource

A resource builder.

Returns a handle; failures surface later via Err().

methodWithCommandbuilder
Adds a resource command
WithCommand(
name string,
displayName string,
executeCommand func(arg ExecuteCommandContext) *ExecuteCommandResult,
options ...*WithCommandOptions,
) Resource
namestringThe name of the command. The name uniquely identifies the command.
displayNamestringThe display name visible in UI.
executeCommandfunc(arg ExecuteCommandContext) *ExecuteCommandResultcallbackA callback that is executed when the command is executed. The callback is run inside the Aspire host. The callback result is used to indicate success or failure in the UI.
options...*WithCommandOptionsOptional settings, described under Options.

Optional parameters are passed in a trailing options ...*WithCommandOptions argument.

CommandOptions*CommandOptionsOptional configuration for the command.
Resource

The resource builder.

Returns a handle; failures surface later via Err().

Configures container build options for a compute resource using an async callback.
WithContainerBuildOptions(callback func(arg ContainerBuildOptionsCallbackContext)) Resource
callbackfunc(arg ContainerBuildOptionsCallbackContext)callbackAn async callback to configure container build options.
Resource

A reference to the IResourceBuilder.

Returns a handle; failures surface later via Err().

Configures the resource to use the specified container registry for container image operations.
WithContainerRegistry(registry Resource) Resource
registryResourceThe container registry resource builder.
Resource

The resource builder for chaining.

Returns a handle; failures surface later via Err().

methodWithDisplayOrderbuilder
Sets the default display order of the resource in lists of resources, such as the dashboard's. A saved ordering takes precedence. Repeated calls replace the order.
WithDisplayOrder(order float64) Resource
orderfloat64A relative sort key. Higher values appear first, consistent with DisplayOrder. Resources without a display order are treated as having an order of 0, so a negative value moves a resource after them.
Resource

The resource builder.

Returns a handle; failures surface later via Err().

Configures custom base images for generated Dockerfiles.
WithDockerfileBaseImage(options ...*WithDockerfileBaseImageOptions) Resource
options...*WithDockerfileBaseImageOptionsOptional settings, described under Options.

Optional parameters are passed in a trailing options ...*WithDockerfileBaseImageOptions argument.

BuildImage*stringThe base image to use for the build stage. If null, uses the default build image.
RuntimeImage*stringThe base image to use for the runtime stage. If null, uses the default runtime image.
Resource

The resource builder.

Returns a handle; failures surface later via Err().

methodWithExplicitStartbuilder
Prevents resource from starting automatically
WithExplicitStart() Resource
Resource

The resource builder.

Returns a handle; failures surface later via Err().

methodWithHealthCheckbuilder
Adds a health check by key
WithHealthCheck(key string) Resource
keystringThe key for the health check.
Resource

The resource builder.

Returns a handle; failures surface later via Err().

methodWithHiddenbuilder
Hides the resource from default resource lists
WithHidden() Resource
Resource

The resource builder.

Returns a handle; failures surface later via Err().

Hides the resource from default resource lists after successful completion
WithHiddenOnCompletion(options ...*WithHiddenOnCompletionOptions) Resource
options...*WithHiddenOnCompletionOptionsOptional settings, described under Options.

Optional parameters are passed in a trailing options ...*WithHiddenOnCompletionOptions argument.

ExitCode*float64The completion exit code to treat as successful. Defaults to 0.
ExitCodes[]float64Completion exit codes to treat as successful. If no values are provided, 0 is used.
Resource

The resource builder.

Returns a handle; failures surface later via Err().

methodWithIconNamebuilder
Specifies the icon to use when displaying the resource in the dashboard.
WithIconName(
iconName string,
options ...*WithIconNameOptions,
) Resource
iconNamestringThe name of the FluentUI icon to use. See https://aka.ms/fluentui-system-icons for available icons.
options...*WithIconNameOptionsOptional settings, described under Options.

Optional parameters are passed in a trailing options ...*WithIconNameOptions argument.

IconVariant*IconVariantThe variant of the icon (Regular or Filled). Defaults to Filled.
Resource

The resource builder.

Returns a handle; failures surface later via Err().

methodWithLifetimeOfbuilder
Configures a resource to match the lifetime of another resource.
WithLifetimeOf(sourceBuilder Resource) Resource
sourceBuilderResourceThe resource builder whose lifetime should be used.
Resource

The resource builder.

Returns a handle; failures surface later via Err().

Configures a resource to use a persistent lifetime that ends when a parent process exits.
WithParentProcessLifetime(parentProcessId float64) Resource
parentProcessIdfloat64The ID of the parent process to monitor.
Resource

The resource builder.

Returns a handle; failures surface later via Err().

Sets the parent relationship
WithParentRelationship(parent Resource) Resource
parentResourceThe parent of builder.
Resource

A resource builder.

Returns a handle; failures surface later via Err().

Configures a resource to use a persistent lifetime.
WithPersistentLifetime() Resource
Resource

The resource builder.

Returns a handle; failures surface later via Err().

Registers a callback to be executed during the pipeline configuration phase, allowing modification of step dependencies and relationships.
WithPipelineConfiguration(callback func(obj PipelineConfigurationContext)) Resource
callbackfunc(obj PipelineConfigurationContext)callbackThe callback function to execute during the configuration phase.
Resource

The resource builder for chaining.

Returns a handle; failures surface later via Err().

Adds a pipeline step to the resource that will be executed during deployment.
WithPipelineStepFactory(
stepName string,
callback func(arg PipelineStepContext),
options ...*WithPipelineStepFactoryOptions,
) Resource
stepNamestringThe unique name of the pipeline step.
callbackfunc(arg PipelineStepContext)callbackThe callback to execute when the step runs.
options...*WithPipelineStepFactoryOptionsOptional settings, described under Options.

Optional parameters are passed in a trailing options ...*WithPipelineStepFactoryOptions argument.

DependsOn[]stringOptional step names that this step depends on.
RequiredBy[]stringOptional step names that require this step.
Tags[]stringOptional tags that categorize this step.
Description*stringAn optional human-readable description of the step.
Resource

The resource builder for chaining.

Returns a handle; failures surface later via Err().

methodWithProcessCommandbuilder
Adds a command to the resource that starts a local process when invoked.
WithProcessCommand(
commandName string,
displayName string,
options *ProcessCommandExportOptions,
) Resource
commandNamestring
displayNamestring
options*ProcessCommandExportOptions
Resource

Returns a handle; failures surface later via Err().

Adds a command to the resource that starts a local process created by a callback when invoked.
WithProcessCommandFactory(
commandName string,
displayName string,
createProcessSpec func(arg ExecuteCommandContext) *ProcessCommandSpecExportData,
options ...*ProcessCommandResultExportOptions,
) Resource
commandNamestring
displayNamestring
createProcessSpecfunc(arg ExecuteCommandContext) *ProcessCommandSpecExportDatacallback
options...*ProcessCommandResultExportOptionsOptional settings, described under Options.

Optional parameters are passed as the existing *ProcessCommandResultExportOptions struct.

Resource

Returns a handle; failures surface later via Err().

methodWithRelationshipbuilder
Adds a relationship to another resource using its builder.
WithRelationship(
resourceBuilder Resource,
type_ string,
) Resource
resourceBuilderResourceThe resource builder that the relationship is to.
type_stringThe relationship type.
Resource

A resource builder.

Returns a handle; failures surface later via Err().

methodWithRequiredCommandbuilder
Declares that a resource requires a specific command/executable to be available on the local machine PATH before it can start.
WithRequiredCommand(
command string,
options ...*WithRequiredCommandOptions,
) Resource
commandstringThe command string (file name or path) that should be validated.
options...*WithRequiredCommandOptionsOptional settings, described under Options.

Optional parameters are passed in a trailing options ...*WithRequiredCommandOptions argument.

HelpLink*stringAn optional help link URL to guide users when the command is missing.
Resource

The resource builder.

Returns a handle; failures surface later via Err().

Declares that a resource requires a specific command/executable to be available on the local machine PATH before it can start, with custom validation logic.
WithRequiredCommandValidation(
command string,
validationCallback func(arg RequiredCommandValidationContext) RequiredCommandValidationResult,
options ...*WithRequiredCommandValidationOptions,
) Resource
commandstringThe command string (file name or path) that should be validated.
validationCallbackfunc(arg RequiredCommandValidationContext) RequiredCommandValidationResultcallbackA callback that validates the resolved command path. Receives a RequiredCommandValidationContext and returns a RequiredCommandValidationResult.
options...*WithRequiredCommandValidationOptionsOptional settings, described under Options.

Optional parameters are passed in a trailing options ...*WithRequiredCommandValidationOptions argument.

HelpLink*stringAn optional help link URL to guide users when the command is missing or fails validation.
Resource

The resource builder.

Returns a handle; failures surface later via Err().

Overrides the human-readable resource type label.
WithResourceTypeDisplayName(resourceTypeDisplayName string) Resource
resourceTypeDisplayNamestringThe type label, such as Redis or PostgreSQL Server.
Resource

The resource builder.

Returns a handle; failures surface later via Err().

Stores a serialized ATS annotation payload on a resource, replacing any existing annotation with the same ID.
WithSerializedAnnotation(
annotationId string,
json string,
) Resource
annotationIdstringThe stable annotation identifier.
jsonstringThe serialized JSON payload.
Resource

The resource.

Returns a handle; failures surface later via Err().

methodWithSessionLifetimebuilder
Configures a resource to use a session lifetime.
WithSessionLifetime() Resource
Resource

The resource builder.

Returns a handle; failures surface later via Err().

methodWithTagsbuilder
Adds AppHost-defined dashboard tags that users cannot remove. Repeated calls add tags.
WithTags(tags []string) Resource
tags[]stringThe tags, each up to 50 characters with single spaces between words.
Resource

The resource builder.

Returns a handle; failures surface later via Err().

methodWithTerminalbuilder
Adds an interactive terminal session to a resource with an optional callback to configure its initial dimensions.
WithTerminal(options ...*WithTerminalOptions) Resource
options...*WithTerminalOptionsOptional settings, described under Options.

Optional parameters are passed in a trailing options ...*WithTerminalOptions argument.

Configurefunc(obj *TerminalOptions)callbackAn optional callback to configure the terminal options.
Resource

A reference to the IResourceBuilder for chaining additional configuration.

Returns a handle; failures surface later via Err().

methodWithTraitbuilder
Adds immutable, non-sensitive metadata to a resource. Repeated names add multiple values.
WithTrait(
name string,
value string,
) Resource
namestringThe case-sensitive trait name.
valuestringThe trait value. Do not include secrets.
Resource

The resource builder.

Returns a handle; failures surface later via Err().

methodWithUrlbuilder
Adds or modifies displayed URLs
WithUrl(
url any,
options ...*WithUrlOptions,
) Resource
urlany
options...*WithUrlOptionsOptional settings, described under Options.

Optional parameters are passed in a trailing options ...*WithUrlOptions argument.

DisplayText*string
Resource

Returns a handle; failures surface later via Err().

methodWithUrlForEndpointbuilder
Registers a callback to update the URL displayed for the endpoint with the specified name.
WithUrlForEndpoint(
endpointName string,
callback func(obj *ResourceUrlAnnotation),
) Resource
endpointNamestringThe name of the endpoint to customize the URL for.
callbackfunc(obj *ResourceUrlAnnotation)callbackThe callback that will customize the URL.
Resource

The resource builder.

Returns a handle; failures surface later via Err().

methodWithUrlsbuilder
Registers a callback to customize the URLs displayed for the resource.
WithUrls(callback func(obj ResourceUrlsCallbackContext)) Resource
callbackfunc(obj ResourceUrlsCallbackContext)callbackThe callback that will customize URLs for the resource.
Resource

The resource builder.

Returns a handle; failures surface later via Err().

Applies to

This interface applies to the following types: