hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.77k stars 9.12k forks source link

[Bug]: Increase of root volume size of AMI in launch template block_device_mapping does not work on arm64 instances but on x86_64 #37559

Open sstoefe opened 4 months ago

sstoefe commented 4 months ago

Terraform Core Version

1.8.2

AWS Provider Version

5.47.0

Affected Resource(s)

Expected Behavior

When I spawn an ec2 x86_64 instance (in this case it was m5zn.metal) via EC2 Fleet API and increase the root volume size via block_device_mapping block inside the aws_launch_template the actual device and partitions are enlarged and work as expected:

image

A default ubuntu 20.04 server AMI (x86_64) was used here. By default the AMI has a volume_size of 8GB. With the block_device_mapping is is increased to 40GB.

When I spawn an arm64 instance (c7g.metal) I expect the same behaviour. Also ubuntu server 20.04 AMI (arm64) is used. By default the AMI has a volume_size of 8GB.

Actual Behavior

However, when I spawn an arm64 instance (c7g.metal) I see that the actual volume is enlarged but the partition is not. There I have to increase the filesystem manually (see https://docs.aws.amazon.com/ebs/latest/userguide/recognize-expanded-volume-linux.html):

image image

Relevant Error/Panic Output Snippet

No response

Terraform Configuration Files

# Fetch latest ubuntu AMI
data "aws_ami" "ubuntu_ami" {
  most_recent = true

  filter {
    name   = "name"
    values = ["ubuntu/images/*ubuntu-focal-20.04-${var.cpu_architecture == "x86_64" ? "amd64" : "arm64"}-server-*"]
  }

  filter {
    name   = "virtualization-type"
    values = ["hvm"]
  }

  filter {
    name   = "architecture"
    values = ["${var.cpu_architecture}"]
  }

  owners = ["099720109477"] # Canonical
}

locals {
  allowed_instance_types    = var.cpu_architecture == "x86_64" ? var.spot_instances_x86_64 : var.spot_instances_arm64
  on_demand_target_capacity = var.cpu_architecture == "x86_64" ? 0 : 1
  spot_target_capacity      = var.cpu_architecture == "x86_64" ? 1 : 0
}

# launch template for EC2 fleet API
resource "aws_launch_template" "launch_template" {
  block_device_mappings {
    device_name = data.aws_ami.ubuntu_ami.root_device_name

    ebs {
      volume_size = 40
    }
  }
  ...
}

# EC2 fleet request
resource "aws_ec2_fleet" "instance" {
  launch_template_config {
    launch_template_specification {
      launch_template_id = aws_launch_template.launch_template.id
      version                      = aws_launch_template.launch_template.latest_version
    }
  }

  target_capacity_specification {
    default_target_capacity_type = "spot"
    on_demand_target_capacity    = local.on_demand_target_capacity
    spot_target_capacity         = local.spot_target_capacity
    total_target_capacity        = 1
  }

  on_demand_options {
    allocation_strategy      = "lowestPrice"
    single_availability_zone = true
    min_target_capacity      = local.on_demand_target_capacity
  }

  spot_options {
    allocation_strategy = "price-capacity-optimized"
  }

  terminate_instances = true

  type = "instant"
}

Steps to Reproduce

  1. terraform init
  2. terraform apply
  3. login to arm64 instance and check volume size

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

No response

Would you like to implement a fix?

None

github-actions[bot] commented 4 months ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue