How do I set a ComponentResource Args to be requir...
# dotnet
How do I set a ComponentResource Args to be required or do conditional checks on the values? I found that I can add the [Input()] attribute on the ResourceArgs of my component but that doesn't seem to do anything. If I don't provide a value it just ends up throwing an error at the resource that was needing the properties value.
Adding a method that just wraps the args in tuple methods does the trick for validating complex requirements. Still trying to see if I can mark args as required vs throwing them all in an if statement.
For custom resources, required properties are usually non-nullable while optional are nullable:
Copy code
[Input("applicationType", required: true)]
public Input<string> ApplicationType { get; set; } = null!;
public Input<double>? DailyDataCapInGb { get; set; }
For component resources, you could enforce the requirement e.g. in the constructor.
Yea mine is a component resource that has a ResourceArgs type for it's arguments.
I guess building the ResourceArgs to be created using a constructor would make sense.
Actually you don’t have to derive from ResourceArgs for compnent resource args AFAIK
yea i figured that. I was just coping some examples trying to see what happens đŸ˜„
So I am using a combination of a constructor for all required fields and then a tuple with if statements to check dynamic fields. Would be nice if the required attribute worked on ComponentResource so they cannot be null.
If I understand you correctly (a code gist could help), we have the same problem with all resources. In C# there’s no real way to mark a property as required.
Yea its a pretty basic ComponentResource that takes an object Args with a bunch of fields. Just trying to make it reusable and include checks to make sure the fields are not null/empty when required for better feedback. Some providers (if in tuples) are even ignored if the property it needs is null without feedback.
In other C# development I have used the RequiredAttribute and similar to make sure class properties are required for like forms and databases, etc.
I wonder if something could be created for Pulumi resource argument properties.
Interesting… How is that RequiredAttribute than used and by whom? Is it picked up by the editor?