Grant
Provides a resource-based access control mechanism for a KMS customer master key.
Example Usage
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.kms.Key;
import com.pulumi.aws.iam.Role;
import com.pulumi.aws.iam.RoleArgs;
import com.pulumi.aws.kms.Grant;
import com.pulumi.aws.kms.GrantArgs;
import com.pulumi.aws.kms.inputs.GrantConstraintArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var key = new Key("key");
var role = new Role("role", RoleArgs.builder()
.assumeRolePolicy("""
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
""")
.build());
var grant = new Grant("grant", GrantArgs.builder()
.keyId(key.keyId())
.granteePrincipal(role.arn())
.operations(
"Encrypt",
"Decrypt",
"GenerateDataKey")
.constraints(GrantConstraintArgs.builder()
.encryptionContextEquals(Map.of("Department", "Finance"))
.build())
.build());
}
}
Import
KMS Grants can be imported using the Key ID and Grant ID separated by a colon (:
), e.g.,
$ pulumi import aws:kms/grant:Grant test 1234abcd-12ab-34cd-56ef-1234567890ab:abcde1237f76e4ba7987489ac329fbfba6ad343d6f7075dbd1ef191f0120514
Properties
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.
A list of grant tokens to be used when creating the grant. See Grant Tokens for more information about grant tokens.
The grant token for the created grant. For more information, see Grant Tokens.
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.