Reference documentation and code samples for the Cloud OS Config V1 API class Google::Cloud::OsConfig::V1::OSPolicy::Resource::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.
(::Google::Cloud::OsConfig::V1::OSPolicy::Resource::ExecResource::Exec) — 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.
value (::Google::Cloud::OsConfig::V1::OSPolicy::Resource::ExecResource::Exec) — 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.
Returns
(::Google::Cloud::OsConfig::V1::OSPolicy::Resource::ExecResource::Exec) — 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"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-09 UTC."],[],[],null,["# Cloud OS Config V1 API - Class Google::Cloud::OsConfig::V1::OSPolicy::Resource::ExecResource (v1.4.0)\n\nVersion latestkeyboard_arrow_down\n\n- [1.4.0 (latest)](/ruby/docs/reference/google-cloud-os_config-v1/latest/Google-Cloud-OsConfig-V1-OSPolicy-Resource-ExecResource)\n- [1.3.0](/ruby/docs/reference/google-cloud-os_config-v1/1.3.0/Google-Cloud-OsConfig-V1-OSPolicy-Resource-ExecResource)\n- [1.2.1](/ruby/docs/reference/google-cloud-os_config-v1/1.2.1/Google-Cloud-OsConfig-V1-OSPolicy-Resource-ExecResource)\n- [1.1.0](/ruby/docs/reference/google-cloud-os_config-v1/1.1.0/Google-Cloud-OsConfig-V1-OSPolicy-Resource-ExecResource)\n- [1.0.1](/ruby/docs/reference/google-cloud-os_config-v1/1.0.1/Google-Cloud-OsConfig-V1-OSPolicy-Resource-ExecResource)\n- [0.16.0](/ruby/docs/reference/google-cloud-os_config-v1/0.16.0/Google-Cloud-OsConfig-V1-OSPolicy-Resource-ExecResource)\n- [0.15.2](/ruby/docs/reference/google-cloud-os_config-v1/0.15.2/Google-Cloud-OsConfig-V1-OSPolicy-Resource-ExecResource)\n- [0.14.0](/ruby/docs/reference/google-cloud-os_config-v1/0.14.0/Google-Cloud-OsConfig-V1-OSPolicy-Resource-ExecResource)\n- [0.13.0](/ruby/docs/reference/google-cloud-os_config-v1/0.13.0/Google-Cloud-OsConfig-V1-OSPolicy-Resource-ExecResource)\n- [0.12.0](/ruby/docs/reference/google-cloud-os_config-v1/0.12.0/Google-Cloud-OsConfig-V1-OSPolicy-Resource-ExecResource)\n- [0.11.0](/ruby/docs/reference/google-cloud-os_config-v1/0.11.0/Google-Cloud-OsConfig-V1-OSPolicy-Resource-ExecResource)\n- [0.10.0](/ruby/docs/reference/google-cloud-os_config-v1/0.10.0/Google-Cloud-OsConfig-V1-OSPolicy-Resource-ExecResource)\n- [0.9.1](/ruby/docs/reference/google-cloud-os_config-v1/0.9.1/Google-Cloud-OsConfig-V1-OSPolicy-Resource-ExecResource) \nReference documentation and code samples for the Cloud OS Config V1 API class Google::Cloud::OsConfig::V1::OSPolicy::Resource::ExecResource.\n\nA resource that allows executing scripts on the VM.\n\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\n\u003cbr /\u003e\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\nInherits\n--------\n\n- Object \n\nExtended By\n-----------\n\n- Google::Protobuf::MessageExts::ClassMethods \n\nIncludes\n--------\n\n- Google::Protobuf::MessageExts\n\nMethods\n-------\n\n### #enforce\n\n def enforce() -\u003e ::Google::Cloud::OsConfig::V1::OSPolicy::Resource::ExecResource::Exec\n\n**Returns**\n\n- ([::Google::Cloud::OsConfig::V1::OSPolicy::Resource::ExecResource::Exec](./Google-Cloud-OsConfig-V1-OSPolicy-Resource-ExecResource-Exec)) --- 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.\n\n### #enforce=\n\n def enforce=(value) -\u003e ::Google::Cloud::OsConfig::V1::OSPolicy::Resource::ExecResource::Exec\n\n**Parameter**\n\n- **value** ([::Google::Cloud::OsConfig::V1::OSPolicy::Resource::ExecResource::Exec](./Google-Cloud-OsConfig-V1-OSPolicy-Resource-ExecResource-Exec)) --- 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. \n**Returns**\n\n- ([::Google::Cloud::OsConfig::V1::OSPolicy::Resource::ExecResource::Exec](./Google-Cloud-OsConfig-V1-OSPolicy-Resource-ExecResource-Exec)) --- 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.\n\n### #validate\n\n def validate() -\u003e ::Google::Cloud::OsConfig::V1::OSPolicy::Resource::ExecResource::Exec\n\n**Returns**\n\n- ([::Google::Cloud::OsConfig::V1::OSPolicy::Resource::ExecResource::Exec](./Google-Cloud-OsConfig-V1-OSPolicy-Resource-ExecResource-Exec)) --- 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.\n\n### #validate=\n\n def validate=(value) -\u003e ::Google::Cloud::OsConfig::V1::OSPolicy::Resource::ExecResource::Exec\n\n**Parameter**\n\n- **value** ([::Google::Cloud::OsConfig::V1::OSPolicy::Resource::ExecResource::Exec](./Google-Cloud-OsConfig-V1-OSPolicy-Resource-ExecResource-Exec)) --- 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. \n**Returns**\n\n- ([::Google::Cloud::OsConfig::V1::OSPolicy::Resource::ExecResource::Exec](./Google-Cloud-OsConfig-V1-OSPolicy-Resource-ExecResource-Exec)) --- 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."]]