generated from Avanade/avanade-template
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto tagging with ResourceTransformation (#33)
Signed-off-by: Piotr <[email protected]> Signed-off-by: Piotr <[email protected]> Co-authored-by: Piotr <[email protected]>
- Loading branch information
Showing
2 changed files
with
46 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,29 @@ | ||
// build CoreEx stack | ||
using My.Hr.Infra.Services; | ||
using Pulumi; | ||
|
||
return await Pulumi.Deployment.RunAsync(() => | ||
return await Deployment.RunAsync(() => | ||
{ | ||
// create ans use actual instance of DB Operations service | ||
// create and use actual instance of DB Operations service | ||
return My.Hr.Infra.CoreExStack.ExecuteStackAsync(new DbOperations()); | ||
}, null); | ||
}, new StackOptions | ||
{ | ||
// apply auto-tagging transformation | ||
// https://gist.github.com/dbeattie71/1f8a1a9264ceb8161ad4c49de1ee3bb3 | ||
ResourceTransformations = new System.Collections.Generic.List<ResourceTransformation>{ | ||
(args) => { | ||
var tagsProp = args.Args.GetType().GetProperty("Tags"); | ||
|
||
if(tagsProp?.GetValue(args.Args) is InputMap<string> tags) | ||
{ | ||
Log.Debug("Adding tags to " + args.Resource.GetResourceName()); | ||
|
||
tags.Add("user:Stack", Deployment.Instance.StackName); | ||
tags.Add("user:Project", Deployment.Instance.ProjectName); | ||
tags.Add("App:Name", "CoreEx"); | ||
} | ||
|
||
return new ResourceTransformationResult(args.Args, args.Options); | ||
} | ||
} | ||
}); |