public sealed class OSPolicy.Types.Resource.Types.ExecResource : IMessage<OSPolicy.Types.Resource.Types.ExecResource>, IEquatable<OSPolicy.Types.Resource.Types.ExecResource>, IDeepCloneable<OSPolicy.Types.Resource.Types.ExecResource>, IBufferMessage, IMessage
Reference documentation and code samples for the Google Cloud OS Config v1alpha API class OSPolicy.Types.Resource.Types.ExecResource.
A resource that allows executing scripts on the VM.
The ExecResource has 2 stages: validate and enforce and both stages
accept a script as an argument to execute.
When the ExecResource is applied by the agent, it first executes the
script in the validate stage. The validate stage can signal that the
ExecResource is already in the desired state by returning an exit code
of 100. If the ExecResource is not in the desired state, it should
return an exit code of 101. Any other exit code returned by this stage
is considered an error.
If the ExecResource is not in the desired state based on the exit code
from the validate stage, the agent proceeds to execute the script from
the enforce stage. If the ExecResource is already in the desired
state, the enforce stage will not be run.
Similar to validate stage, the enforce stage should return an exit
code of 100 to indicate that the resource in now in its desired state.
Any other exit code is considered an error.
NOTE: An exit code of 100 was chosen over 0 (and 101 vs 1) to
have an explicit indicator of in desired state, not in desired state
and errors. Because, for example, Powershell will always return an exit
code of 0 unless an exit statement is provided in the script. So, for
reasons of consistency and being explicit, exit codes 100 and 101
were chosen.
public OSPolicy.Types.Resource.Types.ExecResource.Types.Exec Enforce { get; set; }
What to run to bring this resource into the desired state.
An exit code of 100 indicates "success", any other exit code indicates
a failure running enforce.
public OSPolicy.Types.Resource.Types.ExecResource.Types.Exec Validate { get; set; }
Required. What to run to validate this resource is in the desired state.
An exit code of 100 indicates "in desired state", and exit code of 101
indicates "not in desired state". Any other exit code indicates a
failure running validate.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["\u003cp\u003eThe \u003ccode\u003eOSPolicy.Types.Resource.Types.ExecResource\u003c/code\u003e class allows the execution of scripts on virtual machines (VMs) within the Google Cloud OS Config v1alpha API.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eExecResource\u003c/code\u003e has two stages, \u003ccode\u003evalidate\u003c/code\u003e and \u003ccode\u003eenforce\u003c/code\u003e, where each stage involves executing a script.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003evalidate\u003c/code\u003e stage determines if the \u003ccode\u003eExecResource\u003c/code\u003e is in the desired state, using exit codes 100 for "in desired state" and 101 for "not in desired state".\u003c/p\u003e\n"],["\u003cp\u003eIf \u003ccode\u003evalidate\u003c/code\u003e determines the resource is not in the desired state, the \u003ccode\u003eenforce\u003c/code\u003e stage is executed to bring it to the desired state, and an exit code of 100 from \u003ccode\u003eenforce\u003c/code\u003e indicates success.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eExecResource\u003c/code\u003e class implements multiple interfaces, including \u003ccode\u003eIMessage\u003c/code\u003e, \u003ccode\u003eIEquatable\u003c/code\u003e, \u003ccode\u003eIDeepCloneable\u003c/code\u003e, and \u003ccode\u003eIBufferMessage\u003c/code\u003e, providing extensive functionality and compatibility.\u003c/p\u003e\n"]]],[],null,["# Google Cloud OS Config v1alpha API - Class OSPolicy.Types.Resource.Types.ExecResource (2.0.0-alpha06)\n\nVersion latestkeyboard_arrow_down\n\n- [2.0.0-alpha06 (latest)](/dotnet/docs/reference/Google.Cloud.OsConfig.V1Alpha/latest/Google.Cloud.OsConfig.V1Alpha.OSPolicy.Types.Resource.Types.ExecResource)\n- [2.0.0-alpha05](/dotnet/docs/reference/Google.Cloud.OsConfig.V1Alpha/2.0.0-alpha05/Google.Cloud.OsConfig.V1Alpha.OSPolicy.Types.Resource.Types.ExecResource)\n- [1.0.0-alpha04](/dotnet/docs/reference/Google.Cloud.OsConfig.V1Alpha/1.0.0-alpha04/Google.Cloud.OsConfig.V1Alpha.OSPolicy.Types.Resource.Types.ExecResource) \n\n public sealed class OSPolicy.Types.Resource.Types.ExecResource : IMessage\u003cOSPolicy.Types.Resource.Types.ExecResource\u003e, IEquatable\u003cOSPolicy.Types.Resource.Types.ExecResource\u003e, IDeepCloneable\u003cOSPolicy.Types.Resource.Types.ExecResource\u003e, IBufferMessage, IMessage\n\nReference documentation and code samples for the Google Cloud OS Config v1alpha API class OSPolicy.Types.Resource.Types.ExecResource.\n\nA resource that allows executing scripts on the VM.\n\nThe `ExecResource` has 2 stages: `validate` and `enforce` and both stages\naccept a script as an argument to execute.\n\nWhen the `ExecResource` is applied by the agent, it first executes the\nscript in the `validate` stage. The `validate` stage can signal that the\n`ExecResource` is already in the desired state by returning an exit code\nof `100`. If the `ExecResource` is not in the desired state, it should\nreturn an exit code of `101`. Any other exit code returned by this stage\nis considered an error.\n\nIf the `ExecResource` is not in the desired state based on the exit code\nfrom the `validate` stage, the agent proceeds to execute the script from\nthe `enforce` stage. If the `ExecResource` is already in the desired\nstate, the `enforce` stage will not be run.\nSimilar to `validate` stage, the `enforce` stage should return an exit\ncode of `100` to indicate that the resource in now in its desired state.\nAny other exit code is considered an error.\n\nNOTE: An exit code of `100` was chosen over `0` (and `101` vs `1`) to\nhave an explicit indicator of `in desired state`, `not in desired state`\nand errors. Because, for example, Powershell will always return an exit\ncode of `0` unless an `exit` statement is provided in the script. So, for\nreasons of consistency and being explicit, exit codes `100` and `101`\nwere chosen. \n\nInheritance\n-----------\n\n[object](https://learn.microsoft.com/dotnet/api/system.object) \\\u003e OSPolicy.Types.Resource.Types.ExecResource \n\nImplements\n----------\n\n[IMessage](https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.IMessage-1.html)[OSPolicy](/dotnet/docs/reference/Google.Cloud.OsConfig.V1Alpha/latest/Google.Cloud.OsConfig.V1Alpha.OSPolicy)[Types](/dotnet/docs/reference/Google.Cloud.OsConfig.V1Alpha/latest/Google.Cloud.OsConfig.V1Alpha.OSPolicy.Types)[Resource](/dotnet/docs/reference/Google.Cloud.OsConfig.V1Alpha/latest/Google.Cloud.OsConfig.V1Alpha.OSPolicy.Types.Resource)[Types](/dotnet/docs/reference/Google.Cloud.OsConfig.V1Alpha/latest/Google.Cloud.OsConfig.V1Alpha.OSPolicy.Types.Resource.Types)[ExecResource](/dotnet/docs/reference/Google.Cloud.OsConfig.V1Alpha/latest/Google.Cloud.OsConfig.V1Alpha.OSPolicy.Types.Resource.Types.ExecResource), [IEquatable](https://learn.microsoft.com/dotnet/api/system.iequatable-1)[OSPolicy](/dotnet/docs/reference/Google.Cloud.OsConfig.V1Alpha/latest/Google.Cloud.OsConfig.V1Alpha.OSPolicy)[Types](/dotnet/docs/reference/Google.Cloud.OsConfig.V1Alpha/latest/Google.Cloud.OsConfig.V1Alpha.OSPolicy.Types)[Resource](/dotnet/docs/reference/Google.Cloud.OsConfig.V1Alpha/latest/Google.Cloud.OsConfig.V1Alpha.OSPolicy.Types.Resource)[Types](/dotnet/docs/reference/Google.Cloud.OsConfig.V1Alpha/latest/Google.Cloud.OsConfig.V1Alpha.OSPolicy.Types.Resource.Types)[ExecResource](/dotnet/docs/reference/Google.Cloud.OsConfig.V1Alpha/latest/Google.Cloud.OsConfig.V1Alpha.OSPolicy.Types.Resource.Types.ExecResource), [IDeepCloneable](https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.IDeepCloneable-1.html)[OSPolicy](/dotnet/docs/reference/Google.Cloud.OsConfig.V1Alpha/latest/Google.Cloud.OsConfig.V1Alpha.OSPolicy)[Types](/dotnet/docs/reference/Google.Cloud.OsConfig.V1Alpha/latest/Google.Cloud.OsConfig.V1Alpha.OSPolicy.Types)[Resource](/dotnet/docs/reference/Google.Cloud.OsConfig.V1Alpha/latest/Google.Cloud.OsConfig.V1Alpha.OSPolicy.Types.Resource)[Types](/dotnet/docs/reference/Google.Cloud.OsConfig.V1Alpha/latest/Google.Cloud.OsConfig.V1Alpha.OSPolicy.Types.Resource.Types)[ExecResource](/dotnet/docs/reference/Google.Cloud.OsConfig.V1Alpha/latest/Google.Cloud.OsConfig.V1Alpha.OSPolicy.Types.Resource.Types.ExecResource), [IBufferMessage](https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.IBufferMessage.html), [IMessage](https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.IMessage.html) \n\nInherited Members\n-----------------\n\n[object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode) \n[object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype) \n[object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)\n\nNamespace\n---------\n\n[Google.Cloud.OsConfig.V1Alpha](/dotnet/docs/reference/Google.Cloud.OsConfig.V1Alpha/latest/Google.Cloud.OsConfig.V1Alpha)\n\nAssembly\n--------\n\nGoogle.Cloud.OsConfig.V1Alpha.dll\n\nConstructors\n------------\n\n### ExecResource()\n\n public ExecResource()\n\n### ExecResource(ExecResource)\n\n public ExecResource(OSPolicy.Types.Resource.Types.ExecResource other)\n\nProperties\n----------\n\n### Enforce\n\n public OSPolicy.Types.Resource.Types.ExecResource.Types.Exec Enforce { get; set; }\n\nWhat to run to bring this resource into the desired state.\nAn exit code of 100 indicates \"success\", any other exit code indicates\na failure running enforce.\n\n### Validate\n\n public OSPolicy.Types.Resource.Types.ExecResource.Types.Exec Validate { get; set; }\n\nRequired. What to run to validate this resource is in the desired state.\nAn exit code of 100 indicates \"in desired state\", and exit code of 101\nindicates \"not in desired state\". Any other exit code indicates a\nfailure running validate."]]