Grant
Provides a resource-based access control mechanism for a KMS customer master key.
Example Usage
using Pulumi;
using Aws = Pulumi.Aws;
class MyStack : Stack
{
public MyStack()
{
var key = new Aws.Kms.Key("key", new Aws.Kms.KeyArgs
{
});
var role = new Aws.Iam.Role("role", new Aws.Iam.RoleArgs
{
AssumeRolePolicy = @"{
""Version"": ""2012-10-17"",
""Statement"": [
{
""Action"": ""sts:AssumeRole"",
""Principal"": {
""Service"": ""lambda.amazonaws.com""
},
""Effect"": ""Allow"",
""Sid"": """"
}
]
}
",
});
var grant = new Aws.Kms.Grant("grant", new Aws.Kms.GrantArgs
{
Constraints =
{
new Aws.Kms.Inputs.GrantConstraintArgs
{
EncryptionContextEquals =
{
{ "Department", "Finance" },
},
},
},
GranteePrincipal = role.Arn,
KeyId = key.KeyId,
Operations =
{
"Encrypt",
"Decrypt",
"GenerateDataKey",
},
});
}
}
package main
import (
"fmt"
"github.com/pulumi/pulumi-aws/sdk/v2/go/aws/iam"
"github.com/pulumi/pulumi-aws/sdk/v2/go/aws/kms"
"github.com/pulumi/pulumi/sdk/v2/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
key, err := kms.NewKey(ctx, "key", nil)
if err != nil {
return err
}
role, err := iam.NewRole(ctx, "role", &iam.RoleArgs{
AssumeRolePolicy: pulumi.String(fmt.Sprintf("%v%v%v%v%v%v%v%v%v%v%v%v%v%v", "{\n", " \"Version\": \"2012-10-17\",\n", " \"Statement\": [\n", " {\n", " \"Action\": \"sts:AssumeRole\",\n", " \"Principal\": {\n", " \"Service\": \"lambda.amazonaws.com\"\n", " },\n", " \"Effect\": \"Allow\",\n", " \"Sid\": \"\"\n", " }\n", " ]\n", "}\n", "\n")),
})
if err != nil {
return err
}
_, err = kms.NewGrant(ctx, "grant", &kms.GrantArgs{
Constraints: kms.GrantConstraintArray{
&kms.GrantConstraintArgs{
EncryptionContextEquals: pulumi.StringMap{
"Department": pulumi.String("Finance"),
},
},
},
GranteePrincipal: role.Arn,
KeyId: key.KeyId,
Operations: pulumi.StringArray{
pulumi.String("Encrypt"),
pulumi.String("Decrypt"),
pulumi.String("GenerateDataKey"),
},
})
if err != nil {
return err
}
return nil
})
}import pulumi
import pulumi_aws as aws
key = aws.kms.Key("key")
role = aws.iam.Role("role", assume_role_policy="""{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
""")
grant = aws.kms.Grant("grant",
constraints=[{
"encryptionContextEquals": {
"Department": "Finance",
},
}],
grantee_principal=role.arn,
key_id=key.key_id,
operations=[
"Encrypt",
"Decrypt",
"GenerateDataKey",
])import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const key = new aws.kms.Key("a", {});
const role = new aws.iam.Role("a", {
assumeRolePolicy: `{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
`,
});
const grant = new aws.kms.Grant("a", {
constraints: [{
encryptionContextEquals: {
Department: "Finance",
},
}],
granteePrincipal: role.arn,
keyId: key.keyId,
operations: [
"Encrypt",
"Decrypt",
"GenerateDataKey",
],
});Create a Grant Resource
new Grant(name: string, args: GrantArgs, opts?: CustomResourceOptions);def Grant(resource_name, opts=None, constraints=None, grant_creation_tokens=None, grantee_principal=None, key_id=None, name=None, operations=None, retire_on_delete=None, retiring_principal=None, __props__=None);public Grant(string name, GrantArgs args, CustomResourceOptions? opts = null)- name string
- The unique name of the resource.
- args GrantArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
- resource_name str
- The unique name of the resource.
- opts ResourceOptions
- A bag of options that control this resource's behavior.
- ctx Context
- Context object for the current deployment.
- name string
- The unique name of the resource.
- args GrantArgs
- The arguments to resource properties.
- opts ResourceOption
- Bag of options to control resource's behavior.
- name string
- The unique name of the resource.
- args GrantArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
Grant Resource Properties
To learn more about resource properties and how to use them, see Inputs and Outputs in the Programming Model docs.
Inputs
The Grant resource accepts the following input properties:
- Grantee
Principal string The principal that is given permission to perform the operations that the grant permits in ARN format. Note that due to eventual consistency issues around IAM principals, the state may not always be refreshed to reflect what is true in AWS.
- Key
Id string The unique identifier for the customer master key (CMK) that the grant applies to. Specify the key ID or the Amazon Resource Name (ARN) of the CMK. To specify a CMK in a different AWS account, you must use the key ARN.
- Operations List<string>
A list of operations that the grant permits. The permitted values are:
Decrypt, Encrypt, GenerateDataKey, GenerateDataKeyWithoutPlaintext, ReEncryptFrom, ReEncryptTo, CreateGrant, RetireGrant, DescribeKey- Constraints
List<Grant
Constraint Args> A structure that you can use to allow certain operations in the grant only when the desired encryption context is present. For more information about encryption context, see Encryption Context.
- Grant
Creation List<string>Tokens A list of grant tokens to be used when creating the grant. See Grant Tokens for more information about grant tokens.
- Name string
A friendly name for identifying the grant.
- Retire
On boolDelete -(Defaults to false, Forces new resources) If set to false (the default) the grants will be revoked upon deletion, and if set to true the grants will try to be retired upon deletion. Note that retiring grants requires special permissions, hence why we default to revoking grants. See RetireGrant for more information.
- Retiring
Principal string The principal that is given permission to retire the grant by using RetireGrant operation in ARN format. Note that due to eventual consistency issues around IAM principals, the state may not always be refreshed to reflect what is true in AWS.
- Grantee
Principal string The principal that is given permission to perform the operations that the grant permits in ARN format. Note that due to eventual consistency issues around IAM principals, the state may not always be refreshed to reflect what is true in AWS.
- Key
Id string The unique identifier for the customer master key (CMK) that the grant applies to. Specify the key ID or the Amazon Resource Name (ARN) of the CMK. To specify a CMK in a different AWS account, you must use the key ARN.
- Operations []string
A list of operations that the grant permits. The permitted values are:
Decrypt, Encrypt, GenerateDataKey, GenerateDataKeyWithoutPlaintext, ReEncryptFrom, ReEncryptTo, CreateGrant, RetireGrant, DescribeKey- Constraints
[]Grant
Constraint A structure that you can use to allow certain operations in the grant only when the desired encryption context is present. For more information about encryption context, see Encryption Context.
- Grant
Creation []stringTokens A list of grant tokens to be used when creating the grant. See Grant Tokens for more information about grant tokens.
- Name string
A friendly name for identifying the grant.
- Retire
On boolDelete -(Defaults to false, Forces new resources) If set to false (the default) the grants will be revoked upon deletion, and if set to true the grants will try to be retired upon deletion. Note that retiring grants requires special permissions, hence why we default to revoking grants. See RetireGrant for more information.
- Retiring
Principal string The principal that is given permission to retire the grant by using RetireGrant operation in ARN format. Note that due to eventual consistency issues around IAM principals, the state may not always be refreshed to reflect what is true in AWS.
- grantee
Principal string The principal that is given permission to perform the operations that the grant permits in ARN format. Note that due to eventual consistency issues around IAM principals, the state may not always be refreshed to reflect what is true in AWS.
- key
Id string The unique identifier for the customer master key (CMK) that the grant applies to. Specify the key ID or the Amazon Resource Name (ARN) of the CMK. To specify a CMK in a different AWS account, you must use the key ARN.
- operations string[]
A list of operations that the grant permits. The permitted values are:
Decrypt, Encrypt, GenerateDataKey, GenerateDataKeyWithoutPlaintext, ReEncryptFrom, ReEncryptTo, CreateGrant, RetireGrant, DescribeKey- constraints
Grant
Constraint[] A structure that you can use to allow certain operations in the grant only when the desired encryption context is present. For more information about encryption context, see Encryption Context.
- grant
Creation string[]Tokens A list of grant tokens to be used when creating the grant. See Grant Tokens for more information about grant tokens.
- name string
A friendly name for identifying the grant.
- retire
On booleanDelete -(Defaults to false, Forces new resources) If set to false (the default) the grants will be revoked upon deletion, and if set to true the grants will try to be retired upon deletion. Note that retiring grants requires special permissions, hence why we default to revoking grants. See RetireGrant for more information.
- retiring
Principal string The principal that is given permission to retire the grant by using RetireGrant operation in ARN format. Note that due to eventual consistency issues around IAM principals, the state may not always be refreshed to reflect what is true in AWS.
- grantee_
principal str The principal that is given permission to perform the operations that the grant permits in ARN format. Note that due to eventual consistency issues around IAM principals, the state may not always be refreshed to reflect what is true in AWS.
- key_
id str The unique identifier for the customer master key (CMK) that the grant applies to. Specify the key ID or the Amazon Resource Name (ARN) of the CMK. To specify a CMK in a different AWS account, you must use the key ARN.
- operations List[str]
A list of operations that the grant permits. The permitted values are:
Decrypt, Encrypt, GenerateDataKey, GenerateDataKeyWithoutPlaintext, ReEncryptFrom, ReEncryptTo, CreateGrant, RetireGrant, DescribeKey- constraints
List[Grant
Constraint] A structure that you can use to allow certain operations in the grant only when the desired encryption context is present. For more information about encryption context, see Encryption Context.
- grant_
creation_ List[str]tokens A list of grant tokens to be used when creating the grant. See Grant Tokens for more information about grant tokens.
- name str
A friendly name for identifying the grant.
- retire_
on_ booldelete -(Defaults to false, Forces new resources) If set to false (the default) the grants will be revoked upon deletion, and if set to true the grants will try to be retired upon deletion. Note that retiring grants requires special permissions, hence why we default to revoking grants. See RetireGrant for more information.
- retiring_
principal str The principal that is given permission to retire the grant by using RetireGrant operation in ARN format. Note that due to eventual consistency issues around IAM principals, the state may not always be refreshed to reflect what is true in AWS.
Outputs
All input properties are implicitly available as output properties. Additionally, the Grant resource produces the following output properties:
- Grant
Id string The unique identifier for the grant.
- Grant
Token string The grant token for the created grant. For more information, see Grant Tokens.
- Id string
- The provider-assigned unique ID for this managed resource.
- Grant
Id string The unique identifier for the grant.
- Grant
Token string The grant token for the created grant. For more information, see Grant Tokens.
- Id string
- The provider-assigned unique ID for this managed resource.
- grant
Id string The unique identifier for the grant.
- grant
Token string The grant token for the created grant. For more information, see Grant Tokens.
- id string
- The provider-assigned unique ID for this managed resource.
- grant_
id str The unique identifier for the grant.
- grant_
token str The grant token for the created grant. For more information, see Grant Tokens.
- id str
- The provider-assigned unique ID for this managed resource.
Look up an Existing Grant Resource
Get an existing Grant resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.
public static get(name: string, id: Input<ID>, state?: GrantState, opts?: CustomResourceOptions): Grantstatic get(resource_name, id, opts=None, constraints=None, grant_creation_tokens=None, grant_id=None, grant_token=None, grantee_principal=None, key_id=None, name=None, operations=None, retire_on_delete=None, retiring_principal=None, __props__=None);func GetGrant(ctx *Context, name string, id IDInput, state *GrantState, opts ...ResourceOption) (*Grant, error)public static Grant Get(string name, Input<string> id, GrantState? state, CustomResourceOptions? opts = null)- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- resource_name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
The following state arguments are supported:
- Constraints
List<Grant
Constraint Args> A structure that you can use to allow certain operations in the grant only when the desired encryption context is present. For more information about encryption context, see Encryption Context.
- Grant
Creation List<string>Tokens A list of grant tokens to be used when creating the grant. See Grant Tokens for more information about grant tokens.
- Grant
Id string The unique identifier for the grant.
- Grant
Token string The grant token for the created grant. For more information, see Grant Tokens.
- Grantee
Principal string The principal that is given permission to perform the operations that the grant permits in ARN format. Note that due to eventual consistency issues around IAM principals, the state may not always be refreshed to reflect what is true in AWS.
- Key
Id string The unique identifier for the customer master key (CMK) that the grant applies to. Specify the key ID or the Amazon Resource Name (ARN) of the CMK. To specify a CMK in a different AWS account, you must use the key ARN.
- Name string
A friendly name for identifying the grant.
- Operations List<string>
A list of operations that the grant permits. The permitted values are:
Decrypt, Encrypt, GenerateDataKey, GenerateDataKeyWithoutPlaintext, ReEncryptFrom, ReEncryptTo, CreateGrant, RetireGrant, DescribeKey- Retire
On boolDelete -(Defaults to false, Forces new resources) If set to false (the default) the grants will be revoked upon deletion, and if set to true the grants will try to be retired upon deletion. Note that retiring grants requires special permissions, hence why we default to revoking grants. See RetireGrant for more information.
- Retiring
Principal string The principal that is given permission to retire the grant by using RetireGrant operation in ARN format. Note that due to eventual consistency issues around IAM principals, the state may not always be refreshed to reflect what is true in AWS.
- Constraints
[]Grant
Constraint A structure that you can use to allow certain operations in the grant only when the desired encryption context is present. For more information about encryption context, see Encryption Context.
- Grant
Creation []stringTokens A list of grant tokens to be used when creating the grant. See Grant Tokens for more information about grant tokens.
- Grant
Id string The unique identifier for the grant.
- Grant
Token string The grant token for the created grant. For more information, see Grant Tokens.
- Grantee
Principal string The principal that is given permission to perform the operations that the grant permits in ARN format. Note that due to eventual consistency issues around IAM principals, the state may not always be refreshed to reflect what is true in AWS.
- Key
Id string The unique identifier for the customer master key (CMK) that the grant applies to. Specify the key ID or the Amazon Resource Name (ARN) of the CMK. To specify a CMK in a different AWS account, you must use the key ARN.
- Name string
A friendly name for identifying the grant.
- Operations []string
A list of operations that the grant permits. The permitted values are:
Decrypt, Encrypt, GenerateDataKey, GenerateDataKeyWithoutPlaintext, ReEncryptFrom, ReEncryptTo, CreateGrant, RetireGrant, DescribeKey- Retire
On boolDelete -(Defaults to false, Forces new resources) If set to false (the default) the grants will be revoked upon deletion, and if set to true the grants will try to be retired upon deletion. Note that retiring grants requires special permissions, hence why we default to revoking grants. See RetireGrant for more information.
- Retiring
Principal string The principal that is given permission to retire the grant by using RetireGrant operation in ARN format. Note that due to eventual consistency issues around IAM principals, the state may not always be refreshed to reflect what is true in AWS.
- constraints
Grant
Constraint[] A structure that you can use to allow certain operations in the grant only when the desired encryption context is present. For more information about encryption context, see Encryption Context.
- grant
Creation string[]Tokens A list of grant tokens to be used when creating the grant. See Grant Tokens for more information about grant tokens.
- grant
Id string The unique identifier for the grant.
- grant
Token string The grant token for the created grant. For more information, see Grant Tokens.
- grantee
Principal string The principal that is given permission to perform the operations that the grant permits in ARN format. Note that due to eventual consistency issues around IAM principals, the state may not always be refreshed to reflect what is true in AWS.
- key
Id string The unique identifier for the customer master key (CMK) that the grant applies to. Specify the key ID or the Amazon Resource Name (ARN) of the CMK. To specify a CMK in a different AWS account, you must use the key ARN.
- name string
A friendly name for identifying the grant.
- operations string[]
A list of operations that the grant permits. The permitted values are:
Decrypt, Encrypt, GenerateDataKey, GenerateDataKeyWithoutPlaintext, ReEncryptFrom, ReEncryptTo, CreateGrant, RetireGrant, DescribeKey- retire
On booleanDelete -(Defaults to false, Forces new resources) If set to false (the default) the grants will be revoked upon deletion, and if set to true the grants will try to be retired upon deletion. Note that retiring grants requires special permissions, hence why we default to revoking grants. See RetireGrant for more information.
- retiring
Principal string The principal that is given permission to retire the grant by using RetireGrant operation in ARN format. Note that due to eventual consistency issues around IAM principals, the state may not always be refreshed to reflect what is true in AWS.
- constraints
List[Grant
Constraint] A structure that you can use to allow certain operations in the grant only when the desired encryption context is present. For more information about encryption context, see Encryption Context.
- grant_
creation_ List[str]tokens A list of grant tokens to be used when creating the grant. See Grant Tokens for more information about grant tokens.
- grant_
id str The unique identifier for the grant.
- grant_
token str The grant token for the created grant. For more information, see Grant Tokens.
- grantee_
principal str The principal that is given permission to perform the operations that the grant permits in ARN format. Note that due to eventual consistency issues around IAM principals, the state may not always be refreshed to reflect what is true in AWS.
- key_
id str The unique identifier for the customer master key (CMK) that the grant applies to. Specify the key ID or the Amazon Resource Name (ARN) of the CMK. To specify a CMK in a different AWS account, you must use the key ARN.
- name str
A friendly name for identifying the grant.
- operations List[str]
A list of operations that the grant permits. The permitted values are:
Decrypt, Encrypt, GenerateDataKey, GenerateDataKeyWithoutPlaintext, ReEncryptFrom, ReEncryptTo, CreateGrant, RetireGrant, DescribeKey- retire_
on_ booldelete -(Defaults to false, Forces new resources) If set to false (the default) the grants will be revoked upon deletion, and if set to true the grants will try to be retired upon deletion. Note that retiring grants requires special permissions, hence why we default to revoking grants. See RetireGrant for more information.
- retiring_
principal str The principal that is given permission to retire the grant by using RetireGrant operation in ARN format. Note that due to eventual consistency issues around IAM principals, the state may not always be refreshed to reflect what is true in AWS.
Supporting Types
GrantConstraint
- Encryption
Context Dictionary<string, string>Equals A list of key-value pairs that must match the encryption context in subsequent cryptographic operation requests. The grant allows the operation only when the encryption context in the request is the same as the encryption context specified in this constraint. Conflicts with
encryption_context_subset.- Encryption
Context Dictionary<string, string>Subset A list of key-value pairs that must be included in the encryption context of subsequent cryptographic operation requests. The grant allows the cryptographic operation only when the encryption context in the request includes the key-value pairs specified in this constraint, although it can include additional key-value pairs. Conflicts with
encryption_context_equals.
- Encryption
Context map[string]stringEquals A list of key-value pairs that must match the encryption context in subsequent cryptographic operation requests. The grant allows the operation only when the encryption context in the request is the same as the encryption context specified in this constraint. Conflicts with
encryption_context_subset.- Encryption
Context map[string]stringSubset A list of key-value pairs that must be included in the encryption context of subsequent cryptographic operation requests. The grant allows the cryptographic operation only when the encryption context in the request includes the key-value pairs specified in this constraint, although it can include additional key-value pairs. Conflicts with
encryption_context_equals.
- encryption
Context {[key: string]: string}Equals A list of key-value pairs that must match the encryption context in subsequent cryptographic operation requests. The grant allows the operation only when the encryption context in the request is the same as the encryption context specified in this constraint. Conflicts with
encryption_context_subset.- encryption
Context {[key: string]: string}Subset A list of key-value pairs that must be included in the encryption context of subsequent cryptographic operation requests. The grant allows the cryptographic operation only when the encryption context in the request includes the key-value pairs specified in this constraint, although it can include additional key-value pairs. Conflicts with
encryption_context_equals.
- encryption
Context Dict[str, str]Equals A list of key-value pairs that must match the encryption context in subsequent cryptographic operation requests. The grant allows the operation only when the encryption context in the request is the same as the encryption context specified in this constraint. Conflicts with
encryption_context_subset.- encryption
Context Dict[str, str]Subset A list of key-value pairs that must be included in the encryption context of subsequent cryptographic operation requests. The grant allows the cryptographic operation only when the encryption context in the request includes the key-value pairs specified in this constraint, although it can include additional key-value pairs. Conflicts with
encryption_context_equals.
Package Details
- Repository
- https://github.com/pulumi/pulumi-aws
- License
- Apache-2.0
- Notes
- This Pulumi package is based on the
awsTerraform Provider.