# Google Cloud OsConfig V1 Client - Class OSPolicy (2.2.3)

2.2.3 (latest) 2.2.2 2.1.0 2.0.5 1.3.5 1.2.2 1.1.1 1.0.5 Reference documentation and code samples for the Google Cloud OsConfig V1 Client class OSPolicy.

An OS policy defines the desired state configuration for a VM.

Generated from protobuf message `google.cloud.osconfig.v1.OSPolicy`

## Namespace

Google \\ Cloud \\ OsConfig \\ V1

## Methods

### __construct

Constructor.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `data` | `array` Optional. Data for populating the Message object. |
| `↳ id` | `string` Required. The id of the OS policy with the following restrictions: \* \* Must contain only lowercase letters, numbers, and hyphens. \* \* Must start with a letter. \* \* Must be between 1-63 characters. \* \* Must end with a number or a letter. \* \* Must be unique within the assignment. |
| `↳ description` | `string` Policy description. Length of the description is limited to 1024 characters. |
| `↳ mode` | `int` Required. Policy mode |
| `↳ resource_groups` | `array<https://docs.cloud.google.com/php/docs/reference/cloud-osconfig/latest/V1.OSPolicy.ResourceGroup>` Required. List of resource groups for the policy. For a particular VM, resource groups are evaluated in the order specified and the first resource group that is applicable is selected and the rest are ignored. If none of the resource groups are applicable for a VM, the VM is considered to be non-compliant w.r.t this policy. This behavior can be toggled by the flag `allow_no_resource_group_match` |
| `↳ allow_no_resource_group_match` | `bool` This flag determines the OS policy compliance status when none of the resource groups within the policy are applicable for a VM. Set this value to `true` if the policy needs to be reported as compliant even if the policy has nothing to validate or enforce. |

### getId

Required. The id of the OS policy with the following restrictions:

- Must contain only lowercase letters, numbers, and hyphens.

- Must start with a letter.

- Must be between 1-63 characters.
- Must end with a number or a letter.
- Must be unique within the assignment.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `string` |   |

### setId

Required. The id of the OS policy with the following restrictions:

- Must contain only lowercase letters, numbers, and hyphens.

- Must start with a letter.

- Must be between 1-63 characters.
- Must end with a number or a letter.
- Must be unique within the assignment.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `var` | `string` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `$this` |   |

### getDescription

Policy description.

Length of the description is limited to 1024 characters.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `string` |   |

### setDescription

Policy description.

Length of the description is limited to 1024 characters.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `var` | `string` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `$this` |   |

### getMode

Required. Policy mode

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `int` | Enum of type [Mode](https://docs.cloud.google.com/php/docs/reference/cloud-osconfig/latest/V1.OSPolicy.Mode). |

### setMode

Required. Policy mode

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `var` | `int` Enum of type [Mode](https://docs.cloud.google.com/php/docs/reference/cloud-osconfig/latest/V1.OSPolicy.Mode). |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `$this` |   |

### getResourceGroups

Required. List of resource groups for the policy.

For a particular VM, resource groups are evaluated in the order specified
and the first resource group that is applicable is selected and the rest
are ignored.
If none of the resource groups are applicable for a VM, the VM is
considered to be non-compliant w.r.t this policy. This behavior can be
toggled by the flag `allow_no_resource_group_match`

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://protobuf.dev/reference/php/api-docs/Google/Protobuf/RepeatedField<https://docs.cloud.google.com/php/docs/reference/cloud-osconfig/latest/V1.OSPolicy.ResourceGroup>` |   |

### setResourceGroups

Required. List of resource groups for the policy.

For a particular VM, resource groups are evaluated in the order specified
and the first resource group that is applicable is selected and the rest
are ignored.
If none of the resource groups are applicable for a VM, the VM is
considered to be non-compliant w.r.t this policy. This behavior can be
toggled by the flag `allow_no_resource_group_match`

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `var` | `array<https://docs.cloud.google.com/php/docs/reference/cloud-osconfig/latest/V1.OSPolicy.ResourceGroup>` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `$this` |   |

### getAllowNoResourceGroupMatch

This flag determines the OS policy compliance status when none of the
resource groups within the policy are applicable for a VM. Set this value
to `true` if the policy needs to be reported as compliant even if the
policy has nothing to validate or enforce.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `bool` |   |

### setAllowNoResourceGroupMatch

This flag determines the OS policy compliance status when none of the
resource groups within the policy are applicable for a VM. Set this value
to `true` if the policy needs to be reported as compliant even if the
policy has nothing to validate or enforce.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `var` | `bool` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `$this` |   |