Skip to content

Commit 97b1cb7

Browse files
committed
feat: Add support for direct KMS key ID in volume encryption
1 parent 004982f commit 97b1cb7

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

pkg/aws/ec2.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -622,10 +622,20 @@ func (e EC2Client) MakeLaunchTemplateBlockDeviceMappings(blocks []schemas.BlockD
622622
var LaunchTemplateEbsBlockDevice *ec2.LaunchTemplateEbsBlockDeviceRequest
623623

624624
if enabledEBSEncrypted {
625-
keyId, err := e.getKmsKeyIdByAlias(block.KmsAlias)
626-
if err != nil {
627-
Logger.Fatal(fmt.Sprintf("Error: %s", err.Error()))
625+
var keyId string
626+
var err error
627+
628+
// Priority: KmsKeyId > KmsAlias
629+
if len(block.KmsKeyId) > 0 {
630+
keyId = block.KmsKeyId
631+
Logger.Infof("Using provided KMS Key ID: %s", keyId)
632+
} else {
633+
keyId, err = e.getKmsKeyIdByAlias(block.KmsAlias)
634+
if err != nil {
635+
Logger.Fatal(fmt.Sprintf("Error: %s", err.Error()))
636+
}
628637
}
638+
629639
LaunchTemplateEbsBlockDevice = &ec2.LaunchTemplateEbsBlockDeviceRequest{
630640
VolumeSize: aws.Int64(block.VolumeSize),
631641
VolumeType: aws.String(block.VolumeType),

pkg/schemas/config.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,12 @@ type BlockDevice struct {
249249
// Enable Encrypted
250250
Encrypted bool `yaml:"encrypted"`
251251

252-
// KMS key
252+
// KMS key alias
253253
KmsAlias string `yaml:"kmsAlias"`
254254

255+
// KMS key ID (ARN or key ID)
256+
KmsKeyId string `yaml:"kmsKeyId"`
257+
255258
// Whether to delete the volume on instance termination
256259
DeleteOnTermination bool `yaml:"delete_on_termination"`
257260
}

0 commit comments

Comments
 (0)