Skip to content

Commit 3428737

Browse files
committed
Added lambda invoke action changes
1 parent caee69c commit 3428737

File tree

4 files changed

+107
-0
lines changed

4 files changed

+107
-0
lines changed

.changelog/45170.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
```release-note:enhancement
2+
resource/aws_lambda_function: Add `tenancy_config` argument
3+
```
4+
5+
```release-note:enhancement
6+
data-source/aws_lambda_function: Add `tenancy_config` attribute
7+
```
8+
9+
```release-note:enhancement
10+
resource/aws_lambda_invocation: Add `tenant_id` argument
11+
```
12+
13+
```release-note:enhancement
14+
data-source/aws_lambda_invocation: Add `tenant_id` argument
15+
```
16+
17+
```release-note:enhancement
18+
action/aws_lambda_invoke: Add `tenant_id` argument
19+
```

internal/service/lambda/invoke_action.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ type invokeActionModel struct {
4343
InvocationType fwtypes.StringEnum[awstypes.InvocationType] `tfsdk:"invocation_type"`
4444
LogType fwtypes.StringEnum[awstypes.LogType] `tfsdk:"log_type"`
4545
ClientContext types.String `tfsdk:"client_context"`
46+
TenantId types.String `tfsdk:"tenant_id"`
4647
}
4748

4849
func (a *invokeAction) Schema(ctx context.Context, req action.SchemaRequest, resp *action.SchemaResponse) {
@@ -78,6 +79,10 @@ func (a *invokeAction) Schema(ctx context.Context, req action.SchemaRequest, res
7879
Description: "Up to 3,583 bytes of base64-encoded data about the invoking client to pass to the function in the context object. This is only used for mobile applications.",
7980
Optional: true,
8081
},
82+
"tenant_id": schema.StringAttribute{
83+
Description: "The Tenant Id for lambda function invocation. This is mandatory, if tenancy_config is enabled in lambda function",
84+
Optional: true,
85+
},
8186
},
8287
}
8388
}
@@ -134,6 +139,10 @@ func (a *invokeAction) Invoke(ctx context.Context, req action.InvokeRequest, res
134139
if !config.Qualifier.IsNull() {
135140
input.Qualifier = config.Qualifier.ValueStringPointer()
136141
}
142+
// Set optional parameters
143+
if !config.TenantId.IsNull() {
144+
input.TenantId = config.TenantId.ValueStringPointer()
145+
}
137146

138147
if !config.ClientContext.IsNull() {
139148
clientContext := config.ClientContext.ValueString()

internal/service/lambda/invoke_action_test.go

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,35 @@ func TestAccLambdaInvokeAction_complexPayload(t *testing.T) {
211211
})
212212
}
213213

214+
func TestAccLambdaInvokeAction_tenantId(t *testing.T) {
215+
ctx := acctest.Context(t)
216+
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
217+
testData := "value3"
218+
inputJSON := `{"key1":"value1","key2":"value2"}`
219+
expectedResult := fmt.Sprintf(`{"key1":"value1","key2":"value2","key3":%q}`, testData)
220+
221+
resource.ParallelTest(t, resource.TestCase{
222+
PreCheck: func() {
223+
acctest.PreCheck(ctx, t)
224+
acctest.PreCheckPartitionHasService(t, names.LambdaEndpointID)
225+
},
226+
ErrorCheck: acctest.ErrorCheck(t, names.LambdaServiceID),
227+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
228+
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
229+
tfversion.SkipBelow(tfversion.Version1_14_0),
230+
},
231+
CheckDestroy: acctest.CheckDestroyNoop,
232+
Steps: []resource.TestStep{
233+
{
234+
Config: testAccInvokeActionConfig_tenantId(rName, testData, inputJSON),
235+
Check: resource.ComposeTestCheckFunc(
236+
testAccCheckInvokeAction(ctx, rName, inputJSON, expectedResult),
237+
),
238+
},
239+
},
240+
})
241+
}
242+
214243
// Test helper functions
215244

216245
// testAccCheckInvokeAction verifies that the action can successfully invoke a Lambda function
@@ -559,3 +588,52 @@ resource "terraform_data" "trigger" {
559588
}
560589
`, inputJSON, clientContext))
561590
}
591+
592+
func testAccInvokeActionConfig_function_tenant(rName, testData string) string {
593+
return acctest.ConfigCompose(
594+
testAccInvokeActionConfig_base(rName),
595+
fmt.Sprintf(`
596+
resource "aws_lambda_function" "test" {
597+
depends_on = [aws_iam_role_policy_attachment.test]
598+
599+
filename = "test-fixtures/lambda_invocation.zip"
600+
function_name = %[1]q
601+
role = aws_iam_role.test.arn
602+
handler = "lambda_invocation.handler"
603+
runtime = "nodejs18.x"
604+
605+
tenancy_config {
606+
tenant_isolation_mode = "PER_TENANT"
607+
}
608+
environment {
609+
variables = {
610+
TEST_DATA = %[2]q
611+
}
612+
}
613+
}
614+
`, rName, testData))
615+
}
616+
617+
func testAccInvokeActionConfig_tenantId(rName, testData, inputJSON string) string {
618+
return acctest.ConfigCompose(
619+
testAccInvokeActionConfig_function_tenant(rName, testData),
620+
fmt.Sprintf(`
621+
action "aws_lambda_invoke" "test" {
622+
config {
623+
function_name = aws_lambda_function.test.function_name
624+
payload = %[1]q
625+
tenant_id = "tenant-1"
626+
}
627+
}
628+
629+
resource "terraform_data" "trigger" {
630+
input = "trigger"
631+
lifecycle {
632+
action_trigger {
633+
events = [before_create, before_update]
634+
actions = [action.aws_lambda_invoke.test]
635+
}
636+
}
637+
}
638+
`, inputJSON))
639+
}

website/docs/actions/lambda_invoke.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,4 @@ This action supports the following arguments:
220220
* `payload` - (Required) JSON payload to send to the Lambda function. This should be a valid JSON string that represents the event data for your function. The payload size limit is 6 MB for synchronous invocations and 256 KB for asynchronous invocations.
221221
* `region` - (Optional) Region where this action should be [run](https://docs.aws.amazon.com/general/latest/gr/rande.html#regional-endpoints). Defaults to the Region set in the [provider configuration](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#aws-configuration-reference).
222222
* `qualifier` - (Optional) Version or alias of the Lambda function to invoke. If not specified, the `$LATEST` version will be invoked. Can be a version number (e.g., `1`) or an alias (e.g., `PROD`).
223+
* `tenant_id` - (Optional) Tenant Id to serve invocations from specified tenant.

0 commit comments

Comments
 (0)