diff --git a/.changelog/19488.txt b/.changelog/19488.txt new file mode 100644 index 00000000000..7c45c029cf8 --- /dev/null +++ b/.changelog/19488.txt @@ -0,0 +1,3 @@ +```release-note:new-resource +aws_lambda_invocation +``` \ No newline at end of file diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 2bf573ed7a7..55a1a5019ef 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -1387,6 +1387,7 @@ func Provider() *schema.Provider { "aws_lambda_event_source_mapping": lambda.ResourceEventSourceMapping(), "aws_lambda_function": lambda.ResourceFunction(), "aws_lambda_function_event_invoke_config": lambda.ResourceFunctionEventInvokeConfig(), + "aws_lambda_invocation": lambda.ResourceInvocation(), "aws_lambda_layer_version": lambda.ResourceLayerVersion(), "aws_lambda_layer_version_permission": lambda.ResourceLayerVersionPermission(), "aws_lambda_permission": lambda.ResourcePermission(), diff --git a/internal/service/lambda/alias.go b/internal/service/lambda/alias.go index 9e36ac057cb..8e7f54e30f4 100644 --- a/internal/service/lambda/alias.go +++ b/internal/service/lambda/alias.go @@ -89,7 +89,7 @@ func resourceAliasCreate(d *schema.ResourceData, meta interface{}) error { FunctionName: aws.String(functionName), FunctionVersion: aws.String(d.Get("function_version").(string)), Name: aws.String(aliasName), - RoutingConfig: expandLambdaAliasRoutingConfiguration(d.Get("routing_config").([]interface{})), + RoutingConfig: expandAliasRoutingConfiguration(d.Get("routing_config").([]interface{})), } aliasConfiguration, err := conn.CreateAlias(params) @@ -131,7 +131,7 @@ func resourceAliasRead(d *schema.ResourceData, meta interface{}) error { d.Set("arn", aliasConfiguration.AliasArn) d.SetId(aws.StringValue(aliasConfiguration.AliasArn)) - invokeArn := lambdaFunctionInvokeArn(*aliasConfiguration.AliasArn, meta) + invokeArn := functionInvokeArn(*aliasConfiguration.AliasArn, meta) d.Set("invoke_arn", invokeArn) if err := d.Set("routing_config", flattenAliasRoutingConfiguration(aliasConfiguration.RoutingConfig)); err != nil { @@ -173,7 +173,7 @@ func resourceAliasUpdate(d *schema.ResourceData, meta interface{}) error { FunctionName: aws.String(d.Get("function_name").(string)), FunctionVersion: aws.String(d.Get("function_version").(string)), Name: aws.String(d.Get("name").(string)), - RoutingConfig: expandLambdaAliasRoutingConfiguration(d.Get("routing_config").([]interface{})), + RoutingConfig: expandAliasRoutingConfiguration(d.Get("routing_config").([]interface{})), } _, err := conn.UpdateAlias(params) @@ -184,7 +184,7 @@ func resourceAliasUpdate(d *schema.ResourceData, meta interface{}) error { return nil } -func expandLambdaAliasRoutingConfiguration(l []interface{}) *lambda.AliasRoutingConfiguration { +func expandAliasRoutingConfiguration(l []interface{}) *lambda.AliasRoutingConfiguration { aliasRoutingConfiguration := &lambda.AliasRoutingConfiguration{} if len(l) == 0 || l[0] == nil { diff --git a/internal/service/lambda/alias_data_source.go b/internal/service/lambda/alias_data_source.go index ec4023d4d6f..fec0bbda995 100644 --- a/internal/service/lambda/alias_data_source.go +++ b/internal/service/lambda/alias_data_source.go @@ -69,7 +69,7 @@ func dataSourceAliasRead(d *schema.ResourceData, meta interface{}) error { d.Set("description", aliasConfiguration.Description) d.Set("function_version", aliasConfiguration.FunctionVersion) - invokeArn := lambdaFunctionInvokeArn(*aliasConfiguration.AliasArn, meta) + invokeArn := functionInvokeArn(*aliasConfiguration.AliasArn, meta) d.Set("invoke_arn", invokeArn) return nil diff --git a/internal/service/lambda/code_signing_config.go b/internal/service/lambda/code_signing_config.go index 08fa51380e5..84d9f23deaa 100644 --- a/internal/service/lambda/code_signing_config.go +++ b/internal/service/lambda/code_signing_config.go @@ -90,7 +90,7 @@ func resourceCodeSigningConfigCreate(d *schema.ResourceData, meta interface{}) e log.Printf("[DEBUG] Creating Lambda code signing config") configInput := &lambda.CreateCodeSigningConfigInput{ - AllowedPublishers: expandLambdaCodeSigningConfigAllowedPublishers(d.Get("allowed_publishers").([]interface{})), + AllowedPublishers: expandCodeSigningConfigAllowedPublishers(d.Get("allowed_publishers").([]interface{})), Description: aws.String(d.Get("description").(string)), } @@ -153,7 +153,7 @@ func resourceCodeSigningConfigRead(d *schema.ResourceData, meta interface{}) err return fmt.Errorf("error setting lambda code signing config last modified: %s", err) } - if err := d.Set("allowed_publishers", flattenLambdaCodeSigningConfigAllowedPublishers(codeSigningConfig.AllowedPublishers)); err != nil { + if err := d.Set("allowed_publishers", flattenCodeSigningConfigAllowedPublishers(codeSigningConfig.AllowedPublishers)); err != nil { return fmt.Errorf("error setting lambda code signing config allowed publishers: %s", err) } @@ -173,7 +173,7 @@ func resourceCodeSigningConfigUpdate(d *schema.ResourceData, meta interface{}) e configUpdate := false if d.HasChange("allowed_publishers") { - configInput.AllowedPublishers = expandLambdaCodeSigningConfigAllowedPublishers(d.Get("allowed_publishers").([]interface{})) + configInput.AllowedPublishers = expandCodeSigningConfigAllowedPublishers(d.Get("allowed_publishers").([]interface{})) configUpdate = true } if d.HasChange("policies") { @@ -219,7 +219,7 @@ func resourceCodeSigningConfigDelete(d *schema.ResourceData, meta interface{}) e return nil } -func expandLambdaCodeSigningConfigAllowedPublishers(allowedPublishers []interface{}) *lambda.AllowedPublishers { +func expandCodeSigningConfigAllowedPublishers(allowedPublishers []interface{}) *lambda.AllowedPublishers { if len(allowedPublishers) == 0 || allowedPublishers[0] == nil { return nil } @@ -231,7 +231,7 @@ func expandLambdaCodeSigningConfigAllowedPublishers(allowedPublishers []interfac } } -func flattenLambdaCodeSigningConfigAllowedPublishers(allowedPublishers *lambda.AllowedPublishers) []interface{} { +func flattenCodeSigningConfigAllowedPublishers(allowedPublishers *lambda.AllowedPublishers) []interface{} { if allowedPublishers == nil { return []interface{}{} } diff --git a/internal/service/lambda/code_signing_config_data_source.go b/internal/service/lambda/code_signing_config_data_source.go index a9f2e490d82..7e5622fa077 100644 --- a/internal/service/lambda/code_signing_config_data_source.go +++ b/internal/service/lambda/code_signing_config_data_source.go @@ -98,7 +98,7 @@ func dataSourceCodeSigningConfigRead(d *schema.ResourceData, meta interface{}) e return fmt.Errorf("error setting lambda code signing config last modified: %w", err) } - if err := d.Set("allowed_publishers", flattenLambdaCodeSigningConfigAllowedPublishers(codeSigningConfig.AllowedPublishers)); err != nil { + if err := d.Set("allowed_publishers", flattenCodeSigningConfigAllowedPublishers(codeSigningConfig.AllowedPublishers)); err != nil { return fmt.Errorf("error setting lambda code signing config allowed publishers: %w", err) } diff --git a/internal/service/lambda/event_source_mapping.go b/internal/service/lambda/event_source_mapping.go index 3d0852f9fa0..37a1f8e1062 100644 --- a/internal/service/lambda/event_source_mapping.go +++ b/internal/service/lambda/event_source_mapping.go @@ -329,7 +329,7 @@ func resourceEventSourceMappingCreate(d *schema.ResourceData, meta interface{}) } if v, ok := d.GetOk("destination_config"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil { - input.DestinationConfig = expandLambdaDestinationConfig(v.([]interface{})[0].(map[string]interface{})) + input.DestinationConfig = expandDestinationConfig(v.([]interface{})[0].(map[string]interface{})) } if v, ok := d.GetOk("event_source_arn"); ok { @@ -340,7 +340,7 @@ func resourceEventSourceMappingCreate(d *schema.ResourceData, meta interface{}) } if v, ok := d.GetOk("filter_criteria"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil { - input.FilterCriteria = expandLambdaFilterCriteria(v.([]interface{})[0].(map[string]interface{})) + input.FilterCriteria = expandFilterCriteria(v.([]interface{})[0].(map[string]interface{})) } if v, ok := d.GetOk("function_response_types"); ok && v.(*schema.Set).Len() > 0 { @@ -368,13 +368,13 @@ func resourceEventSourceMappingCreate(d *schema.ResourceData, meta interface{}) } if v, ok := d.GetOk("self_managed_event_source"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil { - input.SelfManagedEventSource = expandLambdaSelfManagedEventSource(v.([]interface{})[0].(map[string]interface{})) + input.SelfManagedEventSource = expandSelfManagedEventSource(v.([]interface{})[0].(map[string]interface{})) target = "Self-Managed Apache Kafka" } if v, ok := d.GetOk("source_access_configuration"); ok && v.(*schema.Set).Len() > 0 { - input.SourceAccessConfigurations = expandLambdaSourceAccessConfigurations(v.(*schema.Set).List()) + input.SourceAccessConfigurations = expandSourceAccessConfigurations(v.(*schema.Set).List()) } if v, ok := d.GetOk("starting_position"); ok { @@ -463,7 +463,7 @@ func resourceEventSourceMappingRead(d *schema.ResourceData, meta interface{}) er d.Set("batch_size", eventSourceMappingConfiguration.BatchSize) d.Set("bisect_batch_on_function_error", eventSourceMappingConfiguration.BisectBatchOnFunctionError) if eventSourceMappingConfiguration.DestinationConfig != nil { - if err := d.Set("destination_config", []interface{}{flattenLambdaDestinationConfig(eventSourceMappingConfiguration.DestinationConfig)}); err != nil { + if err := d.Set("destination_config", []interface{}{flattenDestinationConfig(eventSourceMappingConfiguration.DestinationConfig)}); err != nil { return fmt.Errorf("error setting destination_config: %w", err) } } else { @@ -471,7 +471,7 @@ func resourceEventSourceMappingRead(d *schema.ResourceData, meta interface{}) er } d.Set("event_source_arn", eventSourceMappingConfiguration.EventSourceArn) if v := eventSourceMappingConfiguration.FilterCriteria; v != nil { - if err := d.Set("filter_criteria", []interface{}{flattenLambdaFilterCriteria(v)}); err != nil { + if err := d.Set("filter_criteria", []interface{}{flattenFilterCriteria(v)}); err != nil { return fmt.Errorf("error setting filter criteria: %w", err) } } else { @@ -492,13 +492,13 @@ func resourceEventSourceMappingRead(d *schema.ResourceData, meta interface{}) er d.Set("parallelization_factor", eventSourceMappingConfiguration.ParallelizationFactor) d.Set("queues", aws.StringValueSlice(eventSourceMappingConfiguration.Queues)) if eventSourceMappingConfiguration.SelfManagedEventSource != nil { - if err := d.Set("self_managed_event_source", []interface{}{flattenLambdaSelfManagedEventSource(eventSourceMappingConfiguration.SelfManagedEventSource)}); err != nil { + if err := d.Set("self_managed_event_source", []interface{}{flattenSelfManagedEventSource(eventSourceMappingConfiguration.SelfManagedEventSource)}); err != nil { return fmt.Errorf("error setting self_managed_event_source: %w", err) } } else { d.Set("self_managed_event_source", nil) } - if err := d.Set("source_access_configuration", flattenLambdaSourceAccessConfigurations(eventSourceMappingConfiguration.SourceAccessConfigurations)); err != nil { + if err := d.Set("source_access_configuration", flattenSourceAccessConfigurations(eventSourceMappingConfiguration.SourceAccessConfigurations)); err != nil { return fmt.Errorf("error setting source_access_configuration: %w", err) } d.Set("starting_position", eventSourceMappingConfiguration.StartingPosition) @@ -545,7 +545,7 @@ func resourceEventSourceMappingUpdate(d *schema.ResourceData, meta interface{}) if d.HasChange("destination_config") { if v, ok := d.GetOk("destination_config"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil { - input.DestinationConfig = expandLambdaDestinationConfig(v.([]interface{})[0].(map[string]interface{})) + input.DestinationConfig = expandDestinationConfig(v.([]interface{})[0].(map[string]interface{})) } } @@ -555,7 +555,7 @@ func resourceEventSourceMappingUpdate(d *schema.ResourceData, meta interface{}) if d.HasChange("filter_criteria") { if v, ok := d.GetOk("filter_criteria"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil { - input.FilterCriteria = expandLambdaFilterCriteria(v.([]interface{})[0].(map[string]interface{})) + input.FilterCriteria = expandFilterCriteria(v.([]interface{})[0].(map[string]interface{})) } else { // AWS ignores the removal if this is left as nil. input.FilterCriteria = &lambda.FilterCriteria{} @@ -588,7 +588,7 @@ func resourceEventSourceMappingUpdate(d *schema.ResourceData, meta interface{}) if d.HasChange("source_access_configuration") { if v, ok := d.GetOk("source_access_configuration"); ok && v.(*schema.Set).Len() > 0 { - input.SourceAccessConfigurations = expandLambdaSourceAccessConfigurations(v.(*schema.Set).List()) + input.SourceAccessConfigurations = expandSourceAccessConfigurations(v.(*schema.Set).List()) } } @@ -667,7 +667,7 @@ func resourceEventSourceMappingDelete(d *schema.ResourceData, meta interface{}) return nil } -func expandLambdaDestinationConfig(tfMap map[string]interface{}) *lambda.DestinationConfig { +func expandDestinationConfig(tfMap map[string]interface{}) *lambda.DestinationConfig { if tfMap == nil { return nil } @@ -675,13 +675,13 @@ func expandLambdaDestinationConfig(tfMap map[string]interface{}) *lambda.Destina apiObject := &lambda.DestinationConfig{} if v, ok := tfMap["on_failure"].([]interface{}); ok && len(v) > 0 { - apiObject.OnFailure = expandLambdaOnFailure(v[0].(map[string]interface{})) + apiObject.OnFailure = expandOnFailure(v[0].(map[string]interface{})) } return apiObject } -func expandLambdaOnFailure(tfMap map[string]interface{}) *lambda.OnFailure { +func expandOnFailure(tfMap map[string]interface{}) *lambda.OnFailure { if tfMap == nil { return nil } @@ -695,7 +695,7 @@ func expandLambdaOnFailure(tfMap map[string]interface{}) *lambda.OnFailure { return apiObject } -func flattenLambdaDestinationConfig(apiObject *lambda.DestinationConfig) map[string]interface{} { +func flattenDestinationConfig(apiObject *lambda.DestinationConfig) map[string]interface{} { if apiObject == nil { return nil } @@ -703,13 +703,13 @@ func flattenLambdaDestinationConfig(apiObject *lambda.DestinationConfig) map[str tfMap := map[string]interface{}{} if v := apiObject.OnFailure; v != nil { - tfMap["on_failure"] = []interface{}{flattenLambdaOnFailure(v)} + tfMap["on_failure"] = []interface{}{flattenOnFailure(v)} } return tfMap } -func flattenLambdaOnFailure(apiObject *lambda.OnFailure) map[string]interface{} { +func flattenOnFailure(apiObject *lambda.OnFailure) map[string]interface{} { if apiObject == nil { return nil } @@ -723,7 +723,7 @@ func flattenLambdaOnFailure(apiObject *lambda.OnFailure) map[string]interface{} return tfMap } -func expandLambdaSelfManagedEventSource(tfMap map[string]interface{}) *lambda.SelfManagedEventSource { +func expandSelfManagedEventSource(tfMap map[string]interface{}) *lambda.SelfManagedEventSource { if tfMap == nil { return nil } @@ -743,7 +743,7 @@ func expandLambdaSelfManagedEventSource(tfMap map[string]interface{}) *lambda.Se return apiObject } -func flattenLambdaSelfManagedEventSource(apiObject *lambda.SelfManagedEventSource) map[string]interface{} { +func flattenSelfManagedEventSource(apiObject *lambda.SelfManagedEventSource) map[string]interface{} { if apiObject == nil { return nil } @@ -763,7 +763,7 @@ func flattenLambdaSelfManagedEventSource(apiObject *lambda.SelfManagedEventSourc return tfMap } -func expandLambdaSourceAccessConfiguration(tfMap map[string]interface{}) *lambda.SourceAccessConfiguration { +func expandSourceAccessConfiguration(tfMap map[string]interface{}) *lambda.SourceAccessConfiguration { if tfMap == nil { return nil } @@ -781,7 +781,7 @@ func expandLambdaSourceAccessConfiguration(tfMap map[string]interface{}) *lambda return apiObject } -func expandLambdaSourceAccessConfigurations(tfList []interface{}) []*lambda.SourceAccessConfiguration { +func expandSourceAccessConfigurations(tfList []interface{}) []*lambda.SourceAccessConfiguration { if len(tfList) == 0 { return nil } @@ -795,7 +795,7 @@ func expandLambdaSourceAccessConfigurations(tfList []interface{}) []*lambda.Sour continue } - apiObject := expandLambdaSourceAccessConfiguration(tfMap) + apiObject := expandSourceAccessConfiguration(tfMap) if apiObject == nil { continue @@ -807,7 +807,7 @@ func expandLambdaSourceAccessConfigurations(tfList []interface{}) []*lambda.Sour return apiObjects } -func flattenLambdaSourceAccessConfiguration(apiObject *lambda.SourceAccessConfiguration) map[string]interface{} { +func flattenSourceAccessConfiguration(apiObject *lambda.SourceAccessConfiguration) map[string]interface{} { if apiObject == nil { return nil } @@ -825,7 +825,7 @@ func flattenLambdaSourceAccessConfiguration(apiObject *lambda.SourceAccessConfig return tfMap } -func flattenLambdaSourceAccessConfigurations(apiObjects []*lambda.SourceAccessConfiguration) []interface{} { +func flattenSourceAccessConfigurations(apiObjects []*lambda.SourceAccessConfiguration) []interface{} { if len(apiObjects) == 0 { return nil } @@ -837,13 +837,13 @@ func flattenLambdaSourceAccessConfigurations(apiObjects []*lambda.SourceAccessCo continue } - tfList = append(tfList, flattenLambdaSourceAccessConfiguration(apiObject)) + tfList = append(tfList, flattenSourceAccessConfiguration(apiObject)) } return tfList } -func expandLambdaFilterCriteria(tfMap map[string]interface{}) *lambda.FilterCriteria { +func expandFilterCriteria(tfMap map[string]interface{}) *lambda.FilterCriteria { if tfMap == nil { return nil } @@ -851,13 +851,13 @@ func expandLambdaFilterCriteria(tfMap map[string]interface{}) *lambda.FilterCrit apiObject := &lambda.FilterCriteria{} if v, ok := tfMap["filter"].(*schema.Set); ok && v.Len() > 0 { - apiObject.Filters = expandLambdaFilters(v.List()) + apiObject.Filters = expandFilters(v.List()) } return apiObject } -func flattenLambdaFilterCriteria(apiObject *lambda.FilterCriteria) map[string]interface{} { +func flattenFilterCriteria(apiObject *lambda.FilterCriteria) map[string]interface{} { if apiObject == nil { return nil } @@ -865,13 +865,13 @@ func flattenLambdaFilterCriteria(apiObject *lambda.FilterCriteria) map[string]in tfMap := map[string]interface{}{} if v := apiObject.Filters; len(v) > 0 { - tfMap["filter"] = flattenLambdaFilters(v) + tfMap["filter"] = flattenFilters(v) } return tfMap } -func expandLambdaFilters(tfList []interface{}) []*lambda.Filter { +func expandFilters(tfList []interface{}) []*lambda.Filter { if len(tfList) == 0 { return nil } @@ -885,7 +885,7 @@ func expandLambdaFilters(tfList []interface{}) []*lambda.Filter { continue } - apiObject := expandLambdaFilter(tfMap) + apiObject := expandFilter(tfMap) if apiObject == nil { continue @@ -897,7 +897,7 @@ func expandLambdaFilters(tfList []interface{}) []*lambda.Filter { return apiObjects } -func flattenLambdaFilters(apiObjects []*lambda.Filter) []interface{} { +func flattenFilters(apiObjects []*lambda.Filter) []interface{} { if len(apiObjects) == 0 { return nil } @@ -909,13 +909,13 @@ func flattenLambdaFilters(apiObjects []*lambda.Filter) []interface{} { continue } - tfList = append(tfList, flattenLambdaFilter(apiObject)) + tfList = append(tfList, flattenFilter(apiObject)) } return tfList } -func expandLambdaFilter(tfMap map[string]interface{}) *lambda.Filter { +func expandFilter(tfMap map[string]interface{}) *lambda.Filter { if tfMap == nil { return nil } @@ -930,7 +930,7 @@ func expandLambdaFilter(tfMap map[string]interface{}) *lambda.Filter { return apiObject } -func flattenLambdaFilter(apiObject *lambda.Filter) map[string]interface{} { +func flattenFilter(apiObject *lambda.Filter) map[string]interface{} { if apiObject == nil { return nil } diff --git a/internal/service/lambda/event_source_mapping_test.go b/internal/service/lambda/event_source_mapping_test.go index c5fa33faecb..3ce929ab1b2 100644 --- a/internal/service/lambda/event_source_mapping_test.go +++ b/internal/service/lambda/event_source_mapping_test.go @@ -33,7 +33,7 @@ func TestAccLambdaEventSourceMapping_Kinesis_basic(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaEventSourceMappingDestroy, + CheckDestroy: testAccCheckEventSourceMappingDestroy, Steps: []resource.TestStep{ { Config: testAccEventSourceMappingKinesisBatchSizeConfig(rName, "100"), @@ -89,7 +89,7 @@ func TestAccLambdaEventSourceMapping_SQS_basic(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaEventSourceMappingDestroy, + CheckDestroy: testAccCheckEventSourceMappingDestroy, Steps: []resource.TestStep{ { Config: testAccEventSourceMappingSQSBatchSizeConfig(rName, "10"), @@ -144,7 +144,7 @@ func TestAccLambdaEventSourceMapping_DynamoDB_basic(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaEventSourceMappingDestroy, + CheckDestroy: testAccCheckEventSourceMappingDestroy, Steps: []resource.TestStep{ { Config: testAccEventSourceMappingDynamoDBBatchSizeConfig(rName, "100"), @@ -186,7 +186,7 @@ func TestAccLambdaEventSourceMapping_DynamoDB_functionResponseTypes(t *testing.T PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaEventSourceMappingDestroy, + CheckDestroy: testAccCheckEventSourceMappingDestroy, Steps: []resource.TestStep{ { Config: testAccEventSourceMappingDynamoDBFunctionResponseTypesConfig(rName), @@ -224,7 +224,7 @@ func TestAccLambdaEventSourceMapping_SQS_batchWindow(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaEventSourceMappingDestroy, + CheckDestroy: testAccCheckEventSourceMappingDestroy, Steps: []resource.TestStep{ { Config: testAccEventSourceMappingSQSBatchWindowConfig(rName, batchWindow), @@ -259,7 +259,7 @@ func TestAccLambdaEventSourceMapping_disappears(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaEventSourceMappingDestroy, + CheckDestroy: testAccCheckEventSourceMappingDestroy, Steps: []resource.TestStep{ { Config: testAccEventSourceMappingSQSBatchSizeConfig(rName, "7"), @@ -282,7 +282,7 @@ func TestAccLambdaEventSourceMapping_SQS_changesInEnabledAreDetected(t *testing. PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaEventSourceMappingDestroy, + CheckDestroy: testAccCheckEventSourceMappingDestroy, Steps: []resource.TestStep{ { Config: testAccEventSourceMappingSQSBatchSizeConfig(rName, "9"), @@ -306,7 +306,7 @@ func TestAccLambdaEventSourceMapping_Kinesis_startingPositionTimestamp(t *testin PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaEventSourceMappingDestroy, + CheckDestroy: testAccCheckEventSourceMappingDestroy, Steps: []resource.TestStep{ { Config: testAccEventSourceMappingKinesisStartingPositionTimestampConfig(rName, startingPositionTimestamp), @@ -337,7 +337,7 @@ func TestAccLambdaEventSourceMapping_Kinesis_batchWindow(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaEventSourceMappingDestroy, + CheckDestroy: testAccCheckEventSourceMappingDestroy, Steps: []resource.TestStep{ { Config: testAccEventSourceMappingKinesisBatchWindowConfig(rName, batchWindow), @@ -374,7 +374,7 @@ func TestAccLambdaEventSourceMapping_Kinesis_parallelizationFactor(t *testing.T) PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaEventSourceMappingDestroy, + CheckDestroy: testAccCheckEventSourceMappingDestroy, Steps: []resource.TestStep{ { Config: testAccEventSourceMappingKinesisParallelizationFactorConfig(rName, parallelizationFactor), @@ -411,7 +411,7 @@ func TestAccLambdaEventSourceMapping_Kinesis_tumblingWindowInSeconds(t *testing. PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaEventSourceMappingDestroy, + CheckDestroy: testAccCheckEventSourceMappingDestroy, Steps: []resource.TestStep{ { Config: testAccEventSourceMappingKinesisTumblingWindowInSecondsConfig(rName, tumblingWindowInSeconds), @@ -448,7 +448,7 @@ func TestAccLambdaEventSourceMapping_Kinesis_maximumRetryAttempts(t *testing.T) PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaEventSourceMappingDestroy, + CheckDestroy: testAccCheckEventSourceMappingDestroy, Steps: []resource.TestStep{ { Config: testAccEventSourceMappingKinesisMaximumRetryAttemptsConfig(rName, maximumRetryAttempts), @@ -485,7 +485,7 @@ func TestAccLambdaEventSourceMapping_Kinesis_maximumRetryAttemptsZero(t *testing PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaEventSourceMappingDestroy, + CheckDestroy: testAccCheckEventSourceMappingDestroy, Steps: []resource.TestStep{ { Config: testAccEventSourceMappingKinesisMaximumRetryAttemptsConfig(rName, maximumRetryAttempts), @@ -529,7 +529,7 @@ func TestAccLambdaEventSourceMapping_Kinesis_maximumRetryAttemptsNegativeOne(t * PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaEventSourceMappingDestroy, + CheckDestroy: testAccCheckEventSourceMappingDestroy, Steps: []resource.TestStep{ { Config: testAccEventSourceMappingKinesisMaximumRetryAttemptsConfig(rName, maximumRetryAttempts), @@ -573,7 +573,7 @@ func TestAccLambdaEventSourceMapping_Kinesis_maximumRecordAgeInSeconds(t *testin PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaEventSourceMappingDestroy, + CheckDestroy: testAccCheckEventSourceMappingDestroy, Steps: []resource.TestStep{ { Config: testAccEventSourceMappingKinesisMaximumRecordAgeInSecondsConfig(rName, maximumRecordAgeInSeconds), @@ -610,7 +610,7 @@ func TestAccLambdaEventSourceMapping_Kinesis_maximumRecordAgeInSecondsNegativeOn PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaEventSourceMappingDestroy, + CheckDestroy: testAccCheckEventSourceMappingDestroy, Steps: []resource.TestStep{ { Config: testAccEventSourceMappingKinesisMaximumRecordAgeInSecondsConfig(rName, maximumRecordAgeInSeconds), @@ -647,7 +647,7 @@ func TestAccLambdaEventSourceMapping_Kinesis_bisectBatch(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaEventSourceMappingDestroy, + CheckDestroy: testAccCheckEventSourceMappingDestroy, Steps: []resource.TestStep{ { Config: testAccEventSourceMappingKinesisBisectBatchConfig(rName, bisectBatch), @@ -683,7 +683,7 @@ func TestAccLambdaEventSourceMapping_Kinesis_destination(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaEventSourceMappingDestroy, + CheckDestroy: testAccCheckEventSourceMappingDestroy, Steps: []resource.TestStep{ { Config: testAccEventSourceMappingKinesisDestinationConfig(rName, rName), @@ -723,7 +723,7 @@ func TestAccLambdaEventSourceMapping_msk(t *testing.T) { PreCheck: func() { acctest.PreCheck(t); testAccPreCheckMSK(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID, "kafka"), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaEventSourceMappingDestroy, + CheckDestroy: testAccCheckEventSourceMappingDestroy, Steps: []resource.TestStep{ { Config: testAccEventSourceMappingMSKConfig(rName, "100"), @@ -773,7 +773,7 @@ func TestAccLambdaEventSourceMapping_selfManagedKafka(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaEventSourceMappingDestroy, + CheckDestroy: testAccCheckEventSourceMappingDestroy, Steps: []resource.TestStep{ { Config: testAccEventSourceMappingSelfManagedKafkaConfig(rName, "100", "test1:9092,test2:9092"), @@ -815,7 +815,7 @@ func TestAccLambdaEventSourceMapping_activeMQ(t *testing.T) { }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID, "mq", "secretsmanager"), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaEventSourceMappingDestroy, + CheckDestroy: testAccCheckEventSourceMappingDestroy, Steps: []resource.TestStep{ { Config: testAccEventSourceMappingActiveMQConfig(rName, "100"), @@ -853,7 +853,7 @@ func TestAccLambdaEventSourceMapping_rabbitMQ(t *testing.T) { }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID, "mq", "secretsmanager"), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaEventSourceMappingDestroy, + CheckDestroy: testAccCheckEventSourceMappingDestroy, Steps: []resource.TestStep{ { Config: testAccEventSourceMappingRabbitMQConfig(rName, "100"), @@ -888,7 +888,7 @@ func TestAccLambdaEventSourceMapping_SQS_filterCriteria(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaEventSourceMappingDestroy, + CheckDestroy: testAccCheckEventSourceMappingDestroy, Steps: []resource.TestStep{ { Config: testAccEventSourceMappingSQSFilterCriteria_1(rName, pattern1), @@ -999,7 +999,7 @@ func testAccCheckEventSourceMappingIsBeingDisabled(conf *lambda.EventSourceMappi } } -func testAccCheckLambdaEventSourceMappingDestroy(s *terraform.State) error { +func testAccCheckEventSourceMappingDestroy(s *terraform.State) error { conn := acctest.Provider.Meta().(*conns.AWSClient).LambdaConn for _, rs := range s.RootModule().Resources { diff --git a/internal/service/lambda/function.go b/internal/service/lambda/function.go index 9e4cd3b3089..be8c5bcc4ce 100644 --- a/internal/service/lambda/function.go +++ b/internal/service/lambda/function.go @@ -482,11 +482,11 @@ func resourceFunctionCreate(d *schema.ResourceData, meta interface{}) error { } if v, ok := d.GetOk("file_system_config"); ok && len(v.([]interface{})) > 0 { - params.FileSystemConfigs = expandLambdaFileSystemConfigs(v.([]interface{})) + params.FileSystemConfigs = expandFileSystemConfigs(v.([]interface{})) } if v, ok := d.GetOk("image_config"); ok && len(v.([]interface{})) > 0 { - params.ImageConfig = expandLambdaImageConfigs(v.([]interface{})) + params.ImageConfig = expandImageConfigs(v.([]interface{})) } if v, ok := d.GetOk("vpc_config"); ok && len(v.([]interface{})) > 0 { @@ -595,7 +595,7 @@ func resourceFunctionCreate(d *schema.ResourceData, meta interface{}) error { d.SetId(d.Get("function_name").(string)) - if err := waitForLambdaFunctionCreation(conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { + if err := waitForFunctionCreation(conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { return fmt.Errorf("error waiting for Lambda Function (%s) creation: %w", d.Id(), err) } @@ -751,7 +751,7 @@ func resourceFunctionRead(d *schema.ResourceData, meta interface{}) error { return fmt.Errorf("error setting signing job arn for Lambda Function: %w", err) } - fileSystemConfigs := flattenLambdaFileSystemConfigs(function.FileSystemConfigs) + fileSystemConfigs := flattenFileSystemConfigs(function.FileSystemConfigs) log.Printf("[INFO] Setting Lambda %s file system configs %#v from API", d.Id(), fileSystemConfigs) if err := d.Set("file_system_config", fileSystemConfigs); err != nil { return fmt.Errorf("error setting file system config for Lambda Function (%s): %w", d.Id(), err) @@ -786,7 +786,7 @@ func resourceFunctionRead(d *schema.ResourceData, meta interface{}) error { return fmt.Errorf("error setting vpc_config for Lambda Function (%s): %w", d.Id(), err) } - environment := flattenLambdaEnvironment(function.Environment) + environment := flattenEnvironment(function.Environment) log.Printf("[INFO] Setting Lambda %s environment %#v from API", d.Id(), environment) if err := d.Set("environment", environment); err != nil { log.Printf("[ERR] Error setting environment for Lambda Function (%s): %s", d.Id(), err) @@ -842,7 +842,7 @@ func resourceFunctionRead(d *schema.ResourceData, meta interface{}) error { d.Set("qualified_arn", lastQualifiedArn) } - invokeArn := lambdaFunctionInvokeArn(*function.FunctionArn, meta) + invokeArn := functionInvokeArn(*function.FunctionArn, meta) d.Set("invoke_arn", invokeArn) // Currently, this functionality is only enabled in AWS Commercial partition @@ -990,13 +990,13 @@ func resourceFunctionUpdate(d *schema.ResourceData, meta interface{}) error { if d.HasChange("file_system_config") { configReq.FileSystemConfigs = make([]*lambda.FileSystemConfig, 0) if v, ok := d.GetOk("file_system_config"); ok && len(v.([]interface{})) > 0 { - configReq.FileSystemConfigs = expandLambdaFileSystemConfigs(v.([]interface{})) + configReq.FileSystemConfigs = expandFileSystemConfigs(v.([]interface{})) } } if d.HasChange("image_config") { configReq.ImageConfig = &lambda.ImageConfig{} if v, ok := d.GetOk("image_config"); ok && len(v.([]interface{})) > 0 { - configReq.ImageConfig = expandLambdaImageConfigs(v.([]interface{})) + configReq.ImageConfig = expandImageConfigs(v.([]interface{})) } } if d.HasChange("memory_size") { @@ -1138,7 +1138,7 @@ func resourceFunctionUpdate(d *schema.ResourceData, meta interface{}) error { } } - if err := waitForLambdaFunctionUpdate(conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil { + if err := waitForFunctionUpdate(conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil { return fmt.Errorf("error waiting for Lambda Function (%s) configuration update: %w", d.Id(), err) } } @@ -1188,7 +1188,7 @@ func resourceFunctionUpdate(d *schema.ResourceData, meta interface{}) error { return fmt.Errorf("error modifying Lambda Function (%s) Code: %w", d.Id(), err) } - if err := waitForLambdaFunctionUpdate(conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil { + if err := waitForFunctionUpdate(conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil { return fmt.Errorf("error waiting for Lambda Function (%s) code update: %w", d.Id(), err) } } @@ -1287,7 +1287,7 @@ func readEnvironmentVariables(ev map[string]interface{}) map[string]string { return variables } -func lambdaFunctionInvokeArn(functionArn string, meta interface{}) string { +func functionInvokeArn(functionArn string, meta interface{}) string { return arn.ARN{ Partition: meta.(*conns.AWSClient).Partition, Service: "apigateway", @@ -1297,7 +1297,7 @@ func lambdaFunctionInvokeArn(functionArn string, meta interface{}) string { }.String() } -func refreshLambdaFunctionLastUpdateStatus(conn *lambda.Lambda, functionName string) resource.StateRefreshFunc { +func refreshFunctionLastUpdateStatus(conn *lambda.Lambda, functionName string) resource.StateRefreshFunc { return func() (interface{}, string, error) { input := &lambda.GetFunctionInput{ FunctionName: aws.String(functionName), @@ -1323,7 +1323,7 @@ func refreshLambdaFunctionLastUpdateStatus(conn *lambda.Lambda, functionName str } } -func refreshLambdaFunctionState(conn *lambda.Lambda, functionName string) resource.StateRefreshFunc { +func refreshFunctionState(conn *lambda.Lambda, functionName string) resource.StateRefreshFunc { return func() (interface{}, string, error) { input := &lambda.GetFunctionInput{ FunctionName: aws.String(functionName), @@ -1349,11 +1349,11 @@ func refreshLambdaFunctionState(conn *lambda.Lambda, functionName string) resour } } -func waitForLambdaFunctionCreation(conn *lambda.Lambda, functionName string, timeout time.Duration) error { +func waitForFunctionCreation(conn *lambda.Lambda, functionName string, timeout time.Duration) error { stateConf := &resource.StateChangeConf{ Pending: []string{lambda.StatePending}, Target: []string{lambda.StateActive}, - Refresh: refreshLambdaFunctionState(conn, functionName), + Refresh: refreshFunctionState(conn, functionName), Timeout: timeout, Delay: 5 * time.Second, } @@ -1363,11 +1363,11 @@ func waitForLambdaFunctionCreation(conn *lambda.Lambda, functionName string, tim return err } -func waitForLambdaFunctionUpdate(conn *lambda.Lambda, functionName string, timeout time.Duration) error { +func waitForFunctionUpdate(conn *lambda.Lambda, functionName string, timeout time.Duration) error { stateConf := &resource.StateChangeConf{ Pending: []string{lambda.LastUpdateStatusInProgress}, Target: []string{lambda.LastUpdateStatusSuccessful}, - Refresh: refreshLambdaFunctionLastUpdateStatus(conn, functionName), + Refresh: refreshFunctionLastUpdateStatus(conn, functionName), Timeout: timeout, Delay: 5 * time.Second, } @@ -1377,7 +1377,7 @@ func waitForLambdaFunctionUpdate(conn *lambda.Lambda, functionName string, timeo return err } -func flattenLambdaEnvironment(apiObject *lambda.EnvironmentResponse) []interface{} { +func flattenEnvironment(apiObject *lambda.EnvironmentResponse) []interface{} { if apiObject == nil { return nil } @@ -1391,7 +1391,7 @@ func flattenLambdaEnvironment(apiObject *lambda.EnvironmentResponse) []interface return []interface{}{tfMap} } -func flattenLambdaFileSystemConfigs(fscList []*lambda.FileSystemConfig) []map[string]interface{} { +func flattenFileSystemConfigs(fscList []*lambda.FileSystemConfig) []map[string]interface{} { results := make([]map[string]interface{}, 0, len(fscList)) for _, fsc := range fscList { f := make(map[string]interface{}) @@ -1403,7 +1403,7 @@ func flattenLambdaFileSystemConfigs(fscList []*lambda.FileSystemConfig) []map[st return results } -func expandLambdaFileSystemConfigs(fscMaps []interface{}) []*lambda.FileSystemConfig { +func expandFileSystemConfigs(fscMaps []interface{}) []*lambda.FileSystemConfig { fileSystemConfigs := make([]*lambda.FileSystemConfig, 0, len(fscMaps)) for _, fsc := range fscMaps { fscMap := fsc.(map[string]interface{}) @@ -1429,7 +1429,7 @@ func FlattenImageConfig(response *lambda.ImageConfigResponse) []map[string]inter return []map[string]interface{}{settings} } -func expandLambdaImageConfigs(imageConfigMaps []interface{}) *lambda.ImageConfig { +func expandImageConfigs(imageConfigMaps []interface{}) *lambda.ImageConfig { imageConfig := &lambda.ImageConfig{} // only one image_config block is allowed if len(imageConfigMaps) == 1 && imageConfigMaps[0] != nil { diff --git a/internal/service/lambda/function_data_source.go b/internal/service/lambda/function_data_source.go index bc4d18766aa..366fb01a0be 100644 --- a/internal/service/lambda/function_data_source.go +++ b/internal/service/lambda/function_data_source.go @@ -253,12 +253,12 @@ func dataSourceFunctionRead(d *schema.ResourceData, meta interface{}) error { d.Set("description", function.Description) - if err := d.Set("environment", flattenLambdaEnvironment(function.Environment)); err != nil { + if err := d.Set("environment", flattenEnvironment(function.Environment)); err != nil { return fmt.Errorf("error setting environment: %w", err) } d.Set("handler", function.Handler) - d.Set("invoke_arn", lambdaFunctionInvokeArn(aws.StringValue(function.FunctionArn), meta)) + d.Set("invoke_arn", functionInvokeArn(aws.StringValue(function.FunctionArn), meta)) d.Set("kms_key_arn", function.KMSKeyArn) d.Set("last_modified", function.LastModified) @@ -317,7 +317,7 @@ func dataSourceFunctionRead(d *schema.ResourceData, meta interface{}) error { return fmt.Errorf("error setting vpc_config: %w", err) } - if err := d.Set("file_system_config", flattenLambdaFileSystemConfigs(function.FileSystemConfigs)); err != nil { + if err := d.Set("file_system_config", flattenFileSystemConfigs(function.FileSystemConfigs)); err != nil { return fmt.Errorf("error setting file_system_config: %w", err) } diff --git a/internal/service/lambda/function_data_source_test.go b/internal/service/lambda/function_data_source_test.go index dffeb978e30..aa3976688c2 100644 --- a/internal/service/lambda/function_data_source_test.go +++ b/internal/service/lambda/function_data_source_test.go @@ -198,7 +198,7 @@ func TestAccLambdaFunctionDataSource_image(t *testing.T) { imageLatestID := os.Getenv("AWS_LAMBDA_IMAGE_LATEST_ID") resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(t); testAccDataSourceLambdaImagePreCheck(t) }, + PreCheck: func() { acctest.PreCheck(t); testAccImagePreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, Steps: []resource.TestStep{ @@ -588,7 +588,7 @@ data "aws_lambda_function" "test" { `, rName) } -func testAccDataSourceLambdaImagePreCheck(t *testing.T) { +func testAccImagePreCheck(t *testing.T) { if os.Getenv("AWS_LAMBDA_IMAGE_LATEST_ID") == "" { t.Skip("AWS_LAMBDA_IMAGE_LATEST_ID env var must be set for Lambda Function Data Source Image Support acceptance tests.") } diff --git a/internal/service/lambda/function_event_invoke_config.go b/internal/service/lambda/function_event_invoke_config.go index 2c28e2b089f..e006b4aa6c7 100644 --- a/internal/service/lambda/function_event_invoke_config.go +++ b/internal/service/lambda/function_event_invoke_config.go @@ -105,7 +105,7 @@ func resourceFunctionEventInvokeConfigCreate(d *schema.ResourceData, meta interf } input := &lambda.PutFunctionEventInvokeConfigInput{ - DestinationConfig: expandLambdaFunctionEventInvokeConfigDestinationConfig(d.Get("destination_config").([]interface{})), + DestinationConfig: expandFunctionEventInvokeConfigDestinationConfig(d.Get("destination_config").([]interface{})), FunctionName: aws.String(functionName), MaximumRetryAttempts: aws.Int64(int64(d.Get("maximum_retry_attempts").(int))), } @@ -181,7 +181,7 @@ func resourceFunctionEventInvokeConfigRead(d *schema.ResourceData, meta interfac return fmt.Errorf("error getting Lambda Function Event Invoke Config (%s): %s", d.Id(), err) } - if err := d.Set("destination_config", flattenLambdaFunctionEventInvokeConfigDestinationConfig(output.DestinationConfig)); err != nil { + if err := d.Set("destination_config", flattenFunctionEventInvokeConfigDestinationConfig(output.DestinationConfig)); err != nil { return fmt.Errorf("error setting destination_config: %s", err) } @@ -203,7 +203,7 @@ func resourceFunctionEventInvokeConfigUpdate(d *schema.ResourceData, meta interf } input := &lambda.PutFunctionEventInvokeConfigInput{ - DestinationConfig: expandLambdaFunctionEventInvokeConfigDestinationConfig(d.Get("destination_config").([]interface{})), + DestinationConfig: expandFunctionEventInvokeConfigDestinationConfig(d.Get("destination_config").([]interface{})), FunctionName: aws.String(functionName), MaximumRetryAttempts: aws.Int64(int64(d.Get("maximum_retry_attempts").(int))), } @@ -319,7 +319,7 @@ func FunctionEventInvokeConfigParseID(id string) (string, string, error) { return idParts[0], idParts[1], nil } -func expandLambdaFunctionEventInvokeConfigDestinationConfig(l []interface{}) *lambda.DestinationConfig { +func expandFunctionEventInvokeConfigDestinationConfig(l []interface{}) *lambda.DestinationConfig { if len(l) == 0 || l[0] == nil { return nil } @@ -329,17 +329,17 @@ func expandLambdaFunctionEventInvokeConfigDestinationConfig(l []interface{}) *la destinationConfig := &lambda.DestinationConfig{} if v, ok := m["on_failure"].([]interface{}); ok { - destinationConfig.OnFailure = expandLambdaFunctionEventInvokeConfigDestinationConfigOnFailure(v) + destinationConfig.OnFailure = expandFunctionEventInvokeConfigDestinationConfigOnFailure(v) } if v, ok := m["on_success"].([]interface{}); ok { - destinationConfig.OnSuccess = expandLambdaFunctionEventInvokeConfigDestinationConfigOnSuccess(v) + destinationConfig.OnSuccess = expandFunctionEventInvokeConfigDestinationConfigOnSuccess(v) } return destinationConfig } -func expandLambdaFunctionEventInvokeConfigDestinationConfigOnFailure(l []interface{}) *lambda.OnFailure { +func expandFunctionEventInvokeConfigDestinationConfigOnFailure(l []interface{}) *lambda.OnFailure { if len(l) == 0 || l[0] == nil { return nil } @@ -355,7 +355,7 @@ func expandLambdaFunctionEventInvokeConfigDestinationConfigOnFailure(l []interfa return onFailure } -func expandLambdaFunctionEventInvokeConfigDestinationConfigOnSuccess(l []interface{}) *lambda.OnSuccess { +func expandFunctionEventInvokeConfigDestinationConfigOnSuccess(l []interface{}) *lambda.OnSuccess { if len(l) == 0 || l[0] == nil { return nil } @@ -371,7 +371,7 @@ func expandLambdaFunctionEventInvokeConfigDestinationConfigOnSuccess(l []interfa return onSuccess } -func flattenLambdaFunctionEventInvokeConfigDestinationConfig(destinationConfig *lambda.DestinationConfig) []interface{} { +func flattenFunctionEventInvokeConfigDestinationConfig(destinationConfig *lambda.DestinationConfig) []interface{} { // The API will respond with empty OnFailure and OnSuccess destinations when unconfigured: // "DestinationConfig":{"OnFailure":{"Destination":null},"OnSuccess":{"Destination":null}} // Return no destination configuration to prevent Terraform state difference @@ -389,14 +389,14 @@ func flattenLambdaFunctionEventInvokeConfigDestinationConfig(destinationConfig * } m := map[string]interface{}{ - "on_failure": flattenLambdaFunctionEventInvokeConfigDestinationConfigOnFailure(destinationConfig.OnFailure), - "on_success": flattenLambdaFunctionEventInvokeConfigDestinationConfigOnSuccess(destinationConfig.OnSuccess), + "on_failure": flattenFunctionEventInvokeConfigDestinationConfigOnFailure(destinationConfig.OnFailure), + "on_success": flattenFunctionEventInvokeConfigDestinationConfigOnSuccess(destinationConfig.OnSuccess), } return []interface{}{m} } -func flattenLambdaFunctionEventInvokeConfigDestinationConfigOnFailure(onFailure *lambda.OnFailure) []interface{} { +func flattenFunctionEventInvokeConfigDestinationConfigOnFailure(onFailure *lambda.OnFailure) []interface{} { // The API will respond with empty OnFailure destination when unconfigured: // "DestinationConfig":{"OnFailure":{"Destination":null},"OnSuccess":{"Destination":null}} // Return no on failure configuration to prevent Terraform state difference @@ -412,7 +412,7 @@ func flattenLambdaFunctionEventInvokeConfigDestinationConfigOnFailure(onFailure return []interface{}{m} } -func flattenLambdaFunctionEventInvokeConfigDestinationConfigOnSuccess(onSuccess *lambda.OnSuccess) []interface{} { +func flattenFunctionEventInvokeConfigDestinationConfigOnSuccess(onSuccess *lambda.OnSuccess) []interface{} { // The API will respond with empty OnSuccess destination when unconfigured: // "DestinationConfig":{"OnFailure":{"Destination":null},"OnSuccess":{"Destination":null}} // Return no on success configuration to prevent Terraform state difference diff --git a/internal/service/lambda/function_event_invoke_config_test.go b/internal/service/lambda/function_event_invoke_config_test.go index 6194a1fe59b..0fd4fa4c855 100644 --- a/internal/service/lambda/function_event_invoke_config_test.go +++ b/internal/service/lambda/function_event_invoke_config_test.go @@ -24,7 +24,7 @@ func TestAccLambdaFunctionEventInvokeConfig_basic(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionEventInvokeConfigDestroy, + CheckDestroy: testAccCheckFunctionEventInvokeConfigDestroy, Steps: []resource.TestStep{ { Config: testAccFunctionEventInvokeFunctionNameConfig(rName), @@ -56,7 +56,7 @@ func TestAccLambdaFunctionEventInvokeConfig_Disappears_lambdaFunction(t *testing PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionEventInvokeConfigDestroy, + CheckDestroy: testAccCheckFunctionEventInvokeConfigDestroy, Steps: []resource.TestStep{ { Config: testAccFunctionEventInvokeFunctionNameConfig(rName), @@ -79,7 +79,7 @@ func TestAccLambdaFunctionEventInvokeConfig_Disappears_lambdaFunctionEventInvoke PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionEventInvokeConfigDestroy, + CheckDestroy: testAccCheckFunctionEventInvokeConfigDestroy, Steps: []resource.TestStep{ { Config: testAccFunctionEventInvokeFunctionNameConfig(rName), @@ -103,7 +103,7 @@ func TestAccLambdaFunctionEventInvokeConfig_DestinationOnFailure_destination(t * PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionEventInvokeConfigDestroy, + CheckDestroy: testAccCheckFunctionEventInvokeConfigDestroy, Steps: []resource.TestStep{ { Config: testAccFunctionEventInvokeDestinationOnFailureDestinationSQSQueueConfig(rName), @@ -142,7 +142,7 @@ func TestAccLambdaFunctionEventInvokeConfig_DestinationOnSuccess_destination(t * PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionEventInvokeConfigDestroy, + CheckDestroy: testAccCheckFunctionEventInvokeConfigDestroy, Steps: []resource.TestStep{ { Config: testAccFunctionEventInvokeDestinationOnSuccessDestinationSQSQueueConfig(rName), @@ -180,7 +180,7 @@ func TestAccLambdaFunctionEventInvokeConfig_Destination_remove(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionEventInvokeConfigDestroy, + CheckDestroy: testAccCheckFunctionEventInvokeConfigDestroy, Steps: []resource.TestStep{ { Config: testAccFunctionEventInvokeDestinationOnFailureDestinationSQSQueueConfig(rName), @@ -216,7 +216,7 @@ func TestAccLambdaFunctionEventInvokeConfig_Destination_swap(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionEventInvokeConfigDestroy, + CheckDestroy: testAccCheckFunctionEventInvokeConfigDestroy, Steps: []resource.TestStep{ { Config: testAccFunctionEventInvokeDestinationOnFailureDestinationSQSQueueConfig(rName), @@ -254,7 +254,7 @@ func TestAccLambdaFunctionEventInvokeConfig_FunctionName_arn(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionEventInvokeConfigDestroy, + CheckDestroy: testAccCheckFunctionEventInvokeConfigDestroy, Steps: []resource.TestStep{ { Config: testAccFunctionEventInvokeFunctionNameARNConfig(rName), @@ -282,7 +282,7 @@ func TestAccLambdaFunctionEventInvokeConfig_QualifierFunctionName_arn(t *testing PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionEventInvokeConfigDestroy, + CheckDestroy: testAccCheckFunctionEventInvokeConfigDestroy, Steps: []resource.TestStep{ { Config: testAccFunctionEventInvokeQualifierFunctionNameARNConfig(rName), @@ -309,7 +309,7 @@ func TestAccLambdaFunctionEventInvokeConfig_maximumEventAgeInSeconds(t *testing. PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionEventInvokeConfigDestroy, + CheckDestroy: testAccCheckFunctionEventInvokeConfigDestroy, Steps: []resource.TestStep{ { Config: testAccFunctionEventInvokeMaximumEventAgeInSecondsConfig(rName, 100), @@ -342,7 +342,7 @@ func TestAccLambdaFunctionEventInvokeConfig_maximumRetryAttempts(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionEventInvokeConfigDestroy, + CheckDestroy: testAccCheckFunctionEventInvokeConfigDestroy, Steps: []resource.TestStep{ { Config: testAccFunctionEventInvokeMaximumRetryAttemptsConfig(rName, 0), @@ -383,7 +383,7 @@ func TestAccLambdaFunctionEventInvokeConfig_Qualifier_aliasName(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionEventInvokeConfigDestroy, + CheckDestroy: testAccCheckFunctionEventInvokeConfigDestroy, Steps: []resource.TestStep{ { Config: testAccFunctionEventInvokeQualifierAliasNameConfig(rName), @@ -410,7 +410,7 @@ func TestAccLambdaFunctionEventInvokeConfig_Qualifier_functionVersion(t *testing PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionEventInvokeConfigDestroy, + CheckDestroy: testAccCheckFunctionEventInvokeConfigDestroy, Steps: []resource.TestStep{ { Config: testAccFunctionEventInvokeQualifierFunctionVersionConfig(rName), @@ -437,7 +437,7 @@ func TestAccLambdaFunctionEventInvokeConfig_Qualifier_latest(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionEventInvokeConfigDestroy, + CheckDestroy: testAccCheckFunctionEventInvokeConfigDestroy, Steps: []resource.TestStep{ { Config: testAccFunctionEventInvokeQualifierLatestConfig(rName), @@ -455,7 +455,7 @@ func TestAccLambdaFunctionEventInvokeConfig_Qualifier_latest(t *testing.T) { }) } -func testAccCheckLambdaFunctionEventInvokeConfigDestroy(s *terraform.State) error { +func testAccCheckFunctionEventInvokeConfigDestroy(s *terraform.State) error { conn := acctest.Provider.Meta().(*conns.AWSClient).LambdaConn for _, rs := range s.RootModule().Resources { diff --git a/internal/service/lambda/function_test.go b/internal/service/lambda/function_test.go index cc42aec0c8a..2a974b29da5 100644 --- a/internal/service/lambda/function_test.go +++ b/internal/service/lambda/function_test.go @@ -23,10 +23,10 @@ import ( ) func init() { - acctest.RegisterServiceErrorCheckFunc(lambda.EndpointsID, testAccErrorCheckSkipLambda) + acctest.RegisterServiceErrorCheckFunc(lambda.EndpointsID, testAccErrorCheckSkip) } -func testAccErrorCheckSkipLambda(t *testing.T) resource.ErrorCheckFunc { +func testAccErrorCheckSkip(t *testing.T) resource.ErrorCheckFunc { return acctest.ErrorCheckSkipMessagesContaining(t, "InvalidParameterValueException: Unsupported source arn", "InvalidParameterValueException: CompatibleArchitectures are not", @@ -47,7 +47,7 @@ func TestAccLambdaFunction_basic(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionDestroy, + CheckDestroy: testAccCheckFunctionDestroy, Steps: []resource.TestStep{ { Config: testAccBasicConfig(funcName, policyName, roleName, sgName), @@ -96,7 +96,7 @@ func TestAccLambdaFunction_unpublishedCodeUpdate(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionDestroy, + CheckDestroy: testAccCheckFunctionDestroy, Steps: []resource.TestStep{ { Config: testAccFilenameConfig(initialFilename, funcName, policyName, roleName, sgName), @@ -143,7 +143,7 @@ func TestAccLambdaFunction_disappears(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionDestroy, + CheckDestroy: testAccCheckFunctionDestroy, Steps: []resource.TestStep{ { Config: testAccBasicConfig(rName, rName, rName, rName), @@ -180,7 +180,7 @@ func TestAccLambdaFunction_codeSigning(t *testing.T) { PreCheck: func() { acctest.PreCheck(t); testAccPreCheckSingerSigningProfile(t, "AWSLambda-SHA384-ECDSA") }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionDestroy, + CheckDestroy: testAccCheckFunctionDestroy, Steps: []resource.TestStep{ { Config: testAccCSCCreateConfig(roleName, funcName), @@ -239,7 +239,7 @@ func TestAccLambdaFunction_concurrency(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionDestroy, + CheckDestroy: testAccCheckFunctionDestroy, Steps: []resource.TestStep{ { Config: testAccBasicConcurrencyConfig(funcName, policyName, roleName, sgName), @@ -283,7 +283,7 @@ func TestAccLambdaFunction_concurrencyCycle(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionDestroy, + CheckDestroy: testAccCheckFunctionDestroy, Steps: []resource.TestStep{ { Config: testAccBasicConfig(funcName, policyName, roleName, sgName), @@ -333,7 +333,7 @@ func TestAccLambdaFunction_expectFilenameAndS3Attributes(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionDestroy, + CheckDestroy: testAccCheckFunctionDestroy, Steps: []resource.TestStep{ { Config: testAccWithoutFilenameAndS3AttributesConfig(funcName, policyName, roleName, sgName), @@ -357,7 +357,7 @@ func TestAccLambdaFunction_envVariables(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionDestroy, + CheckDestroy: testAccCheckFunctionDestroy, Steps: []resource.TestStep{ { Config: testAccBasicConfig(funcName, policyName, roleName, sgName), @@ -415,7 +415,7 @@ func TestAccLambdaFunction_EnvironmentVariables_noValue(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionDestroy, + CheckDestroy: testAccCheckFunctionDestroy, Steps: []resource.TestStep{ { Config: testAccEnvironmentVariablesNoValueConfig(rName), @@ -449,7 +449,7 @@ func TestAccLambdaFunction_encryptedEnvVariables(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionDestroy, + CheckDestroy: testAccCheckFunctionDestroy, Steps: []resource.TestStep{ { Config: testAccEncryptedEnvVariablesConfig(keyDesc, funcName, policyName, roleName, sgName), @@ -497,7 +497,7 @@ func TestAccLambdaFunction_versioned(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionDestroy, + CheckDestroy: testAccCheckFunctionDestroy, Steps: []resource.TestStep{ { Config: testAccPublishableConfig("test-fixtures/lambdatest.zip", funcName, policyName, roleName, sgName, true), @@ -544,7 +544,7 @@ func TestAccLambdaFunction_versionedUpdate(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionDestroy, + CheckDestroy: testAccCheckFunctionDestroy, Steps: []resource.TestStep{ { Config: testAccPublishableConfig("test-fixtures/lambdatest.zip", funcName, policyName, roleName, sgName, true), @@ -619,7 +619,7 @@ func TestAccLambdaFunction_enablePublish(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionDestroy, + CheckDestroy: testAccCheckFunctionDestroy, Steps: []resource.TestStep{ { Config: testAccPublishableConfig(fileName, funcName, policyName, roleName, sgName, false), @@ -683,7 +683,7 @@ func TestAccLambdaFunction_disablePublish(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionDestroy, + CheckDestroy: testAccCheckFunctionDestroy, Steps: []resource.TestStep{ { Config: testAccPublishableConfig(fileName, funcName, policyName, roleName, sgName, true), @@ -733,7 +733,7 @@ func TestAccLambdaFunction_deadLetter(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionDestroy, + CheckDestroy: testAccCheckFunctionDestroy, Steps: []resource.TestStep{ { Config: testAccWithDeadLetterConfig(funcName, topicName, policyName, roleName, sgName), @@ -785,7 +785,7 @@ func TestAccLambdaFunction_deadLetterUpdated(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionDestroy, + CheckDestroy: testAccCheckFunctionDestroy, Steps: []resource.TestStep{ { Config: testAccWithDeadLetterConfig(funcName, topic1Name, policyName, roleName, sgName), @@ -825,7 +825,7 @@ func TestAccLambdaFunction_nilDeadLetter(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionDestroy, + CheckDestroy: testAccCheckFunctionDestroy, Steps: []resource.TestStep{ { Config: testAccWithNilDeadLetterConfig(funcName, policyName, roleName, sgName), @@ -850,7 +850,7 @@ func TestAccLambdaFunction_fileSystem(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionDestroy, + CheckDestroy: testAccCheckFunctionDestroy, Steps: []resource.TestStep{ // Ensure a function with lambda file system configuration can be created { @@ -919,7 +919,7 @@ func TestAccLambdaFunction_image(t *testing.T) { }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionDestroy, + CheckDestroy: testAccCheckFunctionDestroy, Steps: []resource.TestStep{ // Ensure a function with lambda image configuration can be created { @@ -978,7 +978,7 @@ func TestAccLambdaFunction_architectures(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionDestroy, + CheckDestroy: testAccCheckFunctionDestroy, Steps: []resource.TestStep{ // Ensure function with arm64 architecture can be created { @@ -1031,7 +1031,7 @@ func TestAccLambdaFunction_architecturesUpdate(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionDestroy, + CheckDestroy: testAccCheckFunctionDestroy, Steps: []resource.TestStep{ // Ensure function with arm64 architecture can be created { @@ -1085,7 +1085,7 @@ func TestAccLambdaFunction_architecturesWithLayer(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionDestroy, + CheckDestroy: testAccCheckFunctionDestroy, Steps: []resource.TestStep{ // Ensure function with arm64 architecture can be created { @@ -1141,7 +1141,7 @@ func TestAccLambdaFunction_tracing(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionDestroy, + CheckDestroy: testAccCheckFunctionDestroy, Steps: []resource.TestStep{ { Config: testAccWithTracingConfig(funcName, policyName, roleName, sgName), @@ -1185,7 +1185,7 @@ func TestAccLambdaFunction_KMSKeyARN_noEnvironmentVariables(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionDestroy, + CheckDestroy: testAccCheckFunctionDestroy, Steps: []resource.TestStep{ { Config: testAccKMSKeyARNNoEnvironmentVariablesConfig(rName), @@ -1220,7 +1220,7 @@ func TestAccLambdaFunction_layers(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionDestroy, + CheckDestroy: testAccCheckFunctionDestroy, Steps: []resource.TestStep{ { Config: testAccWithLayersConfig(funcName, layerName, policyName, roleName, sgName), @@ -1258,7 +1258,7 @@ func TestAccLambdaFunction_layersUpdate(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionDestroy, + CheckDestroy: testAccCheckFunctionDestroy, Steps: []resource.TestStep{ { Config: testAccWithLayersConfig(funcName, layerName, policyName, roleName, sgName), @@ -1304,7 +1304,7 @@ func TestAccLambdaFunction_vpc(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionDestroy, + CheckDestroy: testAccCheckFunctionDestroy, Steps: []resource.TestStep{ { Config: testAccWithVPCConfig(funcName, policyName, roleName, sgName), @@ -1339,7 +1339,7 @@ func TestAccLambdaFunction_vpcRemoval(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionDestroy, + CheckDestroy: testAccCheckFunctionDestroy, Steps: []resource.TestStep{ { Config: testAccWithVPCConfig(rName, rName, rName, rName), @@ -1380,7 +1380,7 @@ func TestAccLambdaFunction_vpcUpdate(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionDestroy, + CheckDestroy: testAccCheckFunctionDestroy, Steps: []resource.TestStep{ { Config: testAccWithVPCConfig(funcName, policyName, roleName, sgName), @@ -1432,7 +1432,7 @@ func TestAccLambdaFunction_VPC_withInvocation(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionDestroy, + CheckDestroy: testAccCheckFunctionDestroy, Steps: []resource.TestStep{ { Config: testAccWithVPCConfig(funcName, policyName, roleName, sgName), @@ -1466,7 +1466,7 @@ func TestAccLambdaFunction_VPCPublishNo_changes(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionDestroy, + CheckDestroy: testAccCheckFunctionDestroy, Steps: []resource.TestStep{ { Config: testAccWithVPCPublishConfig(funcName, policyName, roleName, sgName), @@ -1508,7 +1508,7 @@ func TestAccLambdaFunction_VPCPublishHas_changes(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionDestroy, + CheckDestroy: testAccCheckFunctionDestroy, Steps: []resource.TestStep{ { @@ -1547,7 +1547,7 @@ func TestAccLambdaFunction_VPC_properIAMDependencies(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionDestroy, + CheckDestroy: testAccCheckFunctionDestroy, Steps: []resource.TestStep{ { Config: testAccVPCProperIAMDependenciesConfig(rName), @@ -1577,7 +1577,7 @@ func TestAccLambdaFunction_emptyVPC(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionDestroy, + CheckDestroy: testAccCheckFunctionDestroy, Steps: []resource.TestStep{ { Config: testAccWithEmptyVPCConfig(funcName, policyName, roleName, sgName), @@ -1609,7 +1609,7 @@ func TestAccLambdaFunction_s3(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionDestroy, + CheckDestroy: testAccCheckFunctionDestroy, Steps: []resource.TestStep{ { Config: testAccS3Config(bucketName, roleName, funcName), @@ -1650,7 +1650,7 @@ func TestAccLambdaFunction_localUpdate(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionDestroy, + CheckDestroy: testAccCheckFunctionDestroy, Steps: []resource.TestStep{ { PreConfig: func() { @@ -1718,7 +1718,7 @@ func TestAccLambdaFunction_LocalUpdate_nameOnly(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionDestroy, + CheckDestroy: testAccCheckFunctionDestroy, Steps: []resource.TestStep{ { PreConfig: func() { @@ -1779,7 +1779,7 @@ func TestAccLambdaFunction_S3Update_basic(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionDestroy, + CheckDestroy: testAccCheckFunctionDestroy, Steps: []resource.TestStep{ { PreConfig: func() { @@ -1842,7 +1842,7 @@ func TestAccLambdaFunction_S3Update_unversioned(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionDestroy, + CheckDestroy: testAccCheckFunctionDestroy, Steps: []resource.TestStep{ { PreConfig: func() { @@ -1898,7 +1898,7 @@ func TestAccLambdaFunction_tags(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionDestroy, + CheckDestroy: testAccCheckFunctionDestroy, Steps: []resource.TestStep{ { Config: testAccBasicConfig(funcName, policyName, roleName, sgName), @@ -1994,7 +1994,7 @@ func TestAccLambdaFunction_runtimes(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionDestroy, + CheckDestroy: testAccCheckFunctionDestroy, Steps: steps, }) } @@ -2010,7 +2010,7 @@ func TestAccLambdaFunction_Zip_validation(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaFunctionDestroy, + CheckDestroy: testAccCheckFunctionDestroy, Steps: []resource.TestStep{ { Config: testAccZipWithoutHandlerConfig(funcName, policyName, roleName, sgName), @@ -2024,7 +2024,7 @@ func TestAccLambdaFunction_Zip_validation(t *testing.T) { }) } -func testAccCheckLambdaFunctionDestroy(s *terraform.State) error { +func testAccCheckFunctionDestroy(s *terraform.State) error { conn := acctest.Provider.Meta().(*conns.AWSClient).LambdaConn for _, rs := range s.RootModule().Resources { @@ -3415,7 +3415,7 @@ resource "aws_lambda_function" "test" { `, funcName) } -func TestFlattenLambdaImageConfigShouldNotFailWithEmptyImageConfig(t *testing.T) { +func TestFlattenImageConfigShouldNotFailWithEmptyImageConfig(t *testing.T) { t.Parallel() response := lambda.ImageConfigResponse{} tflambda.FlattenImageConfig(&response) diff --git a/internal/service/lambda/invocation.go b/internal/service/lambda/invocation.go new file mode 100644 index 00000000000..fe4d3c15895 --- /dev/null +++ b/internal/service/lambda/invocation.go @@ -0,0 +1,88 @@ +package lambda + +import ( + "crypto/md5" + "fmt" + "log" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/lambda" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" + "github.com/hashicorp/terraform-provider-aws/internal/conns" +) + +func ResourceInvocation() *schema.Resource { + return &schema.Resource{ + Create: resourceInvocationCreate, + Read: resourceInvocationRead, + Delete: resourceInvocationDelete, + + Schema: map[string]*schema.Schema{ + "function_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "input": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringIsJSON, + }, + "qualifier": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Default: FunctionVersionLatest, + }, + "result": { + Type: schema.TypeString, + Computed: true, + }, + "triggers": { + Type: schema.TypeMap, + Optional: true, + ForceNew: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + }, + } +} + +func resourceInvocationCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*conns.AWSClient).LambdaConn + + functionName := d.Get("function_name").(string) + qualifier := d.Get("qualifier").(string) + input := []byte(d.Get("input").(string)) + + res, err := conn.Invoke(&lambda.InvokeInput{ + FunctionName: aws.String(functionName), + InvocationType: aws.String(lambda.InvocationTypeRequestResponse), + Payload: input, + Qualifier: aws.String(qualifier), + }) + + if err != nil { + return fmt.Errorf("Lambda Invocation (%s) failed: %w", d.Id(), err) + } + + if res.FunctionError != nil { + return fmt.Errorf("Lambda function (%s) returned error: (%s)", functionName, string(res.Payload)) + } + + d.SetId(fmt.Sprintf("%s_%s_%x", functionName, qualifier, md5.Sum(input))) + d.Set("result", string(res.Payload)) + + return nil +} + +func resourceInvocationRead(d *schema.ResourceData, meta interface{}) error { + return nil +} + +func resourceInvocationDelete(d *schema.ResourceData, meta interface{}) error { + log.Printf("[DEBUG] Lambda Invocation (%s) \"deleted\" by removing from state", d.Id()) + return nil +} diff --git a/internal/service/lambda/invocation_data_source_test.go b/internal/service/lambda/invocation_data_source_test.go index bf2ceb851ce..69826e8ea6d 100644 --- a/internal/service/lambda/invocation_data_source_test.go +++ b/internal/service/lambda/invocation_data_source_test.go @@ -12,7 +12,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/verify" ) -func testAccCheckLambdaInvocationResult(name, expectedResult string) resource.TestCheckFunc { +func testAccCheckInvocationResult(name, expectedResult string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[name] if !ok { @@ -49,7 +49,7 @@ func TestAccLambdaInvocationDataSource_basic(t *testing.T) { { Config: testAccInvocationDataSource_basic_config(rName, testData), Check: resource.ComposeTestCheckFunc( - testAccCheckLambdaInvocationResult("data.aws_lambda_invocation.invocation_test", `{"key1":"value1","key2":"value2","key3":"`+testData+`"}`), + testAccCheckInvocationResult("data.aws_lambda_invocation.invocation_test", `{"key1":"value1","key2":"value2","key3":"`+testData+`"}`), ), }, }, @@ -68,7 +68,7 @@ func TestAccLambdaInvocationDataSource_qualifier(t *testing.T) { { Config: testAccInvocationDataSource_qualifier_config(rName, testData), Check: resource.ComposeTestCheckFunc( - testAccCheckLambdaInvocationResult("data.aws_lambda_invocation.invocation_test", `{"key1":"value1","key2":"value2","key3":"`+testData+`"}`), + testAccCheckInvocationResult("data.aws_lambda_invocation.invocation_test", `{"key1":"value1","key2":"value2","key3":"`+testData+`"}`), ), }, }, @@ -87,7 +87,7 @@ func TestAccLambdaInvocationDataSource_complex(t *testing.T) { { Config: testAccInvocationDataSource_complex_config(rName, testData), Check: resource.ComposeTestCheckFunc( - testAccCheckLambdaInvocationResult("data.aws_lambda_invocation.invocation_test", `{"key1":{"subkey1":"subvalue1"},"key2":{"subkey2":"subvalue2","subkey3":{"a": "b"}},"key3":"`+testData+`"}`), + testAccCheckInvocationResult("data.aws_lambda_invocation.invocation_test", `{"key1":{"subkey1":"subvalue1"},"key2":{"subkey2":"subvalue2","subkey3":{"a": "b"}},"key3":"`+testData+`"}`), ), }, }, diff --git a/internal/service/lambda/invocation_test.go b/internal/service/lambda/invocation_test.go new file mode 100644 index 00000000000..c3135a74988 --- /dev/null +++ b/internal/service/lambda/invocation_test.go @@ -0,0 +1,289 @@ +package lambda_test + +import ( + "fmt" + "testing" + + "github.com/aws/aws-sdk-go/service/lambda" + sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/hashicorp/terraform-provider-aws/internal/acctest" +) + +func TestAccLambdaInvocation_basic(t *testing.T) { + resourceName := "aws_lambda_invocation.test" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + testData := "value3" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(t) }, + ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), + Providers: acctest.Providers, + CheckDestroy: testAccCheckInvocationDestroy, + Steps: []resource.TestStep{ + { + Config: testAccConfigInvocation_basic(rName, testData), + Check: resource.ComposeTestCheckFunc( + testAccCheckInvocationResult(resourceName, fmt.Sprintf(`{"key1":"value1","key2":"value2","key3":%q}`, testData)), + ), + }, + }, + }) +} + +func TestAccLambdaInvocation_qualifier(t *testing.T) { + resourceName := "aws_lambda_invocation.test" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + testData := "value3" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(t) }, + ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), + Providers: acctest.Providers, + CheckDestroy: testAccCheckInvocationDestroy, + Steps: []resource.TestStep{ + { + Config: testAccConfigInvocation_qualifier(rName, testData), + Check: resource.ComposeTestCheckFunc( + testAccCheckInvocationResult(resourceName, `{"key1":"value1","key2":"value2","key3":"`+testData+`"}`), + ), + }, + }, + }) +} + +func TestAccLambdaInvocation_complex(t *testing.T) { + resourceName := "aws_lambda_invocation.test" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + testData := "value3" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(t) }, + ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), + Providers: acctest.Providers, + CheckDestroy: testAccCheckInvocationDestroy, + Steps: []resource.TestStep{ + { + Config: testAccConfigInvocation_complex(rName, testData), + Check: resource.ComposeTestCheckFunc( + testAccCheckInvocationResult(resourceName, `{"key1":{"subkey1":"subvalue1"},"key2":{"subkey2":"subvalue2","subkey3":{"a": "b"}},"key3":"`+testData+`"}`), + ), + }, + }, + }) +} + +func TestAccLambdaInvocation_triggers(t *testing.T) { + resourceName := "aws_lambda_invocation.test" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + testData := "value3" + testData2 := "value4" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(t) }, + ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), + Providers: acctest.Providers, + CheckDestroy: testAccCheckInvocationDestroy, + Steps: []resource.TestStep{ + { + Config: testAccConfigInvocation_triggers(rName, testData), + Check: resource.ComposeTestCheckFunc( + testAccCheckInvocationResult(resourceName, `{"key1":{"subkey1":"subvalue1"},"key2":{"subkey2":"subvalue2","subkey3":{"a": "b"}},"key3":"`+testData+`"}`), + ), + }, + { + Config: testAccConfigInvocation_triggers(rName, testData), + Check: resource.ComposeTestCheckFunc( + testAccCheckInvocationResult(resourceName, `{"key1":{"subkey1":"subvalue1"},"key2":{"subkey2":"subvalue2","subkey3":{"a": "b"}},"key3":"`+testData+`"}`), + ), + }, + { + Config: testAccConfigInvocation_triggers(rName, testData2), + Check: resource.ComposeTestCheckFunc( + testAccCheckInvocationResult(resourceName, `{"key1":{"subkey1":"subvalue1"},"key2":{"subkey2":"subvalue2","subkey3":{"a": "b"}},"key3":"`+testData2+`"}`), + ), + }, + }, + }) +} + +func testAccCheckInvocationDestroy(s *terraform.State) error { + // Nothing to check on destroy + return nil +} + +func testAccConfigInvocation_base(roleName string) string { + return fmt.Sprintf(` +data "aws_partition" "current" {} + +data "aws_iam_policy_document" "test" { + statement { + effect = "Allow" + actions = ["sts:AssumeRole"] + principals { + type = "Service" + identifiers = ["lambda.${data.aws_partition.current.dns_suffix}"] + } + } +} + +resource "aws_iam_role" "test" { + name = %[1]q + assume_role_policy = data.aws_iam_policy_document.test.json +} + +resource "aws_iam_role_policy_attachment" "test" { + policy_arn = "arn:${data.aws_partition.current.partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + role = aws_iam_role.test.name +} +`, roleName) +} + +func testAccConfigInvocation_basic(rName, testData string) string { + return acctest.ConfigCompose( + testAccConfigInvocation_base(rName), + fmt.Sprintf(` +resource "aws_lambda_function" "test" { + depends_on = [aws_iam_role_policy_attachment.test] + + filename = "test-fixtures/lambda_invocation.zip" + function_name = %[1]q + role = aws_iam_role.test.arn + handler = "lambda_invocation.handler" + runtime = "nodejs14.x" + + environment { + variables = { + TEST_DATA = %[2]q + } + } +} + +resource "aws_lambda_invocation" "test" { + function_name = aws_lambda_function.test.function_name + + input = jsonencode({ + key1 = "value1" + key2 = "value2" + }) +} +`, rName, testData)) +} + +func testAccConfigInvocation_qualifier(rName, testData string) string { + return acctest.ConfigCompose( + testAccConfigInvocation_base(rName), + fmt.Sprintf(` +resource "aws_lambda_function" "test" { + depends_on = [aws_iam_role_policy_attachment.test] + + filename = "test-fixtures/lambda_invocation.zip" + function_name = %[1]q + role = aws_iam_role.test.arn + handler = "lambda_invocation.handler" + runtime = "nodejs14.x" + publish = true + + environment { + variables = { + TEST_DATA = %[2]q + } + } +} + +resource "aws_lambda_invocation" "test" { + function_name = aws_lambda_function.test.function_name + qualifier = aws_lambda_function.test.version + + input = jsonencode({ + key1 = "value1" + key2 = "value2" + }) +} +`, rName, testData)) +} + +func testAccConfigInvocation_complex(rName, testData string) string { + return acctest.ConfigCompose( + testAccConfigInvocation_base(rName), + fmt.Sprintf(` +resource "aws_lambda_function" "test" { + depends_on = [aws_iam_role_policy_attachment.test] + + filename = "test-fixtures/lambda_invocation.zip" + function_name = %[1]q + role = aws_iam_role.test.arn + handler = "lambda_invocation.handler" + runtime = "nodejs14.x" + publish = true + + environment { + variables = { + TEST_DATA = %[2]q + } + } +} + +resource "aws_lambda_invocation" "test" { + function_name = aws_lambda_function.test.function_name + + input = jsonencode({ + key1 = { + subkey1 = "subvalue1" + } + key2 = { + subkey2 = "subvalue2" + subkey3 = { + a = "b" + } + } + }) +} +`, rName, testData)) +} + +func testAccConfigInvocation_triggers(rName, testData string) string { + return acctest.ConfigCompose( + testAccConfigInvocation_base(rName), + fmt.Sprintf(` +resource "aws_lambda_function" "test" { + depends_on = [aws_iam_role_policy_attachment.test] + + filename = "test-fixtures/lambda_invocation.zip" + function_name = %[1]q + role = aws_iam_role.test.arn + handler = "lambda_invocation.handler" + runtime = "nodejs14.x" + publish = true + + environment { + variables = { + TEST_DATA = %[2]q + } + } +} + +resource "aws_lambda_invocation" "test" { + function_name = aws_lambda_function.test.function_name + + triggers = { + redeployment = sha1(jsonencode([ + aws_lambda_function.test.environment + ])) + } + + input = jsonencode({ + key1 = { + subkey1 = "subvalue1" + } + key2 = { + subkey2 = "subvalue2" + subkey3 = { + a = "b" + } + } + }) +} +`, rName, testData)) +} diff --git a/internal/service/lambda/layer_version_permission_test.go b/internal/service/lambda/layer_version_permission_test.go index 8fe43492ccf..26f9d490808 100644 --- a/internal/service/lambda/layer_version_permission_test.go +++ b/internal/service/lambda/layer_version_permission_test.go @@ -23,12 +23,12 @@ func TestAccLambdaLayerVersionPermission_basic_byARN(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaLayerVersionPermissionDestroy, + CheckDestroy: testAccCheckLayerVersionPermissionDestroy, Steps: []resource.TestStep{ { Config: testLayerVersionPermission_basic_arn(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckAwsLambdaLayerVersionPermissionExists(resourceName), + testAccCheckLayerVersionPermissionExists(resourceName), resource.TestCheckResourceAttr(resourceName, "action", "lambda:GetLayerVersion"), resource.TestCheckResourceAttr(resourceName, "principal", "*"), resource.TestCheckResourceAttr(resourceName, "statement_id", "xaccount"), @@ -52,12 +52,12 @@ func TestAccLambdaLayerVersionPermission_basic_byName(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaLayerVersionPermissionDestroy, + CheckDestroy: testAccCheckLayerVersionPermissionDestroy, Steps: []resource.TestStep{ { Config: testLayerVersionPermission_basic_name(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckAwsLambdaLayerVersionPermissionExists(resourceName), + testAccCheckLayerVersionPermissionExists(resourceName), resource.TestCheckResourceAttr(resourceName, "action", "lambda:GetLayerVersion"), resource.TestCheckResourceAttr(resourceName, "principal", "*"), resource.TestCheckResourceAttr(resourceName, "statement_id", "xaccount"), @@ -81,12 +81,12 @@ func TestAccLambdaLayerVersionPermission_org(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaLayerVersionPermissionDestroy, + CheckDestroy: testAccCheckLayerVersionPermissionDestroy, Steps: []resource.TestStep{ { Config: testLayerVersionPermission_org(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckAwsLambdaLayerVersionPermissionExists(resourceName), + testAccCheckLayerVersionPermissionExists(resourceName), resource.TestCheckResourceAttr(resourceName, "action", "lambda:GetLayerVersion"), resource.TestCheckResourceAttr(resourceName, "principal", "*"), resource.TestCheckResourceAttr(resourceName, "statement_id", "xaccount"), @@ -111,12 +111,12 @@ func TestAccLambdaLayerVersionPermission_account(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaLayerVersionPermissionDestroy, + CheckDestroy: testAccCheckLayerVersionPermissionDestroy, Steps: []resource.TestStep{ { Config: testLayerVersionPermission_account(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckAwsLambdaLayerVersionPermissionExists(resourceName), + testAccCheckLayerVersionPermissionExists(resourceName), resource.TestCheckResourceAttr(resourceName, "action", "lambda:GetLayerVersion"), resource.TestCheckResourceAttrPair(resourceName, "principal", "data.aws_caller_identity.current", "account_id"), resource.TestCheckResourceAttr(resourceName, "statement_id", "xaccount"), @@ -140,12 +140,12 @@ func TestAccLambdaLayerVersionPermission_disappears(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaLayerVersionPermissionDestroy, + CheckDestroy: testAccCheckLayerVersionPermissionDestroy, Steps: []resource.TestStep{ { Config: testLayerVersionPermission_account(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckAwsLambdaLayerVersionPermissionExists(resourceName), + testAccCheckLayerVersionPermissionExists(resourceName), acctest.CheckResourceDisappears(acctest.Provider, tflambda.ResourceLayerVersionPermission(), resourceName), ), ExpectNonEmptyPlan: true, @@ -227,7 +227,7 @@ resource "aws_lambda_layer_version_permission" "test" { `, layerName) } -func testAccCheckAwsLambdaLayerVersionPermissionExists(n string) resource.TestCheckFunc { +func testAccCheckLayerVersionPermissionExists(n string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -258,7 +258,7 @@ func testAccCheckAwsLambdaLayerVersionPermissionExists(n string) resource.TestCh } } -func testAccCheckLambdaLayerVersionPermissionDestroy(s *terraform.State) error { +func testAccCheckLayerVersionPermissionDestroy(s *terraform.State) error { conn := acctest.Provider.Meta().(*conns.AWSClient).LambdaConn for _, rs := range s.RootModule().Resources { diff --git a/internal/service/lambda/permission.go b/internal/service/lambda/permission.go index 5c7e2a54384..450fa0778ae 100644 --- a/internal/service/lambda/permission.go +++ b/internal/service/lambda/permission.go @@ -217,7 +217,7 @@ func resourcePermissionRead(d *schema.ResourceData, meta interface{}) error { return resource.NonRetryableError(err) } - statement, err = getLambdaPolicyStatement(out, d.Id()) + statement, err = getPolicyStatement(out, d.Id()) if err != nil { return resource.RetryableError(err) } @@ -228,7 +228,7 @@ func resourcePermissionRead(d *schema.ResourceData, meta interface{}) error { if err == nil { var psErr error - statement, psErr = getLambdaPolicyStatement(out, d.Id()) + statement, psErr = getPolicyStatement(out, d.Id()) // handle the resource not existing if awsErr, ok := psErr.(awserr.Error); ok { @@ -364,7 +364,7 @@ func resourcePermissionDelete(d *schema.ResourceData, meta interface{}) error { return nil } - statement, err := getLambdaPolicyStatement(resp, d.Id()) + statement, err := getPolicyStatement(resp, d.Id()) if tfresource.NotFound(err) { return nil @@ -382,7 +382,7 @@ func resourcePermissionDelete(d *schema.ResourceData, meta interface{}) error { return nil } -func getLambdaPolicyStatement(out *lambda.GetPolicyOutput, statemendId string) (statement *PolicyStatement, err error) { +func getPolicyStatement(out *lambda.GetPolicyOutput, statemendId string) (statement *PolicyStatement, err error) { policyInBytes := []byte(*out.Policy) policy := Policy{} err = json.Unmarshal(policyInBytes, &policy) diff --git a/internal/service/lambda/permission_test.go b/internal/service/lambda/permission_test.go index 9058fb7afb3..8f481a20c4b 100644 --- a/internal/service/lambda/permission_test.go +++ b/internal/service/lambda/permission_test.go @@ -188,7 +188,7 @@ func TestAccLambdaPermission_basic(t *testing.T) { { Config: testAccPermissionConfig(funcName, roleName), Check: resource.ComposeTestCheckFunc( - testAccCheckLambdaPermissionExists(resourceName, &statement), + testAccCheckPermissionExists(resourceName, &statement), resource.TestCheckResourceAttr(resourceName, "action", "lambda:InvokeFunction"), resource.TestCheckResourceAttr(resourceName, "principal", "events.amazonaws.com"), resource.TestCheckResourceAttr(resourceName, "statement_id", "AllowExecutionFromCloudWatch"), @@ -243,7 +243,7 @@ func TestAccLambdaPermission_withRawFunctionName(t *testing.T) { { Config: testAccPermissionConfig_withRawFunctionName(funcName, roleName), Check: resource.ComposeTestCheckFunc( - testAccCheckLambdaPermissionExists(resourceName, &statement), + testAccCheckPermissionExists(resourceName, &statement), resource.TestCheckResourceAttr(resourceName, "action", "lambda:InvokeFunction"), resource.TestCheckResourceAttr(resourceName, "principal", "events.amazonaws.com"), resource.TestCheckResourceAttr(resourceName, "statement_id", "AllowExecutionWithRawFuncName"), @@ -278,7 +278,7 @@ func TestAccLambdaPermission_withStatementIdPrefix(t *testing.T) { { Config: testAccPermissionConfig_withStatementIdPrefix(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckLambdaPermissionExists(resourceName, &statement), + testAccCheckPermissionExists(resourceName, &statement), resource.TestCheckResourceAttr(resourceName, "action", "lambda:InvokeFunction"), resource.TestCheckResourceAttr(resourceName, "principal", "events.amazonaws.com"), resource.TestMatchResourceAttr(resourceName, "statement_id", startsWithPrefix), @@ -316,7 +316,7 @@ func TestAccLambdaPermission_withQualifier(t *testing.T) { { Config: testAccPermissionConfig_withQualifier(aliasName, funcName, roleName), Check: resource.ComposeTestCheckFunc( - testAccCheckLambdaPermissionExists(resourceName, &statement), + testAccCheckPermissionExists(resourceName, &statement), resource.TestCheckResourceAttr(resourceName, "action", "lambda:InvokeFunction"), resource.TestCheckResourceAttr(resourceName, "principal", "events.amazonaws.com"), resource.TestCheckResourceAttr(resourceName, "statement_id", "AllowExecutionWithQualifier"), @@ -387,13 +387,13 @@ func TestAccLambdaPermission_multiplePerms(t *testing.T) { Config: testAccPermissionConfig_multiplePerms(funcName, roleName), Check: resource.ComposeTestCheckFunc( // 1st - testAccCheckLambdaPermissionExists(resourceNameFirst, &firstStatement), + testAccCheckPermissionExists(resourceNameFirst, &firstStatement), resource.TestCheckResourceAttr(resourceNameFirst, "action", "lambda:InvokeFunction"), resource.TestCheckResourceAttr(resourceNameFirst, "principal", "events.amazonaws.com"), resource.TestCheckResourceAttr(resourceNameFirst, "statement_id", "AllowExecutionFirst"), resource.TestCheckResourceAttrPair(resourceNameFirst, "function_name", functionResourceName, "arn"), // 2nd - testAccCheckLambdaPermissionExists(resourceNameSecond, &firstStatementModified), + testAccCheckPermissionExists(resourceNameSecond, &firstStatementModified), resource.TestCheckResourceAttr(resourceNameSecond, "action", "lambda:*"), resource.TestCheckResourceAttr(resourceNameSecond, "principal", "events.amazonaws.com"), resource.TestCheckResourceAttr(resourceNameSecond, "statement_id", "AllowExecutionSecond"), @@ -404,19 +404,19 @@ func TestAccLambdaPermission_multiplePerms(t *testing.T) { Config: testAccPermissionConfig_multiplePermsModified(funcName, roleName), Check: resource.ComposeTestCheckFunc( // 1st - testAccCheckLambdaPermissionExists(resourceNameFirst, &secondStatement), + testAccCheckPermissionExists(resourceNameFirst, &secondStatement), resource.TestCheckResourceAttr(resourceNameFirst, "action", "lambda:InvokeFunction"), resource.TestCheckResourceAttr(resourceNameFirst, "principal", "events.amazonaws.com"), resource.TestCheckResourceAttr(resourceNameFirst, "statement_id", "AllowExecutionFirst"), resource.TestCheckResourceAttrPair(resourceNameFirst, "function_name", functionResourceName, "arn"), // 2nd - testAccCheckLambdaPermissionExists(resourceNameSecondModified, &secondStatementModified), + testAccCheckPermissionExists(resourceNameSecondModified, &secondStatementModified), resource.TestCheckResourceAttr(resourceNameSecondModified, "action", "lambda:*"), resource.TestCheckResourceAttr(resourceNameSecondModified, "principal", "events.amazonaws.com"), resource.TestCheckResourceAttr(resourceNameSecondModified, "statement_id", "AllowExecutionSec0nd"), resource.TestCheckResourceAttrPair(resourceNameSecondModified, "function_name", functionResourceName, "arn"), // 3rd - testAccCheckLambdaPermissionExists(resourceNameThird, &thirdStatement), + testAccCheckPermissionExists(resourceNameThird, &thirdStatement), resource.TestCheckResourceAttr(resourceNameThird, "action", "lambda:*"), resource.TestCheckResourceAttr(resourceNameThird, "principal", "events.amazonaws.com"), resource.TestCheckResourceAttr(resourceNameThird, "statement_id", "AllowExecutionThird"), @@ -460,7 +460,7 @@ func TestAccLambdaPermission_withS3(t *testing.T) { { Config: testAccPermissionConfig_withS3(bucketName, funcName, roleName), Check: resource.ComposeTestCheckFunc( - testAccCheckLambdaPermissionExists(resourceName, &statement), + testAccCheckPermissionExists(resourceName, &statement), resource.TestCheckResourceAttr(resourceName, "action", "lambda:InvokeFunction"), resource.TestCheckResourceAttr(resourceName, "principal", "s3.amazonaws.com"), resource.TestCheckResourceAttr(resourceName, "statement_id", "AllowExecutionFromS3"), @@ -499,7 +499,7 @@ func TestAccLambdaPermission_withSNS(t *testing.T) { { Config: testAccPermissionConfig_withSNS(topicName, funcName, roleName), Check: resource.ComposeTestCheckFunc( - testAccCheckLambdaPermissionExists(resourceName, &statement), + testAccCheckPermissionExists(resourceName, &statement), resource.TestCheckResourceAttr(resourceName, "action", "lambda:InvokeFunction"), resource.TestCheckResourceAttr(resourceName, "principal", "sns.amazonaws.com"), resource.TestCheckResourceAttr(resourceName, "statement_id", "AllowExecutionFromSNS"), @@ -537,7 +537,7 @@ func TestAccLambdaPermission_withIAMRole(t *testing.T) { { Config: testAccPermissionConfig_withIAMRole(funcName, roleName), Check: resource.ComposeTestCheckFunc( - testAccCheckLambdaPermissionExists(resourceName, &statement), + testAccCheckPermissionExists(resourceName, &statement), resource.TestCheckResourceAttr(resourceName, "action", "lambda:InvokeFunction"), resource.TestCheckResourceAttrPair(resourceName, "principal", iamRoleResourceName, "arn"), resource.TestCheckResourceAttr(resourceName, "statement_id", "AllowExecutionFromIAMRole"), @@ -589,7 +589,7 @@ func testAccPermissionDisappears(n string) resource.TestCheckFunc { } } -func testAccCheckLambdaPermissionExists(n string, statement *tflambda.PolicyStatement) resource.TestCheckFunc { +func testAccCheckPermissionExists(n string, statement *tflambda.PolicyStatement) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -637,7 +637,7 @@ func testAccCheckPermissionDestroy(s *terraform.State) error { // IAM is eventually consistent err := resource.Retry(5*time.Minute, func() *resource.RetryError { - err := isLambdaPermissionGone(rs, conn) + err := isPermissionGone(rs, conn) if err != nil { if !strings.HasPrefix(err.Error(), "Error unmarshalling Lambda policy") { return resource.RetryableError(err) @@ -654,7 +654,7 @@ func testAccCheckPermissionDestroy(s *terraform.State) error { return nil } -func isLambdaPermissionGone(rs *terraform.ResourceState, conn *lambda.Lambda) error { +func isPermissionGone(rs *terraform.ResourceState, conn *lambda.Lambda) error { params := &lambda.GetPolicyInput{ FunctionName: aws.String(rs.Primary.Attributes["function_name"]), } diff --git a/internal/service/lambda/provisioned_concurrency_config.go b/internal/service/lambda/provisioned_concurrency_config.go index cd64cefa664..67557daf98e 100644 --- a/internal/service/lambda/provisioned_concurrency_config.go +++ b/internal/service/lambda/provisioned_concurrency_config.go @@ -70,7 +70,7 @@ func resourceProvisionedConcurrencyConfigCreate(d *schema.ResourceData, meta int d.SetId(fmt.Sprintf("%s:%s", functionName, qualifier)) - if err := waitForLambdaProvisionedConcurrencyConfigStatusReady(conn, functionName, qualifier, d.Timeout(schema.TimeoutCreate)); err != nil { + if err := waitForProvisionedConcurrencyConfigStatusReady(conn, functionName, qualifier, d.Timeout(schema.TimeoutCreate)); err != nil { return fmt.Errorf("error waiting for Lambda Provisioned Concurrency Config (%s) to be ready: %s", d.Id(), err) } @@ -131,7 +131,7 @@ func resourceProvisionedConcurrencyConfigUpdate(d *schema.ResourceData, meta int return fmt.Errorf("error putting Lambda Provisioned Concurrency Config (%s:%s): %s", functionName, qualifier, err) } - if err := waitForLambdaProvisionedConcurrencyConfigStatusReady(conn, functionName, qualifier, d.Timeout(schema.TimeoutUpdate)); err != nil { + if err := waitForProvisionedConcurrencyConfigStatusReady(conn, functionName, qualifier, d.Timeout(schema.TimeoutUpdate)); err != nil { return fmt.Errorf("error waiting for Lambda Provisioned Concurrency Config (%s) to be ready: %s", d.Id(), err) } @@ -175,7 +175,7 @@ func ProvisionedConcurrencyConfigParseID(id string) (string, string, error) { return parts[0], parts[1], nil } -func refreshLambdaProvisionedConcurrencyConfigStatus(conn *lambda.Lambda, functionName, qualifier string) resource.StateRefreshFunc { +func refreshProvisionedConcurrencyConfigStatus(conn *lambda.Lambda, functionName, qualifier string) resource.StateRefreshFunc { return func() (interface{}, string, error) { input := &lambda.GetProvisionedConcurrencyConfigInput{ FunctionName: aws.String(functionName), @@ -198,11 +198,11 @@ func refreshLambdaProvisionedConcurrencyConfigStatus(conn *lambda.Lambda, functi } } -func waitForLambdaProvisionedConcurrencyConfigStatusReady(conn *lambda.Lambda, functionName, qualifier string, timeout time.Duration) error { +func waitForProvisionedConcurrencyConfigStatusReady(conn *lambda.Lambda, functionName, qualifier string, timeout time.Duration) error { stateConf := &resource.StateChangeConf{ Pending: []string{lambda.ProvisionedConcurrencyStatusEnumInProgress}, Target: []string{lambda.ProvisionedConcurrencyStatusEnumReady}, - Refresh: refreshLambdaProvisionedConcurrencyConfigStatus(conn, functionName, qualifier), + Refresh: refreshProvisionedConcurrencyConfigStatus(conn, functionName, qualifier), Timeout: timeout, Delay: 5 * time.Second, } diff --git a/internal/service/lambda/provisioned_concurrency_config_test.go b/internal/service/lambda/provisioned_concurrency_config_test.go index 9d7c232f388..c0e9ef6a8a1 100644 --- a/internal/service/lambda/provisioned_concurrency_config_test.go +++ b/internal/service/lambda/provisioned_concurrency_config_test.go @@ -24,7 +24,7 @@ func TestAccLambdaProvisionedConcurrencyConfig_basic(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaProvisionedConcurrencyConfigDestroy, + CheckDestroy: testAccCheckProvisionedConcurrencyConfigDestroy, Steps: []resource.TestStep{ { Config: testAccProvisionedConcurrencyQualifierFunctionVersionConfig(rName), @@ -54,7 +54,7 @@ func TestAccLambdaProvisionedConcurrencyConfig_Disappears_lambdaFunction(t *test PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaProvisionedConcurrencyConfigDestroy, + CheckDestroy: testAccCheckProvisionedConcurrencyConfigDestroy, Steps: []resource.TestStep{ { Config: testAccProvisionedConcurrencyProvisionedConcurrentExecutionsConfig(rName, 1), @@ -77,7 +77,7 @@ func TestAccLambdaProvisionedConcurrencyConfig_Disappears_lambdaProvisionedConcu PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaProvisionedConcurrencyConfigDestroy, + CheckDestroy: testAccCheckProvisionedConcurrencyConfigDestroy, Steps: []resource.TestStep{ { Config: testAccProvisionedConcurrencyProvisionedConcurrentExecutionsConfig(rName, 1), @@ -99,7 +99,7 @@ func TestAccLambdaProvisionedConcurrencyConfig_provisionedConcurrentExecutions(t PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaProvisionedConcurrencyConfigDestroy, + CheckDestroy: testAccCheckProvisionedConcurrencyConfigDestroy, Steps: []resource.TestStep{ { Config: testAccProvisionedConcurrencyProvisionedConcurrentExecutionsConfig(rName, 1), @@ -137,7 +137,7 @@ func TestAccLambdaProvisionedConcurrencyConfig_Qualifier_aliasName(t *testing.T) PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, lambda.EndpointsID), Providers: acctest.Providers, - CheckDestroy: testAccCheckLambdaProvisionedConcurrencyConfigDestroy, + CheckDestroy: testAccCheckProvisionedConcurrencyConfigDestroy, Steps: []resource.TestStep{ { Config: testAccProvisionedConcurrencyQualifierAliasNameConfig(rName), @@ -155,7 +155,7 @@ func TestAccLambdaProvisionedConcurrencyConfig_Qualifier_aliasName(t *testing.T) }) } -func testAccCheckLambdaProvisionedConcurrencyConfigDestroy(s *terraform.State) error { +func testAccCheckProvisionedConcurrencyConfigDestroy(s *terraform.State) error { conn := acctest.Provider.Meta().(*conns.AWSClient).LambdaConn for _, rs := range s.RootModule().Resources { diff --git a/website/docs/r/lambda_invocation.html.markdown b/website/docs/r/lambda_invocation.html.markdown new file mode 100644 index 00000000000..05e6c448cea --- /dev/null +++ b/website/docs/r/lambda_invocation.html.markdown @@ -0,0 +1,67 @@ +--- +subcategory: "Lambda" +layout: "aws" +page_title: "AWS: aws_lambda_invocation" +description: |- + Invoke AWS Lambda Function +--- + +# Resource: aws_lambda_invocation + +Use this resource to invoke a lambda function. The lambda function is invoked with the [RequestResponse](https://docs.aws.amazon.com/lambda/latest/dg/API_Invoke.html#API_Invoke_RequestSyntax) invocation type. + +~> **NOTE:** This resource _only_ invokes the function when the arguments call for a create or update. In other words, after an initial invocation on _apply_, if the arguments do not change, a subsequent _apply_ does not invoke the function again. To dynamically invoke the function, see the `triggers` example below. To always invoke a function on each _apply_, see the [`aws_lambda_invocation`](/docs/providers/aws/d/lambda_invocation.html) data source. + +## Example Usage + +```terraform +resource "aws_lambda_invocation" "example" { + function_name = aws_lambda_function.lambda_function_test.function_name + + input = jsonencode({ + key1 = "value1" + key2 = "value2" + }) +} + +output "result_entry" { + value = jsondecode(data.aws_lambda_invocation.example.result)["key1"] +} +``` + +### Dynamic Invocation Example Using Triggers + +```terraform +resource "aws_lambda_invocation" "example" { + function_name = aws_lambda_function.lambda_function_test.function_name + + triggers = { + redeployment = sha1(jsonencode([ + aws_lambda_function.example.environment + ])) + } + + input = jsonencode({ + key1 = "value1" + key2 = "value2" + }) +} +``` + +## Argument Reference + +The following arguments are required: + +* `function_name` - (Required) Name of the lambda function. +* `input` - (Required) JSON payload to the lambda function. + +The following arguments are optional: + +* `qualifier` - (Optional) Qualifier (i.e., version) of the lambda function. Defaults to `$LATEST`. +* `triggers` - (Optional) Map of arbitrary keys and values that, when changed, will trigger a re-invocation. To force a re-invocation without changing these keys/values, use the [`terraform taint` command](https://www.terraform.io/docs/commands/taint.html). + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `result` - String result of the lambda function invocation.