Skip to content

aws_instance: resolve:ssm:/ ami not working in combination w/ root_block_device #43488

@aleshav

Description

@aleshav

Terraform and AWS Provider Version

# terraform version
Terraform v1.12.2
on linux_amd64
+ provider registry.opentofu.org/hashicorp/aws v6.4.0
+ provider registry.terraform.io/hashicorp/aws v6.4.0

Affected Resource(s) or Data Source(s)

resource "aws_instance"
...terraform config...

Expected Behavior

The ami should be looked up in ssm and instance created. This is what happens when there is no root_block_device definition.

Actual Behavior

Getting the following error:

Error: collecting instance settings: operation error EC2: DescribeImages, https response error StatusCode: 400, RequestID: c4fdfe66-6f8e-4f9e-933e-869698dda468, api error InvalidAMIID.Malformed: Invalid id: "resolve:ssm:/aws/service/canonical/ubuntu/server-minimal/24.04/stable/current/amd64/hvm/ebs-gp3/ami-id" (expecting "ami-...")

Relevant Error/Panic Output

07:51:23.972 STDOUT terraform: module.ec2_instance.aws_instance.this: Creating...
07:51:25.569 STDERR terraform: ╷
07:51:25.569 STDERR terraform: │ Error: collecting instance settings: operation error EC2: DescribeImages, https response error StatusCode: 400, RequestID: c4fdfe66-6f8e-4f9e-933e-869698dda468, api error InvalidAMIID.Malformed: Invalid id: "resolve:ssm:/aws/service/canonical/ubuntu/server-minimal/24.04/stable/current/amd64/hvm/ebs-gp3/ami-id" (expecting "ami-...")
07:51:25.569 STDERR terraform: │ 
07:51:25.569 STDERR terraform: │   with module.ec2_instance.aws_instance.this,
07:51:25.569 STDERR terraform: │   on ../../../../modules/aws/ec2_instance/1.0/main.tf line 16, in resource "aws_instance" "this":
07:51:25.570 STDERR terraform: │   16: resource "aws_instance" "this" {
07:51:25.570 STDERR terraform: │ 
07:51:25.570 STDERR terraform: ╵
07:51:25.969 STDOUT terraform: Releasing state lock. This may take a few moments...
07:51:26.103 ERROR  terraform invocation failed in .
07:51:26.103 ERROR  error occurred:

* Failed to execute "terraform apply" in .

  │ Error: collecting instance settings: operation error EC2: DescribeImages, https response error StatusCode: 400, RequestID: c4fdfe66-6f8e-4f9e-933e-869698dda468, api error InvalidAMIID.Malformed: Invalid id: "resolve:ssm:/aws/service/canonical/ubuntu/server-minimal/24.04/stable/current/amd64/hvm/ebs-gp3/ami-id" (expecting "ami-...")

Sample Terraform Configuration

Click to expand configuration
resource "aws_instance" "this" {
  ami           = "resolve:ssm:/aws/service/canonical/ubuntu/server-minimal/24.04/stable/current/amd64/hvm/ebs-gp3/ami-id"
  instance_type = "t3a.small"
  subnet_id     = data.aws_subnet.main.id

  associate_public_ip_address = true

  root_block_device {
    volume_type = "gp3"
    volume_size = 10
    tags = {
      "Name" = "root"
    }
  }
}

Steps to Reproduce

terraform init
terraform apply

Debug Logging

Click to expand log output

GenAI / LLM Assisted Development

n/a

Important Facts and References

when root_block_device block is ommited, all works as expected:

resource "aws_instance" "this" {
  ami           = "resolve:ssm:/aws/service/canonical/ubuntu/server-minimal/24.04/stable/current/amd64/hvm/ebs-gp3/ami-id"
  instance_type = "t3a.small"
  subnet_id     = data.aws_subnet.main.id

  associate_public_ip_address = true

}
...terraform config...

Would you like to implement a fix?

No

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAddresses a defect in current functionality.service/ec2Issues and PRs that pertain to the ec2 service.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions