Skip to content

Commit

Permalink
Merge pull request #19337 from rubenfonseca/16624
Browse files Browse the repository at this point in the history
Add support for API Gateway as an EventBrigde target
  • Loading branch information
ewbankkit authored May 12, 2021
2 parents f8fd761 + 4363adf commit c7e8bdc
Show file tree
Hide file tree
Showing 4 changed files with 249 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .changelog/19337.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_cloudwatch_event_target: Add `http_target` argument
```
84 changes: 84 additions & 0 deletions aws/resource_aws_cloudwatch_event_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -354,6 +379,14 @@ func resourceAwsCloudWatchEventTargetRead(d *schema.ResourceData, meta interface
}
}

if t.HttpParameters != nil {
if err := d.Set("http_target", []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 {
if err := d.Set("ecs_target", flattenAwsCloudWatchEventTargetEcsParameters(t.EcsParameters)); err != nil {
return fmt.Errorf("Error setting ecs_target error: %w", err)
Expand Down Expand Up @@ -461,9 +494,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 && 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 {
e.BatchParameters = expandAwsCloudWatchEventTargetBatchParameters(v.([]interface{}))
}
Expand Down Expand Up @@ -637,6 +676,28 @@ func expandAwsCloudWatchEventTargetSqsParameters(config []interface{}) *events.S
return sqsParameters
}

func expandAwsCloudWatchEventTargetHttpParameters(tfMap map[string]interface{}) *events.HttpParameters {
if tfMap == nil {
return nil
}

apiObject := &events.HttpParameters{}

if v, ok := tfMap["header_parameters"].(map[string]interface{}); ok && len(v) > 0 {
apiObject.HeaderParameters = expandStringMap(v)
}

if v, ok := tfMap["path_parameter_values"].(*schema.Set); ok && v.Len() > 0 {
apiObject.PathParameterValues = expandStringSet(v)
}

if v, ok := tfMap["query_string_parameters"].(map[string]interface{}); ok && len(v) > 0 {
apiObject.QueryStringParameters = expandStringMap(v)
}

return apiObject
}

func expandAwsCloudWatchEventTransformerParameters(config []interface{}) *events.InputTransformer {
transformerParameters := &events.InputTransformer{}

Expand Down Expand Up @@ -670,6 +731,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 {
Expand Down Expand Up @@ -732,6 +794,28 @@ func flattenAwsCloudWatchEventTargetSqsParameters(sqsParameters *events.SqsParam
return result
}

func flattenAwsCloudWatchEventTargetHttpParameters(apiObject *events.HttpParameters) map[string]interface{} {
if apiObject == nil {
return nil
}

tfMap := map[string]interface{}{}

if v := apiObject.HeaderParameters; v != nil {
tfMap["header_parameters"] = aws.StringValueMap(v)
}

if v := apiObject.PathParameterValues; v != nil {
tfMap["path_parameter_values"] = aws.StringValueSlice(v)
}

if v := apiObject.QueryStringParameters; v != nil {
tfMap["query_string_parameters"] = aws.StringValueMap(v)
}

return tfMap
}

func flattenAwsCloudWatchInputTransformer(inputTransformer *events.InputTransformer) []map[string]interface{} {
config := make(map[string]interface{})
inputPathsMap := make(map[string]string)
Expand Down
Loading

0 comments on commit c7e8bdc

Please sign in to comment.