Skip to content

Commit 80e64be

Browse files
authored
Update AWS lambda action code examples (#964)
This updates `aws_lambda_invoke` code examples to more closely mirror hashicorp/terraform-provider-aws#43972
2 parents 365ade9 + 9f3dad0 commit 80e64be

File tree

1 file changed

+38
-24
lines changed
  • content/terraform/v1.14.x (beta)/docs/language/block

1 file changed

+38
-24
lines changed

content/terraform/v1.14.x (beta)/docs/language/block/action.mdx

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -193,28 +193,36 @@ The following examples show how to write configuration for common use cases.
193193

194194
### Define an action
195195

196-
The following example adds an `aws_lambda_invoke` action. You can invoke an action using the CLI or configure Terraform to invoke the action during a resource lifecycle state.
196+
The following example adds an `aws_lambda_invoke` action. You can invoke an action using the CLI or configure Terraform to invoke the action during a resource lifecycle state.
197197

198198
```hcl
199199
action "aws_lambda_invoke" "example" {
200200
config {
201-
values = var.values
202-
timeout = 3000
201+
function_name = "my_function"
202+
payload = jsonencode({
203+
key1 = "value1"
204+
key2 = "value2"
205+
})
203206
}
204207
}
205208
```
206209

210+
The value of the `function_name` argument must be defined elsewhere in the configuration. The argument is available in the AWS `lambda_function` resource. Refer to the [AWS provider documentation](https://registry.terraform.io/providers/hashicorp/aws/6.14.0/docs/resources/lambda_function#basic-function-with-nodejs) for information about provisioning an AWS Lambda function.
211+
207212
### Select an alternate provider configuration
208213

209214
The following example configures Terraform to apply the `aws.alias` provider configuration when invoking the action:
210215

211216
```hcl
212-
action "aws_lambda_invocation" "example" {
213-
provider = aws.alias
214-
config {
215-
input = count.index
216-
timeout = 3000
217-
}
217+
action "aws_lambda_invoke" "example" {
218+
provider = aws.alias
219+
config {
220+
function_name = "my_function"
221+
payload = jsonencode({
222+
key1 = "value1"
223+
key2 = "value2"
224+
})
225+
}
218226
}
219227
```
220228

@@ -229,12 +237,15 @@ You can add a `count` or `for_each` meta-argument to invoke an action multiple t
229237
Terraform invokes the action three times.
230238

231239
```hcl
232-
action "aws_lambda_invocation" "example" {
233-
count = 3
234-
config {
235-
input = count.index
236-
timeout = 3000
237-
}
240+
action "aws_lambda_invoke" "example" {
241+
count = 3
242+
config {
243+
function_name = "my_function"
244+
payload = jsonencode({
245+
key1 = "value1"
246+
key2 = "value2"
247+
})
248+
}
238249
}
239250
```
240251

@@ -245,15 +256,18 @@ action "aws_lambda_invocation" "example" {
245256
Terraform invokes the action once for each member of the map, resulting in two invocations.
246257

247258
```hcl
248-
action "aws_lambda_invocation" "example" {
249-
for_each = tomap({
250-
a_group = "eastus"
251-
another_group = "westus2"
252-
})
253-
config {
254-
input = count.index
255-
timeout = 3000
256-
}
259+
action "aws_lambda_invoke" "example" {
260+
for_each = tomap({
261+
a_group = "eastus"
262+
another_group = "westus2"
263+
})
264+
config {
265+
function_name = "my_function"
266+
payload = jsonencode({
267+
key1 = "value1"
268+
key2 = "value2"
269+
})
270+
}
257271
}
258272
```
259273

0 commit comments

Comments
 (0)