# GrantWithResourceOptions

Options for a grant operation.

Extends: [CommonGrantOptions](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_iam.CommonGrantOptions.html)
Used as argument in: [Grant.addToPrincipalOrResource](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_iam.Grant.html#addtoprincipalorresource)

- Source: [`aws-iam/lib/grant.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-iam/lib/grant.ts#L48)
- Type last changed: v2.222.0 · 4 Nov 2025

## Example

TypeScript:

```ts
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import { aws_iam as iam } from 'aws-cdk-lib';

declare const conditions: any;
declare const grantable: iam.IGrantable;
declare const resourceWithPolicyV2: iam.IResourceWithPolicyV2;
const grantWithResourceOptions: iam.GrantWithResourceOptions = {
  actions: ['actions'],
  grantee: grantable,
  resource: resourceWithPolicyV2,
  resourceArns: ['resourceArns'],

  // the properties below are optional
  conditions: {
    conditionsKey: {
      conditionsKey: conditions,
    },
  },
  resourceSelfArns: ['resourceSelfArns'],
};
```

Python:

```python
# The code below shows an example of how to instantiate this type.
# The values are placeholders you should change.
from aws_cdk import aws_iam as iam

# conditions: Any
# grantable: iam.IGrantable
# resource_with_policy_v2: iam.IResourceWithPolicyV2

grant_with_resource_options = iam.GrantWithResourceOptions(
    actions=["actions"],
    grantee=grantable,
    resource=resource_with_policy_v2,
    resource_arns=["resourceArns"],

    # the properties below are optional
    conditions={
        "conditions_key": {
            "conditions_key": conditions
        }
    },
    resource_self_arns=["resourceSelfArns"]
)
```

Java:

```java
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import software.amazon.awscdk.services.iam.*;

Object conditions;
IGrantable grantable;
IResourceWithPolicyV2 resourceWithPolicyV2;

GrantWithResourceOptions grantWithResourceOptions = GrantWithResourceOptions.builder()
        .actions(List.of("actions"))
        .grantee(grantable)
        .resource(resourceWithPolicyV2)
        .resourceArns(List.of("resourceArns"))

        // the properties below are optional
        .conditions(Map.of(
                "conditionsKey", Map.of(
                        "conditionsKey", conditions)))
        .resourceSelfArns(List.of("resourceSelfArns"))
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
using Amazon.CDK.AWS.IAM;

var conditions;
IGrantable grantable;
IResourceWithPolicyV2 resourceWithPolicyV2;

var grantWithResourceOptions = new GrantWithResourceOptions {
    Actions = new [] { "actions" },
    Grantee = grantable,
    Resource = resourceWithPolicyV2,
    ResourceArns = new [] { "resourceArns" },

    // the properties below are optional
    Conditions = new Dictionary<string, IDictionary<string, object>> {
        { "conditionsKey", new Dictionary<string, object> {
            { "conditionsKey", conditions }
        } }
    },
    ResourceSelfArns = new [] { "resourceSelfArns" }
};
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import "github.com/aws/aws-cdk-go/awscdk"

var conditions interface{}
var grantable IGrantable
var resourceWithPolicyV2 IResourceWithPolicyV2

grantWithResourceOptions := &GrantWithResourceOptions{
	Actions: []*string{
		jsii.String("actions"),
	},
	Grantee: grantable,
	Resource: resourceWithPolicyV2,
	ResourceArns: []*string{
		jsii.String("resourceArns"),
	},

	// the properties below are optional
	Conditions: map[string]map[string]interface{}{
		"conditionsKey": map[string]interface{}{
			"conditionsKey": conditions,
		},
	},
	ResourceSelfArns: []*string{
		jsii.String("resourceSelfArns"),
	},
}
```

## Properties

- `actions`: string[] (required) — The actions to grant.

- `conditions`: { [key: string]: { [key: string]: any } } — Any conditions to attach to the grant.

  **Default:** No conditions

- `grantee`: [IGrantable](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IGrantable.html) (required) — The principal to grant to.

  **Default:** if principal is undefined, no work is done.

- `resource`: [IResourceWithPolicyV2](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IResourceWithPolicyV2.html) (required) — The resource with a resource policy.

  The statement will be added to the resource policy if it couldn't be
  added to the principal policy.

- `resourceArns`: string[] (required) — The resource ARNs to grant to.

- `resourceSelfArns`: string[] — When referring to the resource in a resource policy, use this as ARN.

  **Default:** Same as regular resource ARNs

  (Depending on the resource type, this needs to be '*' in a resource policy).
