mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(lambda): omit Environment when no variables are set (#2838)
* fix(lambda): omit Environment when no variables are set
Real AWS omits the Environment member entirely from CreateFunction,
GetFunction, GetFunctionConfiguration and ListFunctions responses when a
function has no environment variables. Floci always emitted it, as an
empty object.
The Terraform provider reads a present-but-empty Environment back as an
environment {} block in state, so any function declared without variables
plans a removal on every run and never converges. On Lambda@Edge, where
environment variables are not permitted at all, the block can never
legitimately exist and each no-op apply also republishes the function.
Layers, KMSKeyArn, FileSystemConfigs and VpcConfig in the same response
builder already omit-when-empty; Environment was the outlier.
* test(compat): correct Environment assertions to match live AWS
Three assertions in the Python and Java SDK compatibility suites required
an Environment block that real AWS does not send:
- test_get_function_configuration_environment_always_present
- test_update_environment_variables_round_trip (the cleared case)
- LambdaFunctionConfigTest.getFunctionConfigurationHasDefaults
Measured against the live service in both directions: a function created
without variables comes back with no Environment member, and clearing to an
empty Variables map removes it again. The tests encoded Floci's previous
behaviour rather than the API's, which is why they went green.
Also corrects the wording of the Java clear case. It sends an Environment
with no Variables member, which is 'leave unchanged', not 'clear' — live AWS
keeps the existing variables, as Floci already did. The assertion now pins
that instead of describing a clear that never happened.
This commit is contained in:
1 parent
db182b3048
commit
2bf9b57bd9
4 files changed
+108
-16
No files matched your search
+17
-7
@@ -102,10 +102,13 @@ class LambdaFunctionConfigTest {
|
||||
.as("default TracingConfig.Mode must be PassThrough")
|
||||
.isEqualTo("PassThrough");
|
||||
|
||||
// Environment block must always be present (even when empty)
|
||||
// AWS omits Environment entirely for a function with no variables — verified
|
||||
// against the live service — so the SDK deserialises it as null here, the same
|
||||
// as layers() and vpcConfig(). Returning an empty block instead gives Terraform
|
||||
// a permanent `- environment {}` diff.
|
||||
assertThat(resp.environment())
|
||||
.as("Environment must always be present in the response")
|
||||
.isNotNull();
|
||||
.as("Environment must be omitted when no variables are set")
|
||||
.isNull();
|
||||
}
|
||||
|
||||
// ─── UpdateFunctionConfiguration ─────────────────────────────────────────
|
||||
@@ -207,16 +210,23 @@ class LambdaFunctionConfigTest {
|
||||
.containsEntry("KEY_A", "value-a")
|
||||
.containsEntry("KEY_B", "value-b");
|
||||
|
||||
// Clear environment — response must still include the Environment block
|
||||
UpdateFunctionConfigurationResponse cleared = lambda.updateFunctionConfiguration(
|
||||
// An Environment with no Variables member is "leave unchanged", not "clear" — the
|
||||
// existing variables survive. Verified against the live service: sending
|
||||
// Environment={} keeps {"KEY_A": "value-a"} on both the update response and the
|
||||
// following read. (Clearing takes an empty Variables map, which AWS answers by
|
||||
// omitting the member entirely.)
|
||||
UpdateFunctionConfigurationResponse unchanged = lambda.updateFunctionConfiguration(
|
||||
UpdateFunctionConfigurationRequest.builder()
|
||||
.functionName(FN)
|
||||
.environment(Environment.builder().build())
|
||||
.build());
|
||||
|
||||
assertThat(cleared.environment())
|
||||
.as("Environment block must be present even after clearing variables")
|
||||
assertThat(unchanged.environment())
|
||||
.as("an Environment with no Variables member must leave the variables alone")
|
||||
.isNotNull();
|
||||
assertThat(unchanged.environment().variables())
|
||||
.containsEntry("KEY_A", "value-a")
|
||||
.containsEntry("KEY_B", "value-b");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in new issue
Block a user