Skip to content

aws_launch_template failed when block_device_mappings.ebs.kms_key_id` is set to an empty string #44648

@quentin9696

Description

@quentin9696

Terraform and AWS Provider Version

Terraform v1.13.3
on linux_amd64
+ provider registry.terraform.io/hashicorp/aws v6.16.0

Affected Resource(s) or Data Source(s)

  • aws_launch_template

Expected Behavior

Apply sucessfully even if kms_key_id is set to an empty string, as most of other arguments of this resource

Actual Behavior

Give the following error:

Error: "block_device_mappings.0.ebs.0.kms_key_id" cannot be shorter than 1 character

Relevant Error/Panic Output

No response

Sample Terraform Configuration

Click to expand configuration
provider "aws" {
  region = "us-east-1"
}

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "6.16.0"
    }
  }
}

data "aws_ssm_parameter" "this" {
  name = "/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-ebs"
}


resource "aws_launch_template" "this" {
  name = "failling_asg"

  image_id      = data.aws_ssm_parameter.this.value
  instance_type = "t3.small"

  block_device_mappings {
    device_name = "/dev/xvda"

    ebs {
      delete_on_termination = true
      kms_key_id            = ""
    }
  }
}

Steps to Reproduce

  1. apply
  2. get the error

Debug Logging

n/a

GenAI / LLM Assisted Development

n/a

Important Facts and References

This code perfectly run with 6.15.0, I guess this is related to the this PR #44505

The current workaround is to change kms_key_id to null instead of empty string. This isn't consistent with most of resources

Would you like to implement a fix?

No

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAddresses a defect in current functionality.regressionPertains to a degraded workflow resulting from an upstream patch or internal enhancement.service/ec2Issues and PRs that pertain to the ec2 service.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions