Files
floci/compatibility-tests/compat-terraform/test/lambda_durable_config.bats
T
TATSUNO “Taz” Yasuhiro ee2d1a68a6 feat(cloudformation): pass Lambda DurableConfig through (#5218)
* feat(cloudformation): pass Lambda DurableConfig through

AWS::Lambda::Function.DurableConfig reaches CreateFunction and
UpdateFunctionConfiguration. As on AWS, a RetentionPeriodInDays the
template leaves out is 14 on update too, a durable function created
without Timeout gets min(ExecutionTimeout, 900), and adding or removing
DurableConfig replaces the function.

* test(terraform): cover aws_lambda_function durable_config

The provider creates a durable function, reads it back without a diff,
updates execution_timeout in place, and before destroy stops a RUNNING
durable execution through ListDurableExecutionsByFunction,
StopDurableExecution and GetDurableExecution.

* fix(cloudformation): honor AWS::NoValue, cleared keys and large numbers in DurableConfig

A DurableConfig that Fn::If removes with AWS::NoValue leaves the
function plain. A KMSKeyArn the template leaves out or sets to "" clears
the key, as CloudFormation does on AWS, since Lambda keeps a stored key
when the update omits the member. A number beyond an integer reaches
Lambda unchanged, so its range check rejects it.

* fix(cloudformation): reject a DurableConfig that is not an object

Only an intrinsic that resolves to AWS::NoValue removes DurableConfig.
CloudFormation rejects a string, number or list in its schema check
before the function is touched, so an update with one no longer
replaces and deletes a durable function.

* test(cloudformation): cover Lambda DurableConfig with the AWS SDK

The CloudFormation and Lambda SDK clients create a durable function,
update DurableConfig in place, and remove it by replacing the function.

* fix(cloudformation): require ExecutionTimeout and known members in DurableConfig

CloudFormation checks DurableConfig against the schema on update too: an
update without ExecutionTimeout, or with a member the schema does not
list, fails before the function is touched. Floci let such an update
through and kept the old timeout.

* refactor(cloudformation): look up a Lambda function once per deploy

The name choice and the replacement decision now share one lookup and one
durable check, so they cannot disagree.
2026-10-07 12:39:36 -04:00

86 lines
3.2 KiB
Bash

#!/usr/bin/env bats
# Lambda durable_config compatibility test
#
# aws_lambda_function.durable_config creates a durable function, reads it back without a
# diff, updates execution_timeout in place, and on destroy stops a RUNNING durable
# execution before it deletes the function.
TF_DIR_NAME="lambda-durable-config-tf"
setup_file() {
load 'test_helper/common-setup'
DURABLE_TF_DIR="$(cd "$(dirname "$BATS_TEST_FILENAME")/$TF_DIR_NAME" && pwd)"
cd "$DURABLE_TF_DIR"
echo "# === Lambda durable_config Test ===" >&3
rm -rf .terraform .terraform.lock.hcl terraform.tfstate* handler.zip 2>/dev/null || true
run terraform init -input=false -no-color
if [ "$status" -ne 0 ]; then
echo "# terraform init failed: $output" >&3
return 1
fi
run terraform apply -var="endpoint=${FLOCI_ENDPOINT}" -input=false -auto-approve -no-color
if [ "$status" -ne 0 ]; then
echo "# terraform apply failed: $output" >&3
return 1
fi
}
teardown_file() {
load 'test_helper/common-setup'
DURABLE_TF_DIR="$(cd "$(dirname "$BATS_TEST_FILENAME")/$TF_DIR_NAME" && pwd)"
cd "$DURABLE_TF_DIR"
terraform destroy -var="endpoint=${FLOCI_ENDPOINT}" -input=false -auto-approve -no-color || true
rm -rf .terraform .terraform.lock.hcl terraform.tfstate* handler.zip 2>/dev/null || true
}
setup() {
load 'test_helper/common-setup'
DURABLE_TF_DIR="$(cd "$(dirname "$BATS_TEST_FILENAME")/$TF_DIR_NAME" && pwd)"
}
@test "durable_config: the function is durable with the default retention" {
run aws_cmd lambda get-function-configuration --function-name floci-tf-lambda-durable
assert_success
assert_equal "$(json_get "$output" '.DurableConfig.ExecutionTimeout')" "60"
assert_equal "$(json_get "$output" '.DurableConfig.RetentionPeriodInDays')" "14"
}
@test "durable_config: a second plan has no changes" {
run terraform -chdir="$DURABLE_TF_DIR" plan -var="endpoint=${FLOCI_ENDPOINT}" \
-input=false -no-color -detailed-exitcode
assert_success
}
@test "durable_config: execution_timeout updates the function in place" {
run terraform -chdir="$DURABLE_TF_DIR" apply -var="endpoint=${FLOCI_ENDPOINT}" \
-var="execution_timeout=120" -input=false -auto-approve -no-color
assert_success
assert_output --partial "0 added, 1 changed, 0 destroyed"
run aws_cmd lambda get-function-configuration --function-name floci-tf-lambda-durable
assert_success
assert_equal "$(json_get "$output" '.DurableConfig.ExecutionTimeout')" "120"
}
@test "durable_config: destroy stops a running durable execution" {
run aws_cmd lambda invoke --function-name 'floci-tf-lambda-durable:$LATEST' \
--invocation-type Event --cli-binary-format raw-in-base64-out --payload '{}' /dev/null
assert_success
execution_arn="$(json_get "$output" '.DurableExecutionArn')"
[ -n "$execution_arn" ] && [ "$execution_arn" != "null" ]
run terraform -chdir="$DURABLE_TF_DIR" destroy -var="endpoint=${FLOCI_ENDPOINT}" \
-var="execution_timeout=120" -input=false -auto-approve -no-color
assert_success
run aws_cmd lambda get-durable-execution --durable-execution-arn "$execution_arn"
assert_success
assert_equal "$(json_get "$output" '.Status')" "STOPPED"
}