Class Resource
- Namespace
- Fabricator.Core
- Assembly
- Fabricator.Core.dll
A resource is a part of the desired environment state that Fabricator is able to check and apply.
[ReferenceEquality]
[CompilationMapping(SourceConstructFlags.RecordType)]
public sealed class Resource
- Inheritance
-
Resource
- Inherited Members
Remarks
Resources are compared by reference: every resource object is a separate resource, even if its contents are equal to some other resource's. The same resource object is checked and applied at most once per execution, no matter how many times it is passed to Fabricator or mentioned in dependencies of other resources.
Since the dependencies of a resource have to exist before the resource itself is created, the dependency graph cannot contain cycles.
Constructors
Resource(string, ImmutableHashSet<Resource>, FSharpFunc<ResourceContext, FSharpAsync<ResourceChange>>, FSharpFunc<ResourceContext, FSharpAsync<ResourceChange>>, FSharpOption<ConcurrencyGroup>?, ImmutableArray<SecretRequest>)
[DynamicDependency(DynamicallyAccessedMemberTypes.PublicFields|DynamicallyAccessedMemberTypes.NonPublicFields|DynamicallyAccessedMemberTypes.PublicProperties|DynamicallyAccessedMemberTypes.NonPublicProperties, typeof(Resource))]
public Resource(string presentableName, ImmutableHashSet<Resource> dependsOn, FSharpFunc<ResourceContext, FSharpAsync<ResourceChange>> alreadyApplied, FSharpFunc<ResourceContext, FSharpAsync<ResourceChange>> apply, FSharpOption<ConcurrencyGroup>? @lock, ImmutableArray<SecretRequest> secrets)
Parameters
presentableNamestringdependsOnImmutableHashSet<Resource>alreadyAppliedFSharpFunc<ResourceContext, FSharpAsync<ResourceChange>>applyFSharpFunc<ResourceContext, FSharpAsync<ResourceChange>>lockFSharpOption<ConcurrencyGroup>secretsImmutableArray<SecretRequest>
Properties
AlreadyApplied
Checks whether the resource is already in its desired state in the current environment. Should return NoChanges if the resource is already applied and requires no further action, or the change required to apply it otherwise.
[CompilationMapping(SourceConstructFlags.Field, 2)]
public FSharpFunc<ResourceContext, FSharpAsync<ResourceChange>> AlreadyApplied { get; }
Property Value
- FSharpFunc<ResourceContext, FSharpAsync<ResourceChange>>
Remarks
The returned change is shown to the user as the change about to be made. Return ChangeWithNoDescription if the resource is not applied, but the change cannot be described.
This function should not change the environment. It may be called concurrently with checks and applications of other resources. While applying, it is only called after all the dependencies from DependsOn are applied.
The passed context is pinned to this check: use its reporter to report the status, progress, and log of the check.
Apply
Brings the resource to its desired state in the current environment. Should return the change that has been made, which is shown to the user.
[CompilationMapping(SourceConstructFlags.Field, 3)]
public FSharpFunc<ResourceContext, FSharpAsync<ResourceChange>> Apply { get; }
Property Value
- FSharpFunc<ResourceContext, FSharpAsync<ResourceChange>>
Remarks
Only called after AlreadyApplied returned a change other than NoChanges, and after all the dependencies from DependsOn are applied (the ones not applied yet are applied first). May be called concurrently with checks and applications of other resources that are not connected to this one via dependencies.
The passed context is pinned to this application: use its reporter to report the status, progress, and log of the application.
DependsOn
The resources this resource depends on. They are not required to be passed to Fabricator explicitly: they are discovered from the resources passed to Fabricator transitively.
[CompilationMapping(SourceConstructFlags.Field, 1)]
public ImmutableHashSet<Resource> DependsOn { get; }
Property Value
Remarks
While applying, the dependencies that are not applied yet get applied before this resource, and this resource is only checked after all its dependencies are in their desired state. If any of the dependencies fails to be checked or applied, this resource is skipped.
While only checking the environment, all the dependencies are checked together with this resource, independently of each other.
Use NoDependencies for resources without dependencies.
Lock
The concurrency group of the resource, or None if the resource can be checked and applied
concurrently with any other resources it's not connected to via dependencies.
[CompilationMapping(SourceConstructFlags.Field, 4)]
public FSharpOption<ConcurrencyGroup>? Lock { get; }
Property Value
- FSharpOption<ConcurrencyGroup>
Remarks
Checks and applications of resources from the same group never run concurrently. Fabricator doesn't keep the group locked between the check and the application of the same resource, so the application should not rely on the environment staying unchanged since the check.
PresentableName
A human-readable name of the resource, used for logging and status reporting.
[CompilationMapping(SourceConstructFlags.Field, 0)]
public string PresentableName { get; }
Property Value
Secrets
The secrets the resource requires. Every secret is passed to the operations of the resource defined by its Mode, via Secrets.
[CompilationMapping(SourceConstructFlags.Field, 5)]
public ImmutableArray<SecretRequest> Secrets { get; }
Property Value
Remarks
Before running any checks or applications, Fabricator opens all the stores of the secrets that might be required by the execution (one by one), and closes them after the execution. Every secret is fetched from its store right before the operation requiring it starts, and disposed right after it finishes. If any store fails to open, the execution fails without checking or applying anything. If a secret fails to be fetched, the operation requiring it fails.
Use NoSecrets for resources without secrets.
Methods
ToString()
public override string ToString()