diff --git a/lib/argument-store.js b/lib/argument-store.js index b03bf44..c943aa5 100644 --- a/lib/argument-store.js +++ b/lib/argument-store.js @@ -14,6 +14,7 @@ class ArgumentStore { "SEMAPHORE_AGENT_ASG_MAX_SIZE": "1", "SEMAPHORE_AGENT_ASG_DESIRED": "", "SEMAPHORE_AGENT_ASG_METRICS": "", + "SEMAPHORE_AGENT_ASG_MAX_INSTANCE_LIFETIME": "0", "SEMAPHORE_AGENT_DISCONNECT_AFTER_JOB": "true", "SEMAPHORE_AGENT_DISCONNECT_AFTER_IDLE_TIMEOUT": "300", "SEMAPHORE_AGENT_OS": "ubuntu-focal", diff --git a/lib/aws-semaphore-agent-stack.js b/lib/aws-semaphore-agent-stack.js index 5f17c82..53e527b 100644 --- a/lib/aws-semaphore-agent-stack.js +++ b/lib/aws-semaphore-agent-stack.js @@ -473,6 +473,11 @@ class AwsSemaphoreAgentStack extends Stack { ], }); + const maxInstanceLifetime = this.argumentStore.getAsNumber("SEMAPHORE_AGENT_ASG_MAX_INSTANCE_LIFETIME"); + if (maxInstanceLifetime !== 0) { + autoScalingGroup.maxInstanceLifetime = maxInstanceLifetime; + } + // if the desired capacity is not specified, leave it empty. // Setting a default desired capacity leads to Cloudformation resetting it during an in-place update. // That can be an issue if you have your stack configured to automatically scale up/down, so we don't do that here. diff --git a/test/aws-semaphore-agent.test.js b/test/aws-semaphore-agent.test.js index eb642b5..9948972 100644 --- a/test/aws-semaphore-agent.test.js +++ b/test/aws-semaphore-agent.test.js @@ -531,7 +531,7 @@ describe("auto scaling group", () => { template.hasResourceProperties("AWS::AutoScaling::AutoScalingGroup", { DesiredCapacity: Match.absent(), MinSize: "0", - MaxSize: "1" + MaxSize: "1", }); }) @@ -630,6 +630,15 @@ describe("auto scaling group", () => { template.resourceCountIs("AWS::CloudFormation::CustomResource", 1); }) + + test("max instance lifetime is set", () => { + const argumentStore = basicArgumentStore(); + argumentStore.set("SEMAPHORE_AGENT_ASG_MAX_INSTANCE_LIFETIME", 86400); + const template = createTemplate(argumentStore); + template.hasResourceProperties("AWS::AutoScaling::AutoScalingGroup", { + MaxInstanceLifetime: 86400, + }); + }) }) describe("scaler lambda", () => {