alicloud_kms_key
Provides a KMS Key resource.
For information about KMS Key and how to use it, see What is Key.
-> NOTE: Available since v1.85.0.
Example Usage
Basic Usage
resource "alicloud_kms_key" "default" {
description = "Hello KMS"
status = "Enabled"
pending_window_in_days = "7"
}
Need more examples? VIEW MORE EXAMPLES
Argument Reference
The following arguments are supported:
-
automatic_rotation- (Optional) Specifies whether to enable automatic key rotation. Default value:Disabled. Valid values:Enabled,Disabled. -
deletion_protection- (Optional, Available since v1.240.0) Specifies whether to enable deletion protection. Default value:Disabled. Valid values:Enabled,Disabled. -
deletion_protection_description- (Optional, Available since v1.240.0) The description of deletion protection. NOTE:deletion_protection_descriptiontakes effect only ifdeletion_protectionis set toEnabled. -
description- (Optional) The description of the key. -
dkms_instance_id- (Optional, ForceNew, Available since v1.183.0) The ID of the KMS instance. If specified, the key is created in the specified KMS instance; if omitted, a default key (master key) is created in the current region.NOTE: The two types of keys differ in capability: only keys in KMS instances support key policies (
policy), and the valid values ofkey_specandrotation_intervalare determined by the key management type. For more information, see CreateKey. -
key_spec- (Optional, ForceNew) The specification of the key. Default value:Aliyun_AES_256. Valid values:Aliyun_AES_256,Aliyun_AES_128,Aliyun_AES_192,Aliyun_SM4,RSA_2048,RSA_3072,EC_P256,EC_P256K,EC_SM2.NOTE: The valid values vary based on the key management type. For keys in KMS instances, the supported specifications are determined by the instance type.
-
key_usage- (Optional, ForceNew) The usage of the key. Default value:ENCRYPT/DECRYPT. Valid values:ENCRYPT/DECRYPT: Encrypts or decrypts data.SIGN/VERIFY: Generates or verifies a digital signature.
-
origin- (Optional, ForceNew) The key material origin. Default value:Aliyun_KMS. Valid values:Aliyun_KMS,EXTERNAL. -
pending_window_in_days- (Optional, Int) The number of days before the CMK is deleted. During this period, the CMK is in the PendingDeletion state. After this period ends, you cannot cancel the deletion. Unit: days. Valid values:7to366. NOTE: From version 1.184.0,pending_window_in_dayscan be set to366. -
policy- (Optional, Available since v1.224.0) The content of the key policy. The value is in the JSON format. The value can be up to 32,768 bytes in length. For more information, see How to use it.NOTE: This parameter takes effect only on keys in KMS instances (
dkms_instance_idspecified). Default keys do not support key policies, and this parameter does not take effect on them. -
protection_level- (Optional, ForceNew) The protection level of the key. Default value:SOFTWARE. Valid values:SOFTWARE,HSM.NOTE: The default value does not take effect when
dkms_instance_idis specified. In this case, this parameter is ignored and the instance type determines the protection level: keys in a software key management instance areSOFTWARE, and keys in a hardware key management instance areHSM. For keys whose actual protection level isHSM(such as hardware instance keys), explicitly setprotection_leveltoHSM. Otherwise, the configuration (defaultSOFTWARE) never matches the actual level and Terraform forces key recreation on every apply. -
rotation_interval- (Optional) The period of automatic key rotation. The following units are supported: d (day), h (hour), m (minute), and s (second). For example, you can use either 7d or 604800s to specify a seven-day interval.NOTE: This parameter is required if
automatic_rotationis set toEnabled, and takes effect only when the key management type supports automatic rotation: default keys support only a fixed period of 365 days, software-protected keys support 7 to 365 days, and hardware-protected keys do not support automatic rotation. -
status- (Optional, Available since v1.123.1) The status of key. Default value:Enabled. Valid values:Enabled,Disabled,PendingDeletion. -
tags- (Optional, Map, Available since v1.207.0) A mapping of tags to assign to the resource. -
deletion_window_in_days- (Optional, Int, Deprecated since v1.85.0) Fielddeletion_window_in_dayshas been deprecated from provider version 1.85.0. New fieldpending_window_in_daysinstead. -
key_state- (Deprecated since v1.123.1) Fieldkey_statehas been deprecated from provider version 1.123.1. New fieldstatusinstead. -
is_enabled- (Optional, Bool, Deprecated since v1.85.0) Fieldis_enabledhas been deprecated from provider version 1.85.0. New fieldstatusinstead.-> NOTE: If you set the origin parameter to EXTERNAL or the key_spec parameter to an asymmetric CMK type, automatic key rotation is unavailable.
-> NOTE: The default type of the CMK is
Aliyun_AES_256. Only keys in KMS instances supportAliyun_AES_128andAliyun_AES_192.-> NOTE: When the pre-deletion days elapses, the key is permanently deleted and cannot be recovered.
Attributes Reference
id- The resource ID in terraform of Key.arn- The ARN of the key.primary_key_version- The ID of the current primary key version of the symmetric CMK.last_rotation_date- The time when the last rotation was performed.next_rotation_date- The time when the next rotation will be performed.material_expire_time- The time when the key material expires.creator- The creator of the CMK.creation_date- The time when the CMK was created.delete_date- The time at which the CMK is scheduled for deletion.
Timeouts
-> NOTE: Available since v1.224.0.
The timeouts block allows you to specify timeouts for certain actions:
create- (Defaults to 5 mins) Used when create the Key.update- (Defaults to 5 mins) Used when update the Key.delete- (Defaults to 5 mins) Used when delete the Key.
Import
KMS Key can be imported using the id, e.g.
$ terraform import alicloud_kms_key.example <id>