https://pulumi.com logo
Title
r

red-flower-37420

04/27/2023, 3:15 PM
I'm running into an issue resizing the additional volume on a EC2 instance launched from an AMI with that additional volume. When I try to increase the volume size, Pulumi wants to replace the instance. I created some simplified code to demonstrate the issue: If I Pulumi up this, it creates everything as expected. Uncomment the ebs_block_devices block and pulumi up again - triggers instance replacement instead of just increasing the volume's size. Has anybody else run into this? I'd like to be able to resize the drive without nuking the instance.
"""Testing Multi-Volume AMIs and Post-Deploy Volume Resizing"""

import pulumi
import pulumi_aws as aws

ubuntu_ami = aws.ec2.get_ami(most_recent=True,
    filters=[
        aws.ec2.GetAmiFilterArgs(
            name="name",
            values=["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"],
        ),
        aws.ec2.GetAmiFilterArgs(
            name="virtualization-type",
            values=["hvm"],
        ),
    ],
    owners=["099720109477"])

# Create an instance with an addditional volume
test_ami_origin = aws.ec2.Instance(
    "test_ami_origin",
    ami=ubuntu_ami.id,
    instance_type="t3.micro",
    tags={"Name": "test_ami_origin",},
    ebs_block_devices=[
        aws.ec2.InstanceEbsBlockDeviceArgs(
            device_name="/dev/sdc",
            volume_size=200,
            volume_type="gp2",
        )
    ],
    subnet_id="subnet-014a297abc46f0170"
    )

# Create an AMI from that instance
prod_ppgdb_ami = aws.ec2.AmiFromInstance(
    "prod_ppgdb_ami",
    source_instance_id=test_ami_origin.id,
)

# First, create a new instance from that AMI,
# Then, uncomment the ebs_block_devices attribute and `pulumi up` again.
# This will trigger replacement of the entire instance, instead of resizing the drive.
test_instance_from_ami = aws.ec2.Instance(
    "test_instance_from_ami",
    ami=prod_ppgdb_ami.id,
    instance_type="t3.micro",
    subnet_id="subnet-014a297abc46f0170",
    # ebs_block_devices=[
    #     aws.ec2.InstanceEbsBlockDeviceArgs(
    #         device_name="/dev/sdc",
    #         volume_size=250,
    #         volume_type="gp2",
    #     )]
    )
b

billowy-army-68599

04/27/2023, 4:14 PM
i believe this is expected behaviour, if you modify the block device size it triggers a replacement. if you want to resize the device, you’ll need to do it manually
r

red-flower-37420

04/27/2023, 4:20 PM
Hmm - do you know why that is? Since the volume can be resized from the console, I expected to be able to do the same with Pulumi.
b

billowy-army-68599

04/27/2023, 4:24 PM
because it’s defined inline in the ec2 instance, if you define it with this resource you can resize it https://www.pulumi.com/registry/packages/aws/api-docs/ebs/volume/
r

red-flower-37420

04/27/2023, 4:26 PM
Gotcha yeah I was just thinking of the ebs.Volume approach.I think that'll work for us fine for normal instances, but I can't use that when the instance comes with multiple volumes that come over from the AMI.
To do it in code, I guess I could use get_volume to retrieve the volume info and then use botocore to increase the volume's size. But... if that's the case, why can't Pulumi do the same?