pulumi / pulumi-aws

An Amazon Web Services (AWS) Pulumi resource package, providing multi-language access to AWS
Apache License 2.0
459 stars 155 forks source link

Modifying instance type is not allowed #4291

Open olly-writes-code opened 2 months ago

olly-writes-code commented 2 months ago

What happened?

Hi, I'm trying to increase an AWS Instance type from g5.4xlarge to p4d.24xlarge.

Upon running pulumi up I get the following error

attribute: operation error EC2: ModifyInstanceAttribute, https response error StatusCode: 400, RequestID: xyz, api error InvalidInstanceAttributeValue: Modifying the instance type from g5.4xlarge to p4d.24xlarge is not allowed.

This means I must terminate the machine manually to increase it to a p4d.24xlarge. Shouldn't Pulumi be able to handle something like this rather than me having to solve this via the AWS console?

Example

Spin up a g5.4xlarge ec2 instance using pulumi up and then change that instance to a p4d.24xlarge and run pulumi up again

Output of pulumi about

CLI
Version      3.122.0
Go Version   go1.22.4
Go Compiler  gc
Plugins
KIND      NAME    VERSION
resource  aws     6.45.0
language  python  unknown
Host
OS       darwin
Version  14.5
Arch     arm64

Dependencies:
NAME        VERSION
pip         24.0
pulumi_aws  6.45.0
setuptools  69.2.0

Additional context

No response

Contributing

Vote on this issue by adding a 👍 reaction. To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

t0yv0 commented 2 months ago

Can you please provide a full repro of the problem?

This program works as expected:

import * as pulumi from "@pulumi/pulumi";

const cfg = new pulumi.Config();
const step = cfg.requireNumber("step");

import * as aws from "@pulumi/aws";

const ubuntu = aws.ec2.getAmi({
    mostRecent: true,
    filters: [
        {
            name: "name",
            values: ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"],
        },
        {
            name: "virtualization-type",
            values: ["hvm"],
        },
    ],
    owners: ["099720109477"],
});

const web = new aws.ec2.Instance("web", {
    ami: ubuntu.then(ubuntu => ubuntu.id),
    instanceType: step===0 ? aws.ec2.InstanceType.T3_Micro : aws.ec2.InstanceType.T3_Small,
    tags: {
        Name: "HelloWorld",
    },
});

export const webId = web.id;
#!/usr/bin/env bash

set -euo pipefail

pulumi destroy --yes

pulumi config set step 0
pulumi up --yes --skip-preview

pulumi config set step 1
pulumi preview --diff
pulumi up --skip-preview
olly-writes-code commented 2 months ago

Hi @t0yv0! 👋

Thanks for helping out! Here's a minimal script to reproduce the error.

Running

#!/usr/bin/env bash

set -euo pipefail

pulumi destroy --yes

pulumi config set step 0
pulumi up --yes --skip-preview

pulumi config set step 1
pulumi preview --diff
pulumi up --skip-preview

Note - these instance types will only be available in us-east-1, and you may need quota to have access to the p4d.24xlarge

import * as pulumi from "@pulumi/pulumi";

const cfg = new pulumi.Config();
const step = cfg.requireNumber("step");

import * as aws from "@pulumi/aws";

const ubuntu = aws.ec2.getAmi({
    mostRecent: true,
    filters: [
        {
            name: "name",
            values: ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"],
        },
        {
            name: "virtualization-type",
            values: ["hvm"],
        },
    ],
    owners: ["099720109477"],
});

const web = new aws.ec2.Instance("web", {
    ami: ubuntu.then(ubuntu => ubuntu.id),
    instanceType: step === 0 ? "g5.4xlarge" : "p4d.24xlarge",
    tags: {
        Name: "HelloWorld",
    },
});

export const webId = web.id;

Here's the output I get

Previewing update (dev3)

View Live: xyz

  pulumi:pulumi:Stack: (same)
    [urn=urn:pulumi:dev3::testing::pulumi:pulumi:Stack::testing-dev3]
    ~ aws:ec2/instance:Instance: (update)
        [id=i-0e716b845383d65a8]
        [urn=urn:pulumi:dev3::testing::aws:ec2/instance:Instance::web]
        [provider=urn:pulumi:dev3::testing::pulumi:providers:aws::default_6_46_0::ef3f8849-06ef-45a9-be35-b9eb9287f279]
      ~ instanceType: "g5.4xlarge" => "p4d.24xlarge"
Resources:
    ~ 1 to update
    1 unchanged
Updating (dev3)

View in Browser (Ctrl+O): xyz

     Type                 Name          Status                  Info
     pulumi:pulumi:Stack  testing-dev3  **failed**              1 error
 ~   └─ aws:ec2:Instance  web           **updating failed**     [diff: ~instanceType]; 1 error

Diagnostics:
  pulumi:pulumi:Stack (testing-dev3):
    error: update failed

  aws:ec2:Instance (web):
    error: 1 error occurred:
        * updating urn:pulumi:dev3::testing::aws:ec2/instance:Instance::web: 1 error occurred:
        * updating EC2 Instance (i-0e716b845383d65a8) type: modifying EC2 Instance (i-0e716b845383d65a8) InstanceType (p4d.24xlarge) attribute: operation error EC2: ModifyInstanceAttribute, https response error StatusCode: 400, RequestID: d20e2444-daf2-4c3c-9767-8f9b82143ad6, api error InvalidInstanceAttributeValue: Modifying the instance type from g5.4xlarge to p4d.24xlarge is not allowed.

Outputs:
  - webId: "i-0e716b845383d65a8"

Resources:
    1 unchanged

Duration: 3m6s
t0yv0 commented 2 months ago

Ah thanks for following up on that. It appears that some particular instance type pairs are not compatible. I have filed https://github.com/hashicorp/terraform-provider-aws/issues/38536 as this behavior is an issue with terraform-provider-aws and is best addressed there. As a workaround you can use replaceOnChanges Resource Option to force a replacement plan for this case.

t0yv0 commented 2 months ago

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/resize-limitations.html looks relevant for all the constraints involved.

olly-writes-code commented 2 months ago

Thanks @t0yv0. That makes sense. Appreciate you taking the time to raise the bug :)