Package com.pulumi.aws.kms
Class Key
- java.lang.Object
-
- com.pulumi.resources.Resource
-
- com.pulumi.resources.CustomResource
-
- com.pulumi.aws.kms.Key
-
public class Key extends com.pulumi.resources.CustomResourceManages a single-Region or multi-Region primary KMS key. > **NOTE on KMS Key Policy:** KMS Key Policy can be configured in either the standalone resource `aws.kms.KeyPolicy` or with the parameter `policy` in this resource. Configuring with both will cause inconsistencies and may overwrite configuration. ## Example Usage ### Symmetric Encryption KMS Key
### Symmetric Encryption KMS Key With Standalone Policy Resourcepackage generated_program; import com.pulumi.Context; import com.pulumi.Pulumi; import com.pulumi.core.Output; import com.pulumi.aws.AwsFunctions; import com.pulumi.aws.inputs.GetCallerIdentityArgs; import com.pulumi.aws.kms.Key; import com.pulumi.aws.kms.KeyArgs; import static com.pulumi.codegen.internal.Serialization.*; import java.util.ArrayList; import java.util.Arrays; 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) { final var current = AwsFunctions.getCallerIdentity(GetCallerIdentityArgs.builder() .build()); var example = new Key("example", KeyArgs.builder() .description("An example symmetric encryption KMS key") .enableKeyRotation(true) .deletionWindowInDays(20) .policy(serializeJson( jsonObject( jsonProperty("Version", "2012-10-17"), jsonProperty("Id", "key-default-1"), jsonProperty("Statement", jsonArray( jsonObject( jsonProperty("Sid", "Enable IAM User Permissions"), jsonProperty("Effect", "Allow"), jsonProperty("Principal", jsonObject( jsonProperty("AWS", String.format("arn:aws:iam::%s:root", current.accountId())) )), jsonProperty("Action", "kms:*"), jsonProperty("Resource", "*") ), jsonObject( jsonProperty("Sid", "Allow administration of the key"), jsonProperty("Effect", "Allow"), jsonProperty("Principal", jsonObject( jsonProperty("AWS", String.format("arn:aws:iam::%s:user/Alice", current.accountId())) )), jsonProperty("Action", jsonArray( "kms:ReplicateKey", "kms:Create*", "kms:Describe*", "kms:Enable*", "kms:List*", "kms:Put*", "kms:Update*", "kms:Revoke*", "kms:Disable*", "kms:Get*", "kms:Delete*", "kms:ScheduleKeyDeletion", "kms:CancelKeyDeletion" )), jsonProperty("Resource", "*") ), jsonObject( jsonProperty("Sid", "Allow use of the key"), jsonProperty("Effect", "Allow"), jsonProperty("Principal", jsonObject( jsonProperty("AWS", String.format("arn:aws:iam::%s:user/Bob", current.accountId())) )), jsonProperty("Action", jsonArray( "kms:DescribeKey", "kms:Encrypt", "kms:Decrypt", "kms:ReEncrypt*", "kms:GenerateDataKey", "kms:GenerateDataKeyWithoutPlaintext" )), jsonProperty("Resource", "*") ) )) ))) .build()); } }
### Asymmetric KMS Keypackage generated_program; import com.pulumi.Context; import com.pulumi.Pulumi; import com.pulumi.core.Output; import com.pulumi.aws.AwsFunctions; import com.pulumi.aws.inputs.GetCallerIdentityArgs; import com.pulumi.aws.kms.Key; import com.pulumi.aws.kms.KeyArgs; import com.pulumi.aws.kms.KeyPolicy; import com.pulumi.aws.kms.KeyPolicyArgs; import static com.pulumi.codegen.internal.Serialization.*; import java.util.ArrayList; import java.util.Arrays; 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) { final var current = AwsFunctions.getCallerIdentity(GetCallerIdentityArgs.builder() .build()); var example = new Key("example", KeyArgs.builder() .description("An example symmetric encryption KMS key") .enableKeyRotation(true) .deletionWindowInDays(20) .build()); var exampleKeyPolicy = new KeyPolicy("exampleKeyPolicy", KeyPolicyArgs.builder() .keyId(example.id()) .policy(serializeJson( jsonObject( jsonProperty("Version", "2012-10-17"), jsonProperty("Id", "key-default-1"), jsonProperty("Statement", jsonArray(jsonObject( jsonProperty("Sid", "Enable IAM User Permissions"), jsonProperty("Effect", "Allow"), jsonProperty("Principal", jsonObject( jsonProperty("AWS", String.format("arn:aws:iam::%s:root", current.accountId())) )), jsonProperty("Action", "kms:*"), jsonProperty("Resource", "*") ))) ))) .build()); } }
### HMAC KMS keypackage generated_program; import com.pulumi.Context; import com.pulumi.Pulumi; import com.pulumi.core.Output; import com.pulumi.aws.AwsFunctions; import com.pulumi.aws.inputs.GetCallerIdentityArgs; import com.pulumi.aws.kms.Key; import com.pulumi.aws.kms.KeyArgs; import static com.pulumi.codegen.internal.Serialization.*; import java.util.ArrayList; import java.util.Arrays; 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) { final var current = AwsFunctions.getCallerIdentity(GetCallerIdentityArgs.builder() .build()); var example = new Key("example", KeyArgs.builder() .description("RSA-3072 asymmetric KMS key for signing and verification") .customerMasterKeySpec("RSA_3072") .keyUsage("SIGN_VERIFY") .enableKeyRotation(false) .policy(serializeJson( jsonObject( jsonProperty("Version", "2012-10-17"), jsonProperty("Id", "key-default-1"), jsonProperty("Statement", jsonArray( jsonObject( jsonProperty("Sid", "Enable IAM User Permissions"), jsonProperty("Effect", "Allow"), jsonProperty("Principal", jsonObject( jsonProperty("AWS", String.format("arn:aws:iam::%s:root", current.accountId())) )), jsonProperty("Action", "kms:*"), jsonProperty("Resource", "*") ), jsonObject( jsonProperty("Sid", "Allow administration of the key"), jsonProperty("Effect", "Allow"), jsonProperty("Principal", jsonObject( jsonProperty("AWS", String.format("arn:aws:iam::%s:role/Admin", current.accountId())) )), jsonProperty("Action", jsonArray( "kms:Create*", "kms:Describe*", "kms:Enable*", "kms:List*", "kms:Put*", "kms:Update*", "kms:Revoke*", "kms:Disable*", "kms:Get*", "kms:Delete*", "kms:ScheduleKeyDeletion", "kms:CancelKeyDeletion" )), jsonProperty("Resource", "*") ), jsonObject( jsonProperty("Sid", "Allow use of the key"), jsonProperty("Effect", "Allow"), jsonProperty("Principal", jsonObject( jsonProperty("AWS", String.format("arn:aws:iam::%s:role/Developer", current.accountId())) )), jsonProperty("Action", jsonArray( "kms:Sign", "kms:Verify", "kms:DescribeKey" )), jsonProperty("Resource", "*") ) )) ))) .build()); } }
### Multi-Region Primary Keypackage generated_program; import com.pulumi.Context; import com.pulumi.Pulumi; import com.pulumi.core.Output; import com.pulumi.aws.AwsFunctions; import com.pulumi.aws.inputs.GetCallerIdentityArgs; import com.pulumi.aws.kms.Key; import com.pulumi.aws.kms.KeyArgs; import static com.pulumi.codegen.internal.Serialization.*; import java.util.ArrayList; import java.util.Arrays; 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) { final var current = AwsFunctions.getCallerIdentity(GetCallerIdentityArgs.builder() .build()); var example = new Key("example", KeyArgs.builder() .description("HMAC_384 key for tokens") .customerMasterKeySpec("HMAC_384") .keyUsage("GENERATE_VERIFY_MAC") .enableKeyRotation(false) .policy(serializeJson( jsonObject( jsonProperty("Version", "2012-10-17"), jsonProperty("Id", "key-default-1"), jsonProperty("Statement", jsonArray( jsonObject( jsonProperty("Sid", "Enable IAM User Permissions"), jsonProperty("Effect", "Allow"), jsonProperty("Principal", jsonObject( jsonProperty("AWS", String.format("arn:aws:iam::%s:root", current.accountId())) )), jsonProperty("Action", "kms:*"), jsonProperty("Resource", "*") ), jsonObject( jsonProperty("Sid", "Allow administration of the key"), jsonProperty("Effect", "Allow"), jsonProperty("Principal", jsonObject( jsonProperty("AWS", String.format("arn:aws:iam::%s:role/Admin", current.accountId())) )), jsonProperty("Action", jsonArray( "kms:Create*", "kms:Describe*", "kms:Enable*", "kms:List*", "kms:Put*", "kms:Update*", "kms:Revoke*", "kms:Disable*", "kms:Get*", "kms:Delete*", "kms:ScheduleKeyDeletion", "kms:CancelKeyDeletion" )), jsonProperty("Resource", "*") ), jsonObject( jsonProperty("Sid", "Allow use of the key"), jsonProperty("Effect", "Allow"), jsonProperty("Principal", jsonObject( jsonProperty("AWS", String.format("arn:aws:iam::%s:role/Developer", current.accountId())) )), jsonProperty("Action", jsonArray( "kms:GenerateMac", "kms:VerifyMac", "kms:DescribeKey" )), jsonProperty("Resource", "*") ) )) ))) .build()); } }
## Import ### Identity Schema #### Required * `id` - (String) ID of the KMS key. #### Optional * `accountId` (String) AWS Account where this resource is managed. * `region` (String) Region where this resource is managed. Using `pulumi import`, import KMS Keys using the `id`. For example: ```sh $ pulumi import aws:kms/key:Key a 1234abcd-12ab-34cd-56ef-1234567890ab ```package generated_program; import com.pulumi.Context; import com.pulumi.Pulumi; import com.pulumi.core.Output; import com.pulumi.aws.AwsFunctions; import com.pulumi.aws.inputs.GetCallerIdentityArgs; import com.pulumi.aws.kms.Key; import com.pulumi.aws.kms.KeyArgs; import static com.pulumi.codegen.internal.Serialization.*; import java.util.ArrayList; import java.util.Arrays; 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) { final var current = AwsFunctions.getCallerIdentity(GetCallerIdentityArgs.builder() .build()); var example = new Key("example", KeyArgs.builder() .description("An example multi-Region primary key") .multiRegion(true) .enableKeyRotation(true) .deletionWindowInDays(10) .policy(serializeJson( jsonObject( jsonProperty("Version", "2012-10-17"), jsonProperty("Id", "key-default-1"), jsonProperty("Statement", jsonArray( jsonObject( jsonProperty("Sid", "Enable IAM User Permissions"), jsonProperty("Effect", "Allow"), jsonProperty("Principal", jsonObject( jsonProperty("AWS", String.format("arn:aws:iam::%s:root", current.accountId())) )), jsonProperty("Action", "kms:*"), jsonProperty("Resource", "*") ), jsonObject( jsonProperty("Sid", "Allow administration of the key"), jsonProperty("Effect", "Allow"), jsonProperty("Principal", jsonObject( jsonProperty("AWS", String.format("arn:aws:iam::%s:user/Alice", current.accountId())) )), jsonProperty("Action", jsonArray( "kms:ReplicateKey", "kms:Create*", "kms:Describe*", "kms:Enable*", "kms:List*", "kms:Put*", "kms:Update*", "kms:Revoke*", "kms:Disable*", "kms:Get*", "kms:Delete*", "kms:ScheduleKeyDeletion", "kms:CancelKeyDeletion" )), jsonProperty("Resource", "*") ), jsonObject( jsonProperty("Sid", "Allow use of the key"), jsonProperty("Effect", "Allow"), jsonProperty("Principal", jsonObject( jsonProperty("AWS", String.format("arn:aws:iam::%s:user/Bob", current.accountId())) )), jsonProperty("Action", jsonArray( "kms:DescribeKey", "kms:Encrypt", "kms:Decrypt", "kms:ReEncrypt*", "kms:GenerateDataKey", "kms:GenerateDataKeyWithoutPlaintext" )), jsonProperty("Resource", "*") ) )) ))) .build()); } }
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description com.pulumi.core.Output<java.lang.String>arn()com.pulumi.core.Output<java.util.Optional<java.lang.Boolean>>bypassPolicyLockoutSafetyCheck()com.pulumi.core.Output<java.util.Optional<java.lang.String>>customerMasterKeySpec()com.pulumi.core.Output<java.util.Optional<java.lang.String>>customKeyStoreId()com.pulumi.core.Output<java.util.Optional<java.lang.Integer>>deletionWindowInDays()com.pulumi.core.Output<java.lang.String>description()com.pulumi.core.Output<java.util.Optional<java.lang.Boolean>>enableKeyRotation()static Keyget(java.lang.String name, com.pulumi.core.Output<java.lang.String> id, KeyState state, com.pulumi.resources.CustomResourceOptions options)Get an existing Host resource's state with the given name, ID, and optional extra properties used to qualify the lookup.com.pulumi.core.Output<java.util.Optional<java.lang.Boolean>>isEnabled()com.pulumi.core.Output<java.lang.String>keyId()com.pulumi.core.Output<java.util.Optional<java.lang.String>>keyUsage()com.pulumi.core.Output<java.lang.Boolean>multiRegion()com.pulumi.core.Output<java.lang.String>policy()com.pulumi.core.Output<java.lang.String>region()com.pulumi.core.Output<java.lang.Integer>rotationPeriodInDays()com.pulumi.core.Output<java.util.Optional<java.util.Map<java.lang.String,java.lang.String>>>tags()com.pulumi.core.Output<java.util.Map<java.lang.String,java.lang.String>>tagsAll()com.pulumi.core.Output<java.util.Optional<java.lang.String>>xksKeyId()
-
-
-
Constructor Detail
-
Key
public Key(java.lang.String name)
- Parameters:
name- The _unique_ name of the resulting resource.
-
Key
public Key(java.lang.String name, @Nullable KeyArgs args)- Parameters:
name- The _unique_ name of the resulting resource.args- The arguments to use to populate this resource's properties.
-
Key
public Key(java.lang.String name, @Nullable KeyArgs args, @Nullable com.pulumi.resources.CustomResourceOptions options)- Parameters:
name- The _unique_ name of the resulting resource.args- The arguments to use to populate this resource's properties.options- A bag of options that control this resource's behavior.
-
-
Method Detail
-
arn
public com.pulumi.core.Output<java.lang.String> arn()
- Returns:
- ARN of the key.
-
bypassPolicyLockoutSafetyCheck
public com.pulumi.core.Output<java.util.Optional<java.lang.Boolean>> bypassPolicyLockoutSafetyCheck()
- Returns:
- Whether to bypass the key policy lockout safety check. Setting this value to true increases the risk that the KMS key becomes unmanageable. Do not set this value to true indiscriminately. For more information, refer to the scenario in the [Default Key Policy](https://docs.aws.amazon.com/kms/latest/developerguide/key-policies.html#key-policy-default-allow-root-enable-iam) section in the _AWS KMS Developer Guide_. The default value is `false`.
-
customKeyStoreId
public com.pulumi.core.Output<java.util.Optional<java.lang.String>> customKeyStoreId()
- Returns:
- ID of the KMS [Custom Key Store](https://docs.aws.amazon.com/kms/latest/developerguide/create-cmk-keystore.html) where the key will be stored instead of KMS (eg CloudHSM).
-
customerMasterKeySpec
public com.pulumi.core.Output<java.util.Optional<java.lang.String>> customerMasterKeySpec()
- Returns:
- Whether the key contains a symmetric key or an asymmetric key pair and the encryption algorithms or signing algorithms that the key supports. Valid values: `SYMMETRIC_DEFAULT`, `RSA_2048`, `RSA_3072`, `RSA_4096`, `HMAC_224`, `HMAC_256`, `HMAC_384`, `HMAC_512`, `ECC_NIST_P256`, `ECC_NIST_P384`, `ECC_NIST_P521`, `ECC_SECG_P256K1`, `ML_DSA_44`, `ML_DSA_65`, `ML_DSA_87`, `SM2` (China Regions only), or `ECC_NIST_EDWARDS25519`. Defaults to `SYMMETRIC_DEFAULT`. For help with choosing a key spec, see the [AWS KMS Developer Guide](https://docs.aws.amazon.com/kms/latest/developerguide/symm-asymm-choose.html).
-
deletionWindowInDays
public com.pulumi.core.Output<java.util.Optional<java.lang.Integer>> deletionWindowInDays()
- Returns:
- Waiting period, specified in number of days. After the waiting period ends, AWS KMS deletes the KMS key. If you specify a value, it must be between `7` and `30`, inclusive. If you do not specify a value, it defaults to `30`. If the KMS key is a multi-Region primary key with replicas, the waiting period begins when the last of its replica keys is deleted. Otherwise, the waiting period begins immediately.
-
description
public com.pulumi.core.Output<java.lang.String> description()
- Returns:
- Description of the key as viewed in AWS console.
-
enableKeyRotation
public com.pulumi.core.Output<java.util.Optional<java.lang.Boolean>> enableKeyRotation()
- Returns:
- Whether [key rotation](http://docs.aws.amazon.com/kms/latest/developerguide/rotate-keys.html) is enabled. Defaults to `false`.
-
isEnabled
public com.pulumi.core.Output<java.util.Optional<java.lang.Boolean>> isEnabled()
- Returns:
- Whether the key is enabled. Defaults to `true`.
-
keyId
public com.pulumi.core.Output<java.lang.String> keyId()
- Returns:
- Globally unique identifier for the key.
-
keyUsage
public com.pulumi.core.Output<java.util.Optional<java.lang.String>> keyUsage()
- Returns:
- Intended use of the key. Valid values: `ENCRYPT_DECRYPT`, `SIGN_VERIFY`, or `GENERATE_VERIFY_MAC`. Defaults to `ENCRYPT_DECRYPT`.
-
multiRegion
public com.pulumi.core.Output<java.lang.Boolean> multiRegion()
- Returns:
- Whether the KMS key is a multi-Region (`true`) or regional (`false`) key. Defaults to `false`.
-
policy
public com.pulumi.core.Output<java.lang.String> policy()
- Returns:
- Valid policy JSON document. Although this is a key policy, not an IAM policy, an `aws.iam.getPolicyDocument`, in the form that designates a principal, can be used. For more information about building policy documents with Terraform, see the AWS IAM Policy Document Guide.
-
region
public com.pulumi.core.Output<java.lang.String> region()
- Returns:
- Region where this resource will be [managed](https://docs.aws.amazon.com/general/latest/gr/rande.html#regional-endpoints). Defaults to the Region set in the provider configuration.
-
rotationPeriodInDays
public com.pulumi.core.Output<java.lang.Integer> rotationPeriodInDays()
- Returns:
- Custom period of time between each rotation date. Must be a number between 90 and 2560 (inclusive).
-
tags
public com.pulumi.core.Output<java.util.Optional<java.util.Map<java.lang.String,java.lang.String>>> tags()
- Returns:
- Map of tags to assign to the object. If configured with a provider `defaultTags` configuration block present, tags with matching keys will overwrite those defined at the provider-level.
-
tagsAll
public com.pulumi.core.Output<java.util.Map<java.lang.String,java.lang.String>> tagsAll()
- Returns:
- Map of tags assigned to the resource, including those inherited from the provider `defaultTags` configuration block.
-
xksKeyId
public com.pulumi.core.Output<java.util.Optional<java.lang.String>> xksKeyId()
- Returns:
- External key that serves as key material for the KMS key in an external key store. > **NOTE:** Note: All KMS keys must have a key policy. If a key policy is not specified, AWS gives the KMS key a [default key policy](https://docs.aws.amazon.com/kms/latest/developerguide/key-policies.html#key-policy-default) that gives all principals in the owning account unlimited access to all KMS operations for the key. This default key policy effectively delegates all access control to IAM policies and KMS grants.
-
get
public static Key get(java.lang.String name, com.pulumi.core.Output<java.lang.String> id, @Nullable KeyState state, @Nullable com.pulumi.resources.CustomResourceOptions options)
Get an existing Host resource's state with the given name, ID, and optional extra properties used to qualify the lookup.- Parameters:
name- The _unique_ name of the resulting resource.id- The _unique_ provider ID of the resource to lookup.state-options- Optional settings to control the behavior of the CustomResource.
-
-