Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(autoscaling): AutoScalingGroup requireImdsv2 with launchTemplate or mixedInstancesPolicy throws unclear error #32220

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1758,6 +1758,9 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements
if (props.blockDevices) {
throw new Error('Setting \'blockDevices\' must not be set when \'launchTemplate\' or \'mixedInstancesPolicy\' is set');
}
if (props.requireImdsv2) {
throw new Error('Setting \'requireImdsv2\' must not be set when \'launchTemplate\' or \'mixedInstancesPolicy\' is set');
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2947,6 +2947,26 @@ describe('InstanceMaintenancePolicy', () => {
});
}).toThrow(/The difference between minHealthyPercentage and maxHealthyPercentage cannot be greater than 100, got 200/);
});

test('throws if requireImdsv2 set when launchTemplate is set', () => {
// GIVEN
const stack = new cdk.Stack();
stack.node.setContext(AUTOSCALING_GENERATE_LAUNCH_TEMPLATE, true);
const vpc = mockVpc(stack);
const lt = LaunchTemplate.fromLaunchTemplateAttributes(stack, 'imported-lt', {
launchTemplateId: 'test-lt-id',
versionNumber: '0',
});

// THEN
expect(() => {
new autoscaling.AutoScalingGroup(stack, 'MyFleet', {
vpc,
launchTemplate: lt,
requireImdsv2: true,
});
}).toThrow(/Setting \'requireImdsv2\' must not be set when \'launchTemplate\' or \'mixedInstancesPolicy\' is set/);
});
});

function mockSecurityGroup(stack: cdk.Stack) {
Expand Down
Loading