# IAMPartialPolicy

`IAMPartialPolicy` lets you manage the IAM policy
bindings for a given Google Cloud resource.

`IAMPartialPolicy` represents a *non-authoritative intent* for the
associated Google Cloud resource's IAM policy
bindings. Config Connector merges the bindings in the
`IAMPartialPolicy` `spec` with the bindings and audit configs
that already exist in the underlying IAM policy, and then
sets the merged result as the IAM policy for the
associated Google Cloud resource. If there are invalid roles or
members, the entire operation fails with errors.

To delete any existing bindings, first acquire the existing bindings by
applying an `IAMPartialPolicy` that includes said bindings, then remove
said bindings from the `IAMPartialPolicy` configuration and re-apply the
configuration.

If you want authoritative control over bindings, use
[IAMPolicy](https://docs.cloud.google.com/config-connector/docs/reference/resource-docs/iam/iampolicy).
If you want to manage the binding for only a single IAM member, use
[IAMPolicyMember](https://docs.cloud.google.com/config-connector/docs/reference/resource-docs/iam/iampolicymember).

> [!WARNING]
> **Warning:** `IAMPartialPolicy` **should not** be used in conjunction with `IAMPolicy` for the same resource.

> [!NOTE]
> **Note:** When you delete an `IAMPartialPolicy`, only the bindings specified in `spec` are deleted from the associated Google Cloud resource's IAM policy.

> [!NOTE]
> **Note:** Updating `spec.resourceRef` is not allowed.

| **Property** | **Value** |
|---|---|
| Google Cloud Service Name | IAM |
| Google Cloud Service Documentation | [/iam/docs/](https://docs.cloud.google.com/iam/docs) |
| Google Cloud REST Resource Name | v1.iamPolicies |
| Google Cloud REST Resource Documentation | <https://docs.cloud.google.com/iam/docs/reference/rest/v1/iamPolicies> |
| Config Connector Resource Short Names | gcpiampartialpolicies gcpiampartialpolicy iampartialpolicy |
| Config Connector Service Name | iam.googleapis.com |
| Config Connector Resource Fully Qualified Name | iampartialpolicies.iam.cnrm.cloud.google.com |
| Can Be Referenced by IAMPolicy/IAMPolicyMember | No |
| Config Connector Default Average Reconcile Interval In Seconds | 600 |

## Supported Resources

You can use `IAMPartialPolicy` to configure IAM for
the following resources.

> [!NOTE]
> **Note:** Resource-level IAM permissions for `BigQueryDataset` must be set through the resource's `spec.access` field. You cannot reference `BigQueryDataset` resources using `IAMPolicy`, `IAMPartialPolicy`, and `IAMPolicyMember` since `BigQueryDataset` does not support IAM.

| **Kind** | **Supports Conditions** |
|---|---|
| `AccessContextManagerAccessPolicy` |   |
| `ApigeeEnvironment` |   |
| `ArtifactRegistryRepository` |   |
| `BigQueryTable` | Y |
| `BigtableInstance` | Y |
| `BigtableTable` | Y |
| `BillingAccount` | Y |
| `BinaryAuthorizationPolicy` | Y |
| `CloudFunctionsFunction` | Y |
| `ComputeBackendBucket` |   |
| `ComputeDisk` |   |
| `ComputeImage` | Y |
| `ComputeInstance` | Y |
| `ComputeSnapshot` |   |
| `ComputeSubnetwork` | Y |
| `DNSManagedZone` |   |
| `DataprocCluster` | Y |
| `Folder` | Y |
| `IAMServiceAccount` | Y |
| `IAMWorkforcePool` | Y |
| `KMSCryptoKey` | Y |
| `KMSKeyRing` | Y |
| `NetworkSecurityAuthorizationPolicy` | Y |
| `NetworkSecurityClientTLSPolicy` | Y |
| `NetworkSecurityServerTLSPolicy` | Y |
| `Organization` | Y |
| `Project` | Y |
| `PubSubSubscription` |   |
| `PubSubTopic` |   |
| `RunJob` |   |
| `RunService` |   |
| `SecretManagerSecret` |   |
| `ServiceDirectoryNamespace` |   |
| `ServiceDirectoryService` |   |
| `SourceRepoRepository` |   |
| `SpannerDatabase` | Y |
| `SpannerInstance` |   |
| `StorageBucket` | Y |

| **Kind** | **External Reference Formats** |
|---|---|
| `AccessContextManagerAccessPolicy` | `{{name}}` |
| `ApigeeEnvironment` | `organizations/{{apigee_organization}}/environments/{{name}}` |
| `ArtifactRegistryRepository` | `projects/{{project}}/locations/{{location}}/repositories/{{repository_id}}` |
| `BigQueryTable` | `projects/{{project}}/datasets/{{dataset_id}}/tables/{{table_id}}` |
| `BigtableInstance` | `projects/{{project}}/instances/{{name}}` |
| `BigtableTable` | `projects/{{project}}/instances/{{instance_name}}/tables/{{name}}` |
| `BillingAccount` | `{{billing_account_id}}` |
| `BinaryAuthorizationPolicy` | `projects/{{project}}/policy` |
| `CloudFunctionsFunction` | `projects/{{project}}/locations/{{region}}/functions/{{name}}` |
| `ComputeBackendBucket` | `projects/{{project}}/global/backendBuckets/{{name}}` |
| `ComputeDisk` | `projects/{{project}}/regions/{{region}}/disks/{{name}}` `projects/{{project}}/zones/{{zone}}/disks/{{name}}` |
| `ComputeImage` | `projects/{{project}}/global/images/{{name}}` |
| `ComputeInstance` | `projects/{{project}}/zones/{{zone}}/instances/{{name}}` |
| `ComputeSnapshot` | `projects/{{project}}/global/snapshots/{{name}}` |
| `ComputeSubnetwork` | `projects/{{project}}/regions/{{region}}/subnetworks/{{name}}` |
| `DNSManagedZone` | `projects/{{project}}/managedZones/{{name}}` |
| `DataprocCluster` | `projects/{{project}}/regions/{{location}}/clusters/{{name}}` |
| `Folder` | `folders/{{folder_id}}` |
| `IAMServiceAccount` | `projects/{{project}}/serviceAccounts/{{account_id}}@{{project}}.iam.gserviceaccount.com` |
| `IAMWorkforcePool` | `locations/{{location}}/workforcePools/{{name}}` |
| `KMSCryptoKey` | `projects/{{project}}/locations/{{location}}/keyRings/{{key_ring_id}}/cryptoKeys/{{name}}` |
| `KMSKeyRing` | `projects/{{project}}/locations/{{location}}/keyRings/{{name}}` |
| `NetworkSecurityAuthorizationPolicy` | `projects/{{project}}/locations/{{location}}/authorizationPolicies/{{name}}` |
| `NetworkSecurityClientTLSPolicy` | `projects/{{project}}/locations/{{location}}/clientTlsPolicies/{{name}}` |
| `NetworkSecurityServerTLSPolicy` | `projects/{{project}}/locations/{{location}}/serverTlsPolicies/{{name}}` |
| `Organization` | `{{org_id}}` |
| `Project` | `projects/{{project_id}}` |
| `PubSubSubscription` | `projects/{{project}}/subscriptions/{{name}}` |
| `PubSubTopic` | `projects/{{project}}/topics/{{name}}` |
| `RunJob` | `projects/{{project}}/locations/{{location}}/jobs/{{name}}` |
| `RunService` | `projects/{{project}}/locations/{{location}}/services/{{name}}` |
| `SecretManagerSecret` | `projects/{{project}}/secrets/{{secret_id}}` |
| `ServiceDirectoryNamespace` | `projects/{{project}}/locations/{{location}}/namespaces/{{namespace_id}}` |
| `ServiceDirectoryService` | `{{namespace}}/services/{{service_id}}` |
| `SourceRepoRepository` | `projects/{{project}}/repos/{{name}}` |
| `SpannerDatabase` | `projects/{{project}}/instances/{{instance}}/databases/{{name}}` |
| `SpannerInstance` | `projects/{{project}}/instances/{{name}}` |
| `StorageBucket` | `{{name}}` |

## Custom Resource Definition Properties

### Spec

#### Schema

    bindings:
    - condition:
        description: string
        expression: string
        title: string
      members:
      - member: string
        memberFrom:
          bigQueryConnectionConnectionRef:
            name: string
            namespace: string
            type: string
          logSinkRef:
            name: string
            namespace: string
          serviceAccountRef:
            name: string
            namespace: string
          serviceIdentityRef:
            name: string
            namespace: string
          sqlInstanceRef:
            name: string
            namespace: string
      role: string
    resourceRef:
      apiVersion: string
      external: string
      kind: string
      name: string
      namespace: string

| Fields ||
|---|---|
| `bindings` *Optional* | `list (object)` Optional. The list of IAM bindings managed by Config Connector. |
| `bindings[]` *Optional* | `object` Specifies the members to bind to an IAM role. |
| `bindings[].condition` *Optional* | `object` Optional. The condition under which the binding applies. |
| `bindings[].condition.description` *Optional* | `string` <br /> |
| `bindings[].condition.expression` *Required\** | `string` <br /> |
| `bindings[].condition.title` *Required\** | `string` <br /> |
| `bindings[].members` *Optional* | `list (object)` Optional. The list of IAM users to be bound to the role. |
| `bindings[].members[]` *Optional* | `object` <br /> |
| `bindings[].members[].member` *Optional* | `string` The IAM identity to be bound to the role. Exactly one of 'member' or 'memberFrom' must be used. |
| `bindings[].members[].memberFrom` *Optional* | `object` The IAM identity to be bound to the role. Exactly one of 'member' or 'memberFrom' must be used, and only one subfield within 'memberFrom' can be used. |
| `bindings[].members[].memberFrom.bigQueryConnectionConnectionRef` *Optional* | `object` BigQueryConnectionConnection whose service account is to be bound to the role. Use the Type field to specify the connection type. For "spark" connection, the service account is in \`status.observedState.spark.serviceAccountID\`. For "cloudSQL" connection, the service account is in \`status.observedState.cloudSQL.serviceAccountID\`. For "cloudResource" connection, the service account is in \`status.observedState.cloudResource.serviceAccountID\`. |
| `bindings[].members[].memberFrom.bigQueryConnectionConnectionRef.name` *Required\** | `string` <br /> |
| `bindings[].members[].memberFrom.bigQueryConnectionConnectionRef.namespace` *Optional* | `string` <br /> |
| `bindings[].members[].memberFrom.bigQueryConnectionConnectionRef.type` *Required\** | `string` Type field specifies the connection type of the BigQueryConnectionConnection resource, whose service account is to be bound to the role. |
| `bindings[].members[].memberFrom.logSinkRef` *Optional* | `object` The LoggingLogSink whose writer identity (i.e. its 'status.writerIdentity') is to be bound to the role. |
| `bindings[].members[].memberFrom.logSinkRef.name` *Required\** | `string` <br /> |
| `bindings[].members[].memberFrom.logSinkRef.namespace` *Optional* | `string` <br /> |
| `bindings[].members[].memberFrom.serviceAccountRef` *Optional* | `object` The IAMServiceAccount to be bound to the role. |
| `bindings[].members[].memberFrom.serviceAccountRef.name` *Required\** | `string` <br /> |
| `bindings[].members[].memberFrom.serviceAccountRef.namespace` *Optional* | `string` <br /> |
| `bindings[].members[].memberFrom.serviceIdentityRef` *Optional* | `object` The ServiceIdentity whose service account (i.e., its 'status.email') is to be bound to the role. |
| `bindings[].members[].memberFrom.serviceIdentityRef.name` *Required\** | `string` <br /> |
| `bindings[].members[].memberFrom.serviceIdentityRef.namespace` *Optional* | `string` <br /> |
| `bindings[].members[].memberFrom.sqlInstanceRef` *Optional* | `object` The SQLInstance whose service account (i.e. its 'status.serviceAccountEmailAddress') is to be bound to the role. |
| `bindings[].members[].memberFrom.sqlInstanceRef.name` *Required\** | `string` <br /> |
| `bindings[].members[].memberFrom.sqlInstanceRef.namespace` *Optional* | `string` <br /> |
| `bindings[].role` *Required\** | `string` Required. The role to bind the users to. |
| `resourceRef` *Required\** | `object` Immutable. Required. The Google Cloud resource to set the IAM policy on (e.g. organization, project...) |
| `resourceRef.apiVersion` *Optional* | `string` APIVersion of the referenced resource |
| `resourceRef.external` *Optional* | `string` The external name of the referenced resource |
| `resourceRef.kind` *Required\** | `string` Kind of the referenced resource |
| `resourceRef.name` *Optional* | `string` <br /> |
| `resourceRef.namespace` *Optional* | `string` <br /> |

\* Field is required when parent field is specified

### Status

#### Schema

    allBindings:
    - condition:
        description: string
        expression: string
        title: string
      members:
      - string
      role: string
    conditions:
    - lastTransitionTime: string
      message: string
      reason: string
      status: string
      type: string
    lastAppliedBindings:
    - condition:
        description: string
        expression: string
        title: string
      members:
      - string
      role: string
    observedGeneration: integer

| Fields ||
|---|---|
| `allBindings` | `list (object)` AllBindings surfaces all IAM bindings for the referenced resource. |
| `allBindings[]` | `object` Specifies the members to bind to an IAM role. |
| `allBindings[].condition` | `object` Optional. The condition under which the binding applies. |
| `allBindings[].condition.description` | `string` <br /> |
| `allBindings[].condition.expression` | `string` <br /> |
| `allBindings[].condition.title` | `string` <br /> |
| `allBindings[].members` | `list (string)` Optional. The list of IAM users to be bound to the role. |
| `allBindings[].members[]` | `string` <br /> |
| `allBindings[].role` | `string` Required. The role to bind the users to. |
| `conditions` | `list (object)` Conditions represent the latest available observations of the IAM policy's current state. |
| `conditions[]` | `object` <br /> |
| `conditions[].lastTransitionTime` | `string` Last time the condition transitioned from one status to another. |
| `conditions[].message` | `string` Human-readable message indicating details about last transition. |
| `conditions[].reason` | `string` Unique, one-word, CamelCase reason for the condition's last transition. |
| `conditions[].status` | `string` Status is the status of the condition. Can be True, False, Unknown. |
| `conditions[].type` | `string` Type is the type of the condition. |
| `lastAppliedBindings` | `list (object)` LastAppliedBindings is the list of IAM bindings that were most recently applied by Config Connector. |
| `lastAppliedBindings[]` | `object` Specifies the members to bind to an IAM role. |
| `lastAppliedBindings[].condition` | `object` Optional. The condition under which the binding applies. |
| `lastAppliedBindings[].condition.description` | `string` <br /> |
| `lastAppliedBindings[].condition.expression` | `string` <br /> |
| `lastAppliedBindings[].condition.title` | `string` <br /> |
| `lastAppliedBindings[].members` | `list (string)` Optional. The list of IAM users to be bound to the role. |
| `lastAppliedBindings[].members[]` | `string` <br /> |
| `lastAppliedBindings[].role` | `string` Required. The role to bind the users to. |
| `observedGeneration` | `integer` ObservedGeneration is the generation of the resource that was most recently observed by the Config Connector controller. If this is equal to metadata.generation, then that means that the current reported status reflects the most recent desired state of the resource. |

## Sample YAML(s)

### Project Level IAMPartialPolicy

    # **NOTE**: The policy here represents a non-authoritative declarative intent for the
    # referenced project. It will merge with the existing bindings on the project.
    apiVersion: iam.cnrm.cloud.google.com/v1beta1
    kind: IAMPartialPolicy
    metadata:
      name: iampartialpolicy-sample-project
    spec:
      resourceRef:
        kind: Project
        name: iampartialpolicy-dep-project
      bindings:
        - role: roles/storage.admin
          members:
            - member: serviceAccount:iampartialpolicy-dep-project@iampartialpolicy-dep-project.iam.gserviceaccount.com
        - role: roles/editor
          members:
            - memberFrom:
                serviceAccountRef:
                  name: iampartialpolicy-dep-project
    ---
    apiVersion: iam.cnrm.cloud.google.com/v1beta1
    kind: IAMServiceAccount
    metadata:
      annotations:
        cnrm.cloud.google.com/project-id: iampartialpolicy-dep-project
      name: iampartialpolicy-dep-project
    ---
    apiVersion: resourcemanager.cnrm.cloud.google.com/v1beta1
    kind: Project
    metadata:
      annotations:
        cnrm.cloud.google.com/auto-create-network: "false"
      name: iampartialpolicy-dep-project
    spec:
      name: Config Connector Sample
      organizationRef:
        # Replace "${ORG_ID?}" with the numeric ID for your organization
        external: "${ORG_ID?}"

### PubSub Admin IAMPartialPolicy

    # Replace ${PROJECT_ID?} below with your desired project ID.
    apiVersion: iam.cnrm.cloud.google.com/v1beta1
    kind: IAMPartialPolicy
    metadata:
      name: iampartialpolicy-sample-pubsubadmin
    spec:
      resourceRef:
        kind: PubSubTopic
        name: iampartialpolicy-dep-pubsubadmin
      bindings:
        - role: roles/editor
          members:
            - member: serviceAccount:partialpolicy-dep-pubsubadmin@${PROJECT_ID?}.iam.gserviceaccount.com
    ---
    # Replace ${PROJECT_ID?} below with your desired project ID.
    apiVersion: iam.cnrm.cloud.google.com/v1beta1
    kind: IAMServiceAccount
    metadata:
      annotations:
        cnrm.cloud.google.com/project-id: ${PROJECT_ID?}
      name: partialpolicy-dep-pubsubadmin
    ---
    apiVersion: pubsub.cnrm.cloud.google.com/v1beta1
    kind: PubSubTopic
    metadata:
      name: iampartialpolicy-dep-pubsubadmin

> [!NOTE]
> **Note:** If you have any trouble with instantiating the resource, refer to [Troubleshoot Config Connector](https://docs.cloud.google.com/config-connector/docs/troubleshooting).