-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAutoNaming.cs
33 lines (27 loc) · 979 Bytes
/
AutoNaming.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
namespace Pulumi.AzureNextGen
{
internal sealed class AutoNaming
{
internal static ResourceTransformation TransformDelegate { get; } = Transform;
private static ResourceTransformationResult? Transform(ResourceTransformationArgs args)
{
if (!args.Resource.IsAzureNextGenResource() || args.Resource is Provider)
return null;
var nameProperty = args.Args.GetNameProperty();
if (nameProperty == null)
{
Log.Debug($"Not applying auto-naming - could not find a matching name property for the resource args type `{args.Args.GetType()}`");
return null;
}
var existingName = nameProperty.GetValue(args.Args);
if (existingName != null)
{
Log.Debug("Not applying auto-naming - a name is already manually specified");
return null;
}
var clonedArgs = args.Args.Clone();
nameProperty.SetInputValue(clonedArgs, args.Resource.GetResourceName());
return new ResourceTransformationResult(clonedArgs, args.Options);
}
}
}