Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions fixtures/11.output.v2-websocket-authorizer.json
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,10 @@
"CodeDeployServiceRole",
"Arn"
]
},
"AlarmConfiguration": {
"Alarms": [],
"Enabled": false
}
}
},
Expand Down
8 changes: 8 additions & 0 deletions fixtures/13.output.multiple-function-hooks.json
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,10 @@
"DeploymentStyle": {
"DeploymentType": "BLUE_GREEN",
"DeploymentOption": "WITH_TRAFFIC_CONTROL"
},
"AlarmConfiguration": {
"Alarms": [],
"Enabled": false
}
}
},
Expand Down Expand Up @@ -409,6 +413,10 @@
"DeploymentStyle": {
"DeploymentType": "BLUE_GREEN",
"DeploymentOption": "WITH_TRAFFIC_CONTROL"
},
"AlarmConfiguration": {
"Alarms": [],
"Enabled": false
}
}
},
Expand Down
8 changes: 8 additions & 0 deletions fixtures/17.output.elbV2-with-provisioned-concurrency.json
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,10 @@
"DeploymentStyle": {
"DeploymentType": "BLUE_GREEN",
"DeploymentOption": "WITH_TRAFFIC_CONTROL"
},
"AlarmConfiguration": {
"Alarms": [],
"Enabled": false
}
}
},
Expand Down Expand Up @@ -460,6 +464,10 @@
"DeploymentStyle": {
"DeploymentType": "BLUE_GREEN",
"DeploymentOption": "WITH_TRAFFIC_CONTROL"
},
"AlarmConfiguration": {
"Alarms": [],
"Enabled": false
}
}
},
Expand Down
4 changes: 4 additions & 0 deletions fixtures/20.output.canary-alarms-mixed.json
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,10 @@
"CodeDeployServiceRole",
"Arn"
]
},
"AlarmConfiguration": {
"Alarms": [],
"Enabled": false
}
}
},
Expand Down
19 changes: 8 additions & 11 deletions lib/CfTemplateGenerators/CodeDeploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,14 @@ function buildFnDeploymentGroup ({ codeDeployAppName, codeDeployGroupName, codeD
const lookupRole = { 'Fn::GetAtt': ['CodeDeployServiceRole', 'Arn'] }
const roleArn = codeDeployRoleArn || lookupRole
Object.assign(deploymentGroup.Properties, { ServiceRoleArn: roleArn })
if (deploymentSettings.alarms) {
const alarmNames = deploymentSettings.alarms.map(a => {
const name = _.propOr({ Ref: a }, 'name', a)
return { Name: name }
})
const alarmConfig = {
Alarms: alarmNames,
Enabled: true
}
Object.assign(deploymentGroup.Properties, { AlarmConfiguration: alarmConfig })
}
const alarmNames = (deploymentSettings.alarms || []).map(a => {
const name = _.propOr({ Ref: a }, 'name', a)
return { Name: name }
})
const alarmConfig = alarmNames.length
? { Alarms: alarmNames, Enabled: true }
: { Alarms: [], Enabled: false }
Object.assign(deploymentGroup.Properties, { AlarmConfiguration: alarmConfig })
if (deploymentSettings.triggerConfigurations) {
Object.assign(deploymentGroup.Properties, { TriggerConfigurations: deploymentSettings.triggerConfigurations })
}
Expand Down
6 changes: 5 additions & 1 deletion lib/CfTemplateGenerators/CodeDeploy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ describe('CodeDeploy', () => {
DeploymentStyle: {
DeploymentType: 'BLUE_GREEN',
DeploymentOption: 'WITH_TRAFFIC_CONTROL'
},
AlarmConfiguration: {
Alarms: [],
Enabled: false
}
}
}
Expand All @@ -73,7 +77,7 @@ describe('CodeDeploy', () => {
})

context('when no alarms were provided', () => {
it('should not include the AlarmConfiguration property', () => {
it('should explicitly disable the AlarmConfiguration so previously attached alarms are detached', () => {
const deploymentSettings = { type: 'Linear10PercentEvery1Minute' }
const expected = _.pipe(
_.set('Properties.ApplicationName', { Ref: codeDeployAppName }),
Expand Down
6 changes: 3 additions & 3 deletions serverless-plugin-canary-deployments.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ describe('ServerlessCanaryDeployments', () => {
const deploymentGroup = resources.HelloLambdaFunctionDeploymentGroup

expect(deploymentGroup).to.not.equal(undefined)
expect(deploymentGroup.Properties.AlarmConfiguration).to.equal(undefined)
expect(deploymentGroup.Properties.AlarmConfiguration).to.deep.equal({ Alarms: [], Enabled: false })
})

it('attaches composite alarm to all deployment groups when multiple functions have canaryAlarms', () => {
Expand Down Expand Up @@ -236,9 +236,9 @@ describe('ServerlessCanaryDeployments', () => {
const helloDeploymentGroup = resources.HelloLambdaFunctionDeploymentGroup
expect(helloDeploymentGroup.Properties.AlarmConfiguration).to.not.equal(undefined)

// world does not have canaryAlarms - should NOT have AlarmConfiguration
// world does not have canaryAlarms - should have alarms explicitly disabled
const worldDeploymentGroup = resources.WorldLambdaFunctionDeploymentGroup
expect(worldDeploymentGroup.Properties.AlarmConfiguration).to.equal(undefined)
expect(worldDeploymentGroup.Properties.AlarmConfiguration).to.deep.equal({ Alarms: [], Enabled: false })
})

it('preserves existing alarms when canaryAlarms is also configured', () => {
Expand Down
Loading