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 v1 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-12 UTC."],[[["\u003cp\u003eThe \u003ccode\u003eExecResource\u003c/code\u003e class within the Google Cloud OS Config v1 API allows for the execution of scripts on virtual machines (VMs) for configuration management.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eExecResource\u003c/code\u003e operates in two stages, \u003ccode\u003evalidate\u003c/code\u003e and \u003ccode\u003eenforce\u003c/code\u003e, where each stage takes a script as input to determine or achieve the desired VM state, respectively.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003evalidate\u003c/code\u003e stage checks the current state and returns an exit code of \u003ccode\u003e100\u003c/code\u003e if in the desired state or \u003ccode\u003e101\u003c/code\u003e if not, while \u003ccode\u003eenforce\u003c/code\u003e aims to achieve the desired state and returns \u003ccode\u003e100\u003c/code\u003e upon success, with other codes indicating failures.\u003c/p\u003e\n"],["\u003cp\u003eThe latest version of the documentation for \u003ccode\u003eExecResource\u003c/code\u003e is \u003ccode\u003e2.4.0\u003c/code\u003e, with other previous versions also listed.\u003c/p\u003e\n"],["\u003cp\u003eThe class \u003ccode\u003eOSPolicy.Types.Resource.Types.ExecResource\u003c/code\u003e implements several interfaces, including \u003ccode\u003eIMessage\u003c/code\u003e, \u003ccode\u003eIEquatable\u003c/code\u003e, \u003ccode\u003eIDeepCloneable\u003c/code\u003e, and \u003ccode\u003eIBufferMessage\u003c/code\u003e, and includes properties for \u003ccode\u003eEnforce\u003c/code\u003e and \u003ccode\u003eValidate\u003c/code\u003e actions.\u003c/p\u003e\n"]]],[],null,["# Google Cloud OS Config v1 API - Class OSPolicy.Types.Resource.Types.ExecResource (2.5.0)\n\nVersion latestkeyboard_arrow_down\n\n- [2.5.0 (latest)](/dotnet/docs/reference/Google.Cloud.OsConfig.V1/latest/Google.Cloud.OsConfig.V1.OSPolicy.Types.Resource.Types.ExecResource)\n- [2.4.0](/dotnet/docs/reference/Google.Cloud.OsConfig.V1/2.4.0/Google.Cloud.OsConfig.V1.OSPolicy.Types.Resource.Types.ExecResource)\n- [2.3.0](/dotnet/docs/reference/Google.Cloud.OsConfig.V1/2.3.0/Google.Cloud.OsConfig.V1.OSPolicy.Types.Resource.Types.ExecResource)\n- [2.2.0](/dotnet/docs/reference/Google.Cloud.OsConfig.V1/2.2.0/Google.Cloud.OsConfig.V1.OSPolicy.Types.Resource.Types.ExecResource)\n- [2.1.0](/dotnet/docs/reference/Google.Cloud.OsConfig.V1/2.1.0/Google.Cloud.OsConfig.V1.OSPolicy.Types.Resource.Types.ExecResource)\n- [2.0.0](/dotnet/docs/reference/Google.Cloud.OsConfig.V1/2.0.0/Google.Cloud.OsConfig.V1.OSPolicy.Types.Resource.Types.ExecResource)\n- [1.8.0](/dotnet/docs/reference/Google.Cloud.OsConfig.V1/1.8.0/Google.Cloud.OsConfig.V1.OSPolicy.Types.Resource.Types.ExecResource)\n- [1.7.0](/dotnet/docs/reference/Google.Cloud.OsConfig.V1/1.7.0/Google.Cloud.OsConfig.V1.OSPolicy.Types.Resource.Types.ExecResource)\n- [1.6.0](/dotnet/docs/reference/Google.Cloud.OsConfig.V1/1.6.0/Google.Cloud.OsConfig.V1.OSPolicy.Types.Resource.Types.ExecResource)\n- [1.5.0](/dotnet/docs/reference/Google.Cloud.OsConfig.V1/1.5.0/Google.Cloud.OsConfig.V1.OSPolicy.Types.Resource.Types.ExecResource)\n- [1.4.0](/dotnet/docs/reference/Google.Cloud.OsConfig.V1/1.4.0/Google.Cloud.OsConfig.V1.OSPolicy.Types.Resource.Types.ExecResource)\n- [1.3.0](/dotnet/docs/reference/Google.Cloud.OsConfig.V1/1.3.0/Google.Cloud.OsConfig.V1.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 v1 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.V1/latest/Google.Cloud.OsConfig.V1.OSPolicy)[Types](/dotnet/docs/reference/Google.Cloud.OsConfig.V1/latest/Google.Cloud.OsConfig.V1.OSPolicy.Types)[Resource](/dotnet/docs/reference/Google.Cloud.OsConfig.V1/latest/Google.Cloud.OsConfig.V1.OSPolicy.Types.Resource)[Types](/dotnet/docs/reference/Google.Cloud.OsConfig.V1/latest/Google.Cloud.OsConfig.V1.OSPolicy.Types.Resource.Types)[ExecResource](/dotnet/docs/reference/Google.Cloud.OsConfig.V1/latest/Google.Cloud.OsConfig.V1.OSPolicy.Types.Resource.Types.ExecResource), [IEquatable](https://learn.microsoft.com/dotnet/api/system.iequatable-1)[OSPolicy](/dotnet/docs/reference/Google.Cloud.OsConfig.V1/latest/Google.Cloud.OsConfig.V1.OSPolicy)[Types](/dotnet/docs/reference/Google.Cloud.OsConfig.V1/latest/Google.Cloud.OsConfig.V1.OSPolicy.Types)[Resource](/dotnet/docs/reference/Google.Cloud.OsConfig.V1/latest/Google.Cloud.OsConfig.V1.OSPolicy.Types.Resource)[Types](/dotnet/docs/reference/Google.Cloud.OsConfig.V1/latest/Google.Cloud.OsConfig.V1.OSPolicy.Types.Resource.Types)[ExecResource](/dotnet/docs/reference/Google.Cloud.OsConfig.V1/latest/Google.Cloud.OsConfig.V1.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.V1/latest/Google.Cloud.OsConfig.V1.OSPolicy)[Types](/dotnet/docs/reference/Google.Cloud.OsConfig.V1/latest/Google.Cloud.OsConfig.V1.OSPolicy.Types)[Resource](/dotnet/docs/reference/Google.Cloud.OsConfig.V1/latest/Google.Cloud.OsConfig.V1.OSPolicy.Types.Resource)[Types](/dotnet/docs/reference/Google.Cloud.OsConfig.V1/latest/Google.Cloud.OsConfig.V1.OSPolicy.Types.Resource.Types)[ExecResource](/dotnet/docs/reference/Google.Cloud.OsConfig.V1/latest/Google.Cloud.OsConfig.V1.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.V1](/dotnet/docs/reference/Google.Cloud.OsConfig.V1/latest/Google.Cloud.OsConfig.V1)\n\nAssembly\n--------\n\nGoogle.Cloud.OsConfig.V1.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\nstate. An exit code of 100 indicates \"in desired state\", and exit code\nof 101 indicates \"not in desired state\". Any other exit code indicates\na failure running validate."]]