-
-
Notifications
You must be signed in to change notification settings - Fork 748
Description
Description
Lambda Alias no_refresh and with_refresh are backwards. Currently (for the last two years), the ignore_changes lifecycle block has been on the with_refresh resource. This causes the alias NOT to refresh to the passed in lambda version when you pass in refresh_alias = true.
Version
- Terraform: 1.1.7
- Module: Lambda Alias
Reproduction
Steps to reproduce the behavior:
- Create a lambda function and alias with
with_refreshset totrue. - Run terraform plan and apply
- Update something on the lambda function and publish a new version.
- Run terraform plan and apply
- Alias will not be updated to the latest version of the lambda function
Expected Behavior
When refresh_alias = true I would expect the alias to be pointed at var.function_version that was passed into the module.
When refresh_alias = false I would expect the alias to stay pinned to the original var.function_version that was passed into the module.
Actual Behavior
When refresh_alias = true the alias stays pinned to the original var.function_version that was passed into the module.
When refresh_alias = false the alias points at var.function_version that was passed into the module.
Code Change
Move lines of code on lines 48-50 to below line 28
resource "aws_lambda_alias" "no_refresh" {
count = var.create && !var.use_existing_alias && !var.refresh_alias ? 1 : 0
name = var.name
description = var.description
function_name = var.function_name
function_version = var.function_version != "" ? var.function_version : "$LATEST"
# $LATEST is not supported for an alias pointing to more than 1 version
dynamic "routing_config" {
for_each = length(keys(var.routing_additional_version_weights)) == 0 ? [] : [true]
content {
additional_version_weights = var.routing_additional_version_weights
}
}
lifecycle {
ignore_changes = [function_version]
}
}
resource "aws_lambda_alias" "with_refresh" {
count = var.create && !var.use_existing_alias && var.refresh_alias ? 1 : 0
name = var.name
description = var.description
function_name = var.function_name
function_version = var.function_version != "" ? var.function_version : "$LATEST"
# $LATEST is not supported for an alias pointing to more than 1 version
dynamic "routing_config" {
for_each = length(keys(var.routing_additional_version_weights)) == 0 ? [] : [true]
content {
additional_version_weights = var.routing_additional_version_weights
}
}
}