From 81902c0384dd19a493542734825ef31c8061ee4a Mon Sep 17 00:00:00 2001 From: Ruben Fonseca Date: Wed, 12 May 2021 10:19:33 +0200 Subject: [PATCH 01/11] Add support for API Gateway as an EventBrigde target. Fixes hashicorp/terraform-provider-aws#16624. --- aws/resource_aws_cloudwatch_event_target.go | 89 +++++++++++++++ ...source_aws_cloudwatch_event_target_test.go | 105 ++++++++++++++++++ .../r/cloudwatch_event_target.html.markdown | 40 +++++++ 3 files changed, 234 insertions(+) diff --git a/aws/resource_aws_cloudwatch_event_target.go b/aws/resource_aws_cloudwatch_event_target.go index 794341d91ac..fcaf934ed39 100644 --- a/aws/resource_aws_cloudwatch_event_target.go +++ b/aws/resource_aws_cloudwatch_event_target.go @@ -106,6 +106,31 @@ func resourceAwsCloudWatchEventTarget() *schema.Resource { }, }, + "http_target": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "header_parameters": { + Type: schema.TypeMap, + Optional: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "query_string_parameters": { + Type: schema.TypeMap, + Optional: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "path_parameter_values": { + Type: schema.TypeSet, + Optional: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + }, + }, + }, + "ecs_target": { Type: schema.TypeList, Optional: true, @@ -354,6 +379,12 @@ func resourceAwsCloudWatchEventTargetRead(d *schema.ResourceData, meta interface } } + if t.HttpParameters != nil { + if err := d.Set("http_target", flattenAwsCloudWatchEventTargetHttpParameters(t.HttpParameters)); err != nil { + return fmt.Errorf("Error setting http_target error: %w", err) + } + } + if t.EcsParameters != nil { if err := d.Set("ecs_target", flattenAwsCloudWatchEventTargetEcsParameters(t.EcsParameters)); err != nil { return fmt.Errorf("Error setting ecs_target error: %w", err) @@ -461,9 +492,15 @@ func buildPutTargetInputStruct(d *schema.ResourceData) *events.PutTargetsInput { if v, ok := d.GetOk("run_command_targets"); ok { e.RunCommandParameters = expandAwsCloudWatchEventTargetRunParameters(v.([]interface{})) } + if v, ok := d.GetOk("ecs_target"); ok { e.EcsParameters = expandAwsCloudWatchEventTargetEcsParameters(v.([]interface{})) } + + if v, ok := d.GetOk("http_target"); ok { + e.HttpParameters = expandAwsCloudWatchEventTargetHttpParameters(v.([]interface{})) + } + if v, ok := d.GetOk("batch_target"); ok { e.BatchParameters = expandAwsCloudWatchEventTargetBatchParameters(v.([]interface{})) } @@ -636,6 +673,36 @@ func expandAwsCloudWatchEventTargetSqsParameters(config []interface{}) *events.S return sqsParameters } +func expandAwsCloudWatchEventTargetHttpParameters(config []interface{}) *events.HttpParameters { + httpParameters := &events.HttpParameters{} + + headerParametersMap := map[string]*string{} + queryStringParametersMap := map[string]*string{} + pathParameterValues := []*string{} + + for _, c := range config { + param := c.(map[string]interface{}) + + headerParameters := param["header_parameters"].(map[string]interface{}) + for k, v := range headerParameters { + headerParametersMap[k] = aws.String(v.(string)) + } + + queryStringParameters := param["query_string_parameters"].(map[string]interface{}) + for k, v := range queryStringParameters { + queryStringParametersMap[k] = aws.String(v.(string)) + } + + pathParameters := expandStringSet(param["path_parameter_values"].(*schema.Set)) + pathParameterValues = append(pathParameterValues, pathParameters...) + } + + httpParameters.SetHeaderParameters(headerParametersMap) + httpParameters.SetQueryStringParameters(queryStringParametersMap) + httpParameters.SetPathParameterValues(pathParameterValues) + + return httpParameters +} func expandAwsCloudWatchEventTransformerParameters(config []interface{}) *events.InputTransformer { transformerParameters := &events.InputTransformer{} @@ -670,6 +737,7 @@ func flattenAwsCloudWatchEventTargetRunParameters(runCommand *events.RunCommandP return result } + func flattenAwsCloudWatchEventTargetEcsParameters(ecsParameters *events.EcsParameters) []map[string]interface{} { config := make(map[string]interface{}) if ecsParameters.Group != nil { @@ -732,6 +800,27 @@ func flattenAwsCloudWatchEventTargetSqsParameters(sqsParameters *events.SqsParam return result } +func flattenAwsCloudWatchEventTargetHttpParameters(httpParameters *events.HttpParameters) []map[string]interface{} { + config := make(map[string]interface{}) + + headerParametersMap := make(map[string]string) + for k, v := range httpParameters.HeaderParameters { + headerParametersMap[k] = aws.StringValue(v) + } + + queryStringParametersMap := make(map[string]string) + for k, v := range httpParameters.QueryStringParameters { + queryStringParametersMap[k] = aws.StringValue(v) + } + + config["header_parameters"] = headerParametersMap + config["path_parameter_values"] = flattenStringSet(httpParameters.PathParameterValues) + config["query_string_parameters"] = queryStringParametersMap + + result := []map[string]interface{}{config} + return result +} + func flattenAwsCloudWatchInputTransformer(inputTransformer *events.InputTransformer) []map[string]interface{} { config := make(map[string]interface{}) inputPathsMap := make(map[string]string) diff --git a/aws/resource_aws_cloudwatch_event_target_test.go b/aws/resource_aws_cloudwatch_event_target_test.go index 61f5fd99815..0ec9ae32391 100644 --- a/aws/resource_aws_cloudwatch_event_target_test.go +++ b/aws/resource_aws_cloudwatch_event_target_test.go @@ -380,6 +380,41 @@ func TestAccAWSCloudWatchEventTarget_ssmDocument(t *testing.T) { }) } +func TestAccAWSCloudWatchEventTarget_http(t *testing.T) { + resourceName := "aws_cloudwatch_event_target.test" + + var v events.Target + rName := acctest.RandomWithPrefix("tf_http_target") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ErrorCheck: testAccErrorCheck(t, cloudwatchevents.EndpointsID), + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSCloudWatchEventTargetDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSCloudWatchEventTargetConfigHttp(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckCloudWatchEventTargetExists(resourceName, &v), + resource.TestCheckResourceAttr(resourceName, "http_target.#", "1"), + resource.TestCheckResourceAttr(resourceName, "http_target.0.path_parameter_values.#", "0"), + resource.TestCheckResourceAttr(resourceName, "http_target.0.header_parameters.%", "1"), + resource.TestCheckResourceAttr(resourceName, "http_target.0.header_parameters.X-Test", "test"), + resource.TestCheckResourceAttr(resourceName, "http_target.0.query_string_parameters.%", "2"), + resource.TestCheckResourceAttr(resourceName, "http_target.0.query_string_parameters.Env", "test"), + resource.TestCheckResourceAttr(resourceName, "http_target.0.query_string_parameters.Path", "$.detail.path"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccAWSCloudWatchEventTargetImportStateIdFunc(resourceName), + ImportStateVerify: true, + }, + }, + }) +} + func TestAccAWSCloudWatchEventTarget_ecs(t *testing.T) { resourceName := "aws_cloudwatch_event_target.test" iamRoleResourceName := "aws_iam_role.test" @@ -1066,6 +1101,76 @@ data "aws_partition" "current" {} `, rName) } +func testAccAWSCloudWatchEventTargetConfigHttp(rName string) string { + return fmt.Sprintf(` +resource "aws_cloudwatch_event_rule" "test" { + name = %[1]q + description = "schedule_http_test" + + schedule_expression = "rate(5 minutes)" +} + +resource "aws_cloudwatch_event_target" "test" { + arn = "${aws_api_gateway_stage.test.execution_arn}/GET" + rule = aws_cloudwatch_event_rule.test.id + + http_target { + path_parameter_values = [] + query_string_parameters = { + Env = "test" + Path = "$.detail.path" + } + header_parameters = { + X-Test = "test" + } + } +} + +resource "aws_api_gateway_rest_api" "test" { + name = %[1]q + body = jsonencode({ + openapi = "3.0.1" + info = { + title = "example" + version = "1.0" + } + paths = { + "/" = { + get = { + x-amazon-apigateway-integration = { + httpMethod = "GET" + payloadFormatVersion = "1.0" + type = "HTTP_PROXY" + uri = "https://ip-ranges.amazonaws.com" + } + } + } + } + }) +} + +resource "aws_api_gateway_deployment" "test" { + rest_api_id = aws_api_gateway_rest_api.test.id + + triggers = { + redeployment = sha1(jsonencode(aws_api_gateway_rest_api.test.body)) + } + + lifecycle { + create_before_destroy = true + } +} + +resource "aws_api_gateway_stage" "test" { + deployment_id = aws_api_gateway_deployment.test.id + rest_api_id = aws_api_gateway_rest_api.test.id + stage_name = "test" +} + +data "aws_partition" "current" {} +`, rName) +} + func testAccAWSCloudWatchEventTargetConfigEcs(rName string) string { return fmt.Sprintf(` resource "aws_cloudwatch_event_rule" "test" { diff --git a/website/docs/r/cloudwatch_event_target.html.markdown b/website/docs/r/cloudwatch_event_target.html.markdown index 5deb49d7836..12ea0770e3b 100644 --- a/website/docs/r/cloudwatch_event_target.html.markdown +++ b/website/docs/r/cloudwatch_event_target.html.markdown @@ -237,6 +237,39 @@ DOC } ``` +## Example API Gateway target + +```terraform +resource "aws_cloudwatch_event_target" "example" { + arn = "${aws_api_gateway_stage.example.execution_arn}/GET" + rule = aws_cloudwatch_event_rule.example.id + + http_target { + query_string_parameters = { + Body = "$.detail.body" + } + header_parameters = { + Env = "Test" + } + } +} + +resource "aws_cloudwatch_event_rule" "example" { + # ... +} + +resource "aws_api_gateway_deployment" "example" { + rest_api_id = aws_api_gateway_rest_api.example.id + # ... +} + +resource "aws_api_gateway_stage" "example" { + rest_api_id = aws_api_gateway_rest_api.example.id + deployment_id = aws_api_gateway_deployment.example.id + # ... +} +``` + ## Example Input Transformer Usage - JSON Object ```terraform @@ -306,6 +339,7 @@ The following arguments are supported: * `batch_target` - (Optional) Parameters used when you are using the rule to invoke an Amazon Batch Job. Documented below. A maximum of 1 are allowed. * `kinesis_target` - (Optional) Parameters used when you are using the rule to invoke an Amazon Kinesis Stream. Documented below. A maximum of 1 are allowed. * `sqs_target` - (Optional) Parameters used when you are using the rule to invoke an Amazon SQS Queue. Documented below. A maximum of 1 are allowed. +* `http_target` - (Optional) Parameters used when you are using the rule to invoke an API Gateway REST endpoint. Documented below. A maxium of 1 are allowed. * `input_transformer` - (Optional) Parameters used when you are providing a custom input to a target based on certain event data. Conflicts with `input` and `input_path`. * `retry_policy` - (Optional) Parameters used when you are providing retry policies. Documented below. A maximum of 1 are allowed. * `dead_letter_config` - (Optional) Parameters used when you are providing a dead letter config. Documented below. A maximum of 1 are allowed. @@ -347,6 +381,12 @@ For more information, see [Task Networking](https://docs.aws.amazon.com/AmazonEC * `message_group_id` - (Optional) The FIFO message group ID to use as the target. +`http_target`support the following: + +* `path_parameter_values` - (Optional) The list of values that correspond sequentially to any path variables in your endpoint ARN (for example `arn:aws:execute-api:us-east-1:123456:myapi/*/POST/pets/*`). +* `query_string_parameters` - (Optional) Represents keys/values of query string parameters that are appended to the invoked endpoint. +* `header_parameters` - (Optional) Enables you to specify HTTP headers to add to the request. + `input_transformer` support the following: * `input_paths` - (Optional) Key value pairs specified in the form of JSONPath (for example, time = $.time) From 95445cd4fd2af93f824427f90b281b2a6b89da8c Mon Sep 17 00:00:00 2001 From: Ruben Fonseca Date: Wed, 12 May 2021 14:11:51 +0200 Subject: [PATCH 02/11] Fix typo in the documentation. Co-authored-by: Kit Ewbank --- website/docs/r/cloudwatch_event_target.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/cloudwatch_event_target.html.markdown b/website/docs/r/cloudwatch_event_target.html.markdown index 12ea0770e3b..338d594a878 100644 --- a/website/docs/r/cloudwatch_event_target.html.markdown +++ b/website/docs/r/cloudwatch_event_target.html.markdown @@ -339,7 +339,7 @@ The following arguments are supported: * `batch_target` - (Optional) Parameters used when you are using the rule to invoke an Amazon Batch Job. Documented below. A maximum of 1 are allowed. * `kinesis_target` - (Optional) Parameters used when you are using the rule to invoke an Amazon Kinesis Stream. Documented below. A maximum of 1 are allowed. * `sqs_target` - (Optional) Parameters used when you are using the rule to invoke an Amazon SQS Queue. Documented below. A maximum of 1 are allowed. -* `http_target` - (Optional) Parameters used when you are using the rule to invoke an API Gateway REST endpoint. Documented below. A maxium of 1 are allowed. +* `http_target` - (Optional) Parameters used when you are using the rule to invoke an API Gateway REST endpoint. Documented below. A maximum of 1 is allowed. * `input_transformer` - (Optional) Parameters used when you are providing a custom input to a target based on certain event data. Conflicts with `input` and `input_path`. * `retry_policy` - (Optional) Parameters used when you are providing retry policies. Documented below. A maximum of 1 are allowed. * `dead_letter_config` - (Optional) Parameters used when you are providing a dead letter config. Documented below. A maximum of 1 are allowed. From f5d961b47504c5388f31753a7aa9deb24dc9607e Mon Sep 17 00:00:00 2001 From: Ruben Fonseca Date: Wed, 12 May 2021 14:14:07 +0200 Subject: [PATCH 03/11] Fix formating on the documentation. --- website/docs/r/cloudwatch_event_target.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/cloudwatch_event_target.html.markdown b/website/docs/r/cloudwatch_event_target.html.markdown index 338d594a878..4bb47f3e22a 100644 --- a/website/docs/r/cloudwatch_event_target.html.markdown +++ b/website/docs/r/cloudwatch_event_target.html.markdown @@ -264,7 +264,7 @@ resource "aws_api_gateway_deployment" "example" { } resource "aws_api_gateway_stage" "example" { - rest_api_id = aws_api_gateway_rest_api.example.id + rest_api_id = aws_api_gateway_rest_api.example.id deployment_id = aws_api_gateway_deployment.example.id # ... } From 05c0b0041064cea04c12275509b479b95ac1163a Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 12 May 2021 10:00:21 -0400 Subject: [PATCH 04/11] Add CHANGELOG. --- .changelog/19337.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/19337.txt diff --git a/.changelog/19337.txt b/.changelog/19337.txt new file mode 100644 index 00000000000..07985056ae7 --- /dev/null +++ b/.changelog/19337.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_cloudwatch_event_target: Add `http_target` argument +``` \ No newline at end of file From fc1b28834e23ce9a6119a9968e4ea4e920cdb414 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 12 May 2021 10:02:20 -0400 Subject: [PATCH 05/11] r/aws_cloudwatch_event_target: Tidy up 'expandAwsCloudWatchEventTargetHttpParameters' and 'flattenAwsCloudWatchEventTargetHttpParameters'. --- aws/resource_aws_cloudwatch_event_target.go | 73 ++++++++++----------- 1 file changed, 34 insertions(+), 39 deletions(-) diff --git a/aws/resource_aws_cloudwatch_event_target.go b/aws/resource_aws_cloudwatch_event_target.go index fcaf934ed39..2a68c71244e 100644 --- a/aws/resource_aws_cloudwatch_event_target.go +++ b/aws/resource_aws_cloudwatch_event_target.go @@ -380,9 +380,11 @@ func resourceAwsCloudWatchEventTargetRead(d *schema.ResourceData, meta interface } if t.HttpParameters != nil { - if err := d.Set("http_target", flattenAwsCloudWatchEventTargetHttpParameters(t.HttpParameters)); err != nil { - return fmt.Errorf("Error setting http_target error: %w", err) + if err := d.Set("attribute_name", []interface{}{flattenAwsCloudWatchEventTargetHttpParameters(t.HttpParameters)}); err != nil { + return fmt.Errorf("error setting http_target: %w", err) } + } else { + d.Set("http_target", nil) } if t.EcsParameters != nil { @@ -497,8 +499,8 @@ func buildPutTargetInputStruct(d *schema.ResourceData) *events.PutTargetsInput { e.EcsParameters = expandAwsCloudWatchEventTargetEcsParameters(v.([]interface{})) } - if v, ok := d.GetOk("http_target"); ok { - e.HttpParameters = expandAwsCloudWatchEventTargetHttpParameters(v.([]interface{})) + if v, ok := d.GetOk("http_target"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil { + e.HttpParameters = expandAwsCloudWatchEventTargetHttpParameters(v.([]interface{})[0].(map[string]interface{})) } if v, ok := d.GetOk("batch_target"); ok { @@ -673,35 +675,27 @@ func expandAwsCloudWatchEventTargetSqsParameters(config []interface{}) *events.S return sqsParameters } -func expandAwsCloudWatchEventTargetHttpParameters(config []interface{}) *events.HttpParameters { - httpParameters := &events.HttpParameters{} - - headerParametersMap := map[string]*string{} - queryStringParametersMap := map[string]*string{} - pathParameterValues := []*string{} - for _, c := range config { - param := c.(map[string]interface{}) +func expandAwsCloudWatchEventTargetHttpParameters(tfMap map[string]interface{}) *events.HttpParameters { + if tfMap == nil { + return nil + } - headerParameters := param["header_parameters"].(map[string]interface{}) - for k, v := range headerParameters { - headerParametersMap[k] = aws.String(v.(string)) - } + apiObject := &events.HttpParameters{} - queryStringParameters := param["query_string_parameters"].(map[string]interface{}) - for k, v := range queryStringParameters { - queryStringParametersMap[k] = aws.String(v.(string)) - } + if v, ok := tfMap["header_parameters"].(map[string]interface{}); ok && len(v) > 0 { + apiObject.HeaderParameters = expandStringMap(v) + } - pathParameters := expandStringSet(param["path_parameter_values"].(*schema.Set)) - pathParameterValues = append(pathParameterValues, pathParameters...) + if v, ok := tfMap["path_parameter_values"].(*schema.Set); ok && v.Len() > 0 { + apiObject.PathParameterValues = expandStringSet(v) } - httpParameters.SetHeaderParameters(headerParametersMap) - httpParameters.SetQueryStringParameters(queryStringParametersMap) - httpParameters.SetPathParameterValues(pathParameterValues) + if v, ok := tfMap["query_string_parameters"].(map[string]interface{}); ok && len(v) > 0 { + apiObject.QueryStringParameters = expandStringMap(v) + } - return httpParameters + return apiObject } func expandAwsCloudWatchEventTransformerParameters(config []interface{}) *events.InputTransformer { @@ -800,25 +794,26 @@ func flattenAwsCloudWatchEventTargetSqsParameters(sqsParameters *events.SqsParam return result } -func flattenAwsCloudWatchEventTargetHttpParameters(httpParameters *events.HttpParameters) []map[string]interface{} { - config := make(map[string]interface{}) +func flattenAwsCloudWatchEventTargetHttpParameters(apiObject *events.HttpParameters) map[string]interface{} { + if apiObject == nil { + return nil + } - headerParametersMap := make(map[string]string) - for k, v := range httpParameters.HeaderParameters { - headerParametersMap[k] = aws.StringValue(v) + tfMap := map[string]interface{}{} + + if v := apiObject.HeaderParameters; v != nil { + tfMap["header_parameters"] = aws.StringValueMap(v) } - queryStringParametersMap := make(map[string]string) - for k, v := range httpParameters.QueryStringParameters { - queryStringParametersMap[k] = aws.StringValue(v) + if v := apiObject.PathParameterValues; v != nil { + tfMap["path_parameter_values"] = aws.StringValueSlice(v) } - config["header_parameters"] = headerParametersMap - config["path_parameter_values"] = flattenStringSet(httpParameters.PathParameterValues) - config["query_string_parameters"] = queryStringParametersMap + if v := apiObject.QueryStringParameters; v != nil { + tfMap["query_string_parameters"] = aws.StringValueMap(v) + } - result := []map[string]interface{}{config} - return result + return tfMap } func flattenAwsCloudWatchInputTransformer(inputTransformer *events.InputTransformer) []map[string]interface{} { From 27665944306b3b9bfe6ff0b08e5244537f80b349 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 12 May 2021 10:06:02 -0400 Subject: [PATCH 06/11] Correct double import of 'github.com/aws/aws-sdk-go/service/cloudwatchevents'. --- ...source_aws_cloudwatch_event_target_test.go | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/aws/resource_aws_cloudwatch_event_target_test.go b/aws/resource_aws_cloudwatch_event_target_test.go index 0ec9ae32391..d6d3ac83bf8 100644 --- a/aws/resource_aws_cloudwatch_event_target_test.go +++ b/aws/resource_aws_cloudwatch_event_target_test.go @@ -10,7 +10,6 @@ import ( "testing" "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/cloudwatchevents" events "github.com/aws/aws-sdk-go/service/cloudwatchevents" "github.com/hashicorp/go-multierror" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" @@ -120,7 +119,7 @@ func TestAccAWSCloudWatchEventTarget_basic(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - ErrorCheck: testAccErrorCheck(t, cloudwatchevents.EndpointsID), + ErrorCheck: testAccErrorCheck(t, events.EndpointsID), Providers: testAccProviders, CheckDestroy: testAccCheckAWSCloudWatchEventTargetDestroy, Steps: []resource.TestStep{ @@ -187,7 +186,7 @@ func TestAccAWSCloudWatchEventTarget_EventBusName(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - ErrorCheck: testAccErrorCheck(t, cloudwatchevents.EndpointsID), + ErrorCheck: testAccErrorCheck(t, events.EndpointsID), Providers: testAccProviders, CheckDestroy: testAccCheckAWSCloudWatchEventTargetDestroy, Steps: []resource.TestStep{ @@ -229,7 +228,7 @@ func TestAccAWSCloudWatchEventTarget_GeneratedTargetId(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - ErrorCheck: testAccErrorCheck(t, cloudwatchevents.EndpointsID), + ErrorCheck: testAccErrorCheck(t, events.EndpointsID), Providers: testAccProviders, CheckDestroy: testAccCheckAWSCloudWatchEventTargetDestroy, Steps: []resource.TestStep{ @@ -264,7 +263,7 @@ func TestAccAWSCloudWatchEventTarget_RetryPolicy_DeadLetterConfig(t *testing.T) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - ErrorCheck: testAccErrorCheck(t, cloudwatchevents.EndpointsID), + ErrorCheck: testAccErrorCheck(t, events.EndpointsID), Providers: testAccProviders, CheckDestroy: testAccCheckAWSCloudWatchEventTargetDestroy, Steps: []resource.TestStep{ @@ -297,7 +296,7 @@ func TestAccAWSCloudWatchEventTarget_full(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - ErrorCheck: testAccErrorCheck(t, cloudwatchevents.EndpointsID), + ErrorCheck: testAccErrorCheck(t, events.EndpointsID), Providers: testAccProviders, CheckDestroy: testAccCheckAWSCloudWatchEventTargetDestroy, Steps: []resource.TestStep{ @@ -333,7 +332,7 @@ func TestAccAWSCloudWatchEventTarget_disappears(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - ErrorCheck: testAccErrorCheck(t, cloudwatchevents.EndpointsID), + ErrorCheck: testAccErrorCheck(t, events.EndpointsID), Providers: testAccProviders, CheckDestroy: testAccCheckAWSCloudWatchEventTargetDestroy, Steps: []resource.TestStep{ @@ -356,7 +355,7 @@ func TestAccAWSCloudWatchEventTarget_ssmDocument(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - ErrorCheck: testAccErrorCheck(t, cloudwatchevents.EndpointsID), + ErrorCheck: testAccErrorCheck(t, events.EndpointsID), Providers: testAccProviders, CheckDestroy: testAccCheckAWSCloudWatchEventTargetDestroy, Steps: []resource.TestStep{ @@ -388,7 +387,7 @@ func TestAccAWSCloudWatchEventTarget_http(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - ErrorCheck: testAccErrorCheck(t, cloudwatchevents.EndpointsID), + ErrorCheck: testAccErrorCheck(t, events.EndpointsID), Providers: testAccProviders, CheckDestroy: testAccCheckAWSCloudWatchEventTargetDestroy, Steps: []resource.TestStep{ @@ -424,7 +423,7 @@ func TestAccAWSCloudWatchEventTarget_ecs(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - ErrorCheck: testAccErrorCheck(t, cloudwatchevents.EndpointsID), + ErrorCheck: testAccErrorCheck(t, events.EndpointsID), Providers: testAccProviders, CheckDestroy: testAccCheckAWSCloudWatchEventTargetDestroy, Steps: []resource.TestStep{ @@ -458,7 +457,7 @@ func TestAccAWSCloudWatchEventTarget_ecsWithBlankTaskCount(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - ErrorCheck: testAccErrorCheck(t, cloudwatchevents.EndpointsID), + ErrorCheck: testAccErrorCheck(t, events.EndpointsID), Providers: testAccProviders, CheckDestroy: testAccCheckAWSCloudWatchEventTargetDestroy, Steps: []resource.TestStep{ @@ -488,7 +487,7 @@ func TestAccAWSCloudWatchEventTarget_batch(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - ErrorCheck: testAccErrorCheck(t, cloudwatchevents.EndpointsID), + ErrorCheck: testAccErrorCheck(t, events.EndpointsID), Providers: testAccProviders, CheckDestroy: testAccCheckAWSCloudWatchEventTargetDestroy, Steps: []resource.TestStep{ @@ -518,7 +517,7 @@ func TestAccAWSCloudWatchEventTarget_kinesis(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - ErrorCheck: testAccErrorCheck(t, cloudwatchevents.EndpointsID), + ErrorCheck: testAccErrorCheck(t, events.EndpointsID), Providers: testAccProviders, CheckDestroy: testAccCheckAWSCloudWatchEventTargetDestroy, Steps: []resource.TestStep{ @@ -546,7 +545,7 @@ func TestAccAWSCloudWatchEventTarget_sqs(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - ErrorCheck: testAccErrorCheck(t, cloudwatchevents.EndpointsID), + ErrorCheck: testAccErrorCheck(t, events.EndpointsID), Providers: testAccProviders, CheckDestroy: testAccCheckAWSCloudWatchEventTargetDestroy, Steps: []resource.TestStep{ @@ -612,7 +611,7 @@ func TestAccAWSCloudWatchEventTarget_input_transformer(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - ErrorCheck: testAccErrorCheck(t, cloudwatchevents.EndpointsID), + ErrorCheck: testAccErrorCheck(t, events.EndpointsID), Providers: testAccProviders, CheckDestroy: testAccCheckAWSCloudWatchEventTargetDestroy, Steps: []resource.TestStep{ @@ -648,7 +647,7 @@ func TestAccAWSCloudWatchEventTarget_inputTransformerJsonString(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - ErrorCheck: testAccErrorCheck(t, cloudwatchevents.EndpointsID), + ErrorCheck: testAccErrorCheck(t, events.EndpointsID), Providers: testAccProviders, CheckDestroy: testAccCheckAWSCloudWatchEventTargetDestroy, Steps: []resource.TestStep{ @@ -680,7 +679,7 @@ func TestAccAWSCloudWatchEventTarget_PartnerEventBus(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, - ErrorCheck: testAccErrorCheck(t, cloudwatchevents.EndpointsID), + ErrorCheck: testAccErrorCheck(t, events.EndpointsID), Providers: testAccProviders, CheckDestroy: testAccCheckAWSCloudWatchEventTargetDestroy, Steps: []resource.TestStep{ From 415320403c817a055d1f8c4aa243451863b053af Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 12 May 2021 10:12:59 -0400 Subject: [PATCH 07/11] Fix terrafmt errors. --- ...source_aws_cloudwatch_event_target_test.go | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/aws/resource_aws_cloudwatch_event_target_test.go b/aws/resource_aws_cloudwatch_event_target_test.go index d6d3ac83bf8..ea7eda3b05c 100644 --- a/aws/resource_aws_cloudwatch_event_target_test.go +++ b/aws/resource_aws_cloudwatch_event_target_test.go @@ -1103,7 +1103,7 @@ data "aws_partition" "current" {} func testAccAWSCloudWatchEventTargetConfigHttp(rName string) string { return fmt.Sprintf(` resource "aws_cloudwatch_event_rule" "test" { - name = %[1]q + name = %[1]q description = "schedule_http_test" schedule_expression = "rate(5 minutes)" @@ -1116,7 +1116,7 @@ resource "aws_cloudwatch_event_target" "test" { http_target { path_parameter_values = [] query_string_parameters = { - Env = "test" + Env = "test" Path = "$.detail.path" } header_parameters = { @@ -1129,22 +1129,22 @@ resource "aws_api_gateway_rest_api" "test" { name = %[1]q body = jsonencode({ openapi = "3.0.1" - info = { - title = "example" - version = "1.0" - } - paths = { - "/" = { - get = { - x-amazon-apigateway-integration = { - httpMethod = "GET" - payloadFormatVersion = "1.0" - type = "HTTP_PROXY" - uri = "https://ip-ranges.amazonaws.com" - } - } - } - } + info = { + title = "example" + version = "1.0" + } + paths = { + "/" = { + get = { + x-amazon-apigateway-integration = { + httpMethod = "GET" + payloadFormatVersion = "1.0" + type = "HTTP_PROXY" + uri = "https://ip-ranges.amazonaws.com" + } + } + } + } }) } From 05e8b0e31c0dcc842150afed2b0af04d699b42a8 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 12 May 2021 10:13:49 -0400 Subject: [PATCH 08/11] Add explicit check for no 'http_target' in 'TestAccAWSCloudWatchEventTarget_basic'. --- aws/resource_aws_cloudwatch_event_target_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/aws/resource_aws_cloudwatch_event_target_test.go b/aws/resource_aws_cloudwatch_event_target_test.go index ea7eda3b05c..e3e09766e08 100644 --- a/aws/resource_aws_cloudwatch_event_target_test.go +++ b/aws/resource_aws_cloudwatch_event_target_test.go @@ -136,8 +136,9 @@ func TestAccAWSCloudWatchEventTarget_basic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "input_path", ""), resource.TestCheckResourceAttr(resourceName, "role_arn", ""), resource.TestCheckResourceAttr(resourceName, "run_command_targets.#", "0"), - resource.TestCheckResourceAttr(resourceName, "ecs_target.#", "0"), resource.TestCheckResourceAttr(resourceName, "batch_target.#", "0"), + resource.TestCheckResourceAttr(resourceName, "ecs_target.#", "0"), + resource.TestCheckResourceAttr(resourceName, "http_target.#", "0"), resource.TestCheckResourceAttr(resourceName, "kinesis_target.#", "0"), resource.TestCheckResourceAttr(resourceName, "sqs_target.#", "0"), resource.TestCheckResourceAttr(resourceName, "input_transformer.#", "0"), From e2675c2ce89142963889e4c86174159539e4a595 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 12 May 2021 10:18:41 -0400 Subject: [PATCH 09/11] Fix typo. --- aws/resource_aws_cloudwatch_event_target.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws/resource_aws_cloudwatch_event_target.go b/aws/resource_aws_cloudwatch_event_target.go index 2a68c71244e..d4c60d91cb8 100644 --- a/aws/resource_aws_cloudwatch_event_target.go +++ b/aws/resource_aws_cloudwatch_event_target.go @@ -380,7 +380,7 @@ func resourceAwsCloudWatchEventTargetRead(d *schema.ResourceData, meta interface } if t.HttpParameters != nil { - if err := d.Set("attribute_name", []interface{}{flattenAwsCloudWatchEventTargetHttpParameters(t.HttpParameters)}); err != nil { + if err := d.Set("http_target", []interface{}{flattenAwsCloudWatchEventTargetHttpParameters(t.HttpParameters)}); err != nil { return fmt.Errorf("error setting http_target: %w", err) } } else { From d19bb15cc36dbad6625b5e8629755a21b6878427 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 12 May 2021 10:29:24 -0400 Subject: [PATCH 10/11] Really fix the terrafmt errors. --- aws/resource_aws_cloudwatch_event_target_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/aws/resource_aws_cloudwatch_event_target_test.go b/aws/resource_aws_cloudwatch_event_target_test.go index e3e09766e08..204239733a7 100644 --- a/aws/resource_aws_cloudwatch_event_target_test.go +++ b/aws/resource_aws_cloudwatch_event_target_test.go @@ -1153,7 +1153,7 @@ resource "aws_api_gateway_deployment" "test" { rest_api_id = aws_api_gateway_rest_api.test.id triggers = { - redeployment = sha1(jsonencode(aws_api_gateway_rest_api.test.body)) + redeployment = sha1(jsonencode(aws_api_gateway_rest_api.test.body)) } lifecycle { @@ -1163,8 +1163,8 @@ resource "aws_api_gateway_deployment" "test" { resource "aws_api_gateway_stage" "test" { deployment_id = aws_api_gateway_deployment.test.id - rest_api_id = aws_api_gateway_rest_api.test.id - stage_name = "test" + rest_api_id = aws_api_gateway_rest_api.test.id + stage_name = "test" } data "aws_partition" "current" {} From 4363adf5ca43d7ce8cf0ea88ab565b8575959733 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 12 May 2021 10:32:25 -0400 Subject: [PATCH 11/11] Really, really fix the terrafmt errors. --- aws/resource_aws_cloudwatch_event_target_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws/resource_aws_cloudwatch_event_target_test.go b/aws/resource_aws_cloudwatch_event_target_test.go index 204239733a7..987a4b7eaf3 100644 --- a/aws/resource_aws_cloudwatch_event_target_test.go +++ b/aws/resource_aws_cloudwatch_event_target_test.go @@ -1131,7 +1131,7 @@ resource "aws_api_gateway_rest_api" "test" { body = jsonencode({ openapi = "3.0.1" info = { - title = "example" + title = "example" version = "1.0" } paths = {