Terraform
action block reference
The action block specifies a provider-defined action that you can invoke using the Terraform CLI or during an apply operation. Actions are preset operations built into providers that you can invoke to trigger automations outside of Terraform, such as Ansible playbooks and Lambda jobs. Refer to Invoke an action for more information.
Configuration model
The action block supports the following configuration:
- action "<TYPE>" "<LABEL>"block
Complete configuration
The following action block includes all supported built-in arguments:
action "<TYPE>" "<LABEL>" {
   config {
      <PROVIDER ARGUMENTS>
   }
   for_each = {          # `for_each` and `count` are mutually exclusive
      <KEY> = <VALUE>
   }
   for_each = [       # `for_each` accepts a map or a set of strings
      "<VALUE>",
      "<VALUE>"
  ]
   count = <NUMBER>      # `for_each` and `count` are mutually exclusive
   provider = <REFERENCE.TO.ALIAS> 
}
Specification
An action block supports the following configuration.
action "<TYPE>" "<LABEL>"
You must set the following arguments for every action block:
- TYPE: Specifies the type of action to invoke. Refer to the provider documentation for information about the types of actions you can declare.
- LABEL: Specifies a label for the- actionblock. Terraform uses this label as part of the unique name for the action as configured by the block. The label does not affect the operation performed by Terraform when a user invokes the action. Refer to References to Named Values and Resource naming for expression syntax and label recommendations.
Use the action.<TYPE>.<LABEL> syntax to reference the action elsewhere in your configuration.
config
The config block sets values for arguments or nested blocks defined by the provider. 
action "<TYPE>" "<LABEL>" {
  config { 
    <provider-specific arguments>
  }
  # . . . 
}
The config block may contain arguments, nested blocks, or a combination of both. Refer to the provider documentation for arguments you can configure in the config block for the type of action you want to invoke.
Summary
- Data type: Map of arguments or nested blocks
- Example: Define an action
count
The count meta-argument instructs Terraform to invoke an action multiple times using the same configuration.
resource {
  count = <number>
}
count is a meta-argument. Meta-arguments are built into the Terraform language and control how Terraform creates resources. Refer to the count reference for details about how the argument works.
for_each
The for_each meta-argument instructs Terraform to invoke the action once for each member of a list or key-value pair in a map.
action "<TYPE>" "<LABEL>" {
  for_each = [ "<VALUE>" ]
  # . . .
}
for_each is a meta-argument. Meta-arguments are built into the Terraform language and control how Terraform creates resources. Refer to the for_each reference for details about how the argument works.
provider
The provider argument instructs Terraform to use an alternate provider configuration to invoke the action.
action "<TYPE>" "<LABEL>" {
  provider = <provider>.<alias>
}
provider is a meta-argument. Meta-arguments are built into the Terraform language and control how Terraform creates resources. Refer to the provider reference for details about how the argument works.
Examples
The following examples show how to write configuration for common use cases.
Define an action
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. Refer to Invoke an action for instructions on how to invoke actions.
action "aws_lambda_invoke" "example" {
  config {
    function_name = "123456789012:function:my-function:1"
    payload = jsonencode({
      key1 = "value1"
      key2 = "value2"
    })
  }
}
The function_name argument must reference an existing AWS Lambda function by name or ARN. Refer to the aws_lambda_invoke documentation for details.
Select an alternate provider configuration
The following example configures Terraform to apply the aws.alias provider configuration when invoking the action:
action "aws_lambda_invoke" "example" {
  provider = aws.alias
  config {
    function_name = "my_function"
    payload = jsonencode({
      key1 = "value1"
      key2 = "value2"
    })
  }
}
Invoke an action multiple times
You can add a count or for_each meta-argument to invoke an action multiple times.
Terraform invokes the action three times.
action "aws_lambda_invoke" "example" {
  count = 3 
  config {
    function_name = "my_function"
    payload = jsonencode({
      key1 = "value1"
      key2 = "value2"
    })
  }
}