-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support Eventbridge Pipes parameters
* Add support for Eventbridge Enrichment Parameters * Add support for Eventbridge Target Parameters * Add support for Eventbridge Source Parameters * Due to the amount of parameters add unit tests to ensure the mapping is correct to the right struct value * Update docs to support parameters
- Loading branch information
1 parent
4c0c86b
commit bd781d4
Showing
15 changed files
with
9,644 additions
and
539 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
package pipes | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go-v2/aws" | ||
"github.com/aws/aws-sdk-go-v2/service/pipes/types" | ||
"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/flex" | ||
) | ||
|
||
var enrichment_parameters_schema = &schema.Schema{ | ||
Type: schema.TypeList, | ||
Optional: true, | ||
MaxItems: 1, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"input_template": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
ValidateFunc: validation.StringLenBetween(0, 8192), | ||
}, | ||
"http_parameters": { | ||
Type: schema.TypeList, | ||
Optional: true, | ||
MaxItems: 1, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"header": { | ||
Type: schema.TypeList, | ||
Optional: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"key": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: validation.StringLenBetween(0, 512), | ||
}, | ||
"value": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: validation.StringLenBetween(0, 512), | ||
}, | ||
}, | ||
}, | ||
}, | ||
"path_parameters": { | ||
Type: schema.TypeList, | ||
Optional: true, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
}, | ||
"query_string": { | ||
Type: schema.TypeList, | ||
Optional: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"key": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: validation.StringLenBetween(0, 512), | ||
}, | ||
"value": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: validation.StringLenBetween(0, 512), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
func expandEnrichmentParameters(config []interface{}) *types.PipeEnrichmentParameters { | ||
if len(config) == 0 { | ||
return nil | ||
} | ||
|
||
var parameters types.PipeEnrichmentParameters | ||
for _, c := range config { | ||
param := c.(map[string]interface{}) | ||
if val, ok := param["input_template"].(string); ok && val != "" { | ||
parameters.InputTemplate = aws.String(val) | ||
} | ||
if val, ok := param["http_parameters"]; ok { | ||
parameters.HttpParameters = expandEnrichmentHTTPParameters(val.([]interface{})) | ||
} | ||
} | ||
return ¶meters | ||
} | ||
|
||
func expandEnrichmentHTTPParameters(config []interface{}) *types.PipeEnrichmentHttpParameters { | ||
if len(config) == 0 { | ||
return nil | ||
} | ||
|
||
var parameters types.PipeEnrichmentHttpParameters | ||
for _, c := range config { | ||
param := c.(map[string]interface{}) | ||
if val, ok := param["path_parameters"]; ok { | ||
parameters.PathParameterValues = flex.ExpandStringValueList(val.([]interface{})) | ||
} | ||
|
||
if val, ok := param["header"]; ok { | ||
headers := map[string]string{} | ||
if values, ok := val.([]interface{}); ok { | ||
for _, v := range values { | ||
valueParam := v.(map[string]interface{}) | ||
|
||
if key, ok := valueParam["key"].(string); ok && key != "" { | ||
if value, ok := valueParam["value"].(string); ok && value != "" { | ||
headers[key] = value | ||
} | ||
} | ||
} | ||
} | ||
if len(headers) > 0 { | ||
parameters.HeaderParameters = headers | ||
} | ||
} | ||
|
||
if val, ok := param["query_string"]; ok { | ||
queryStrings := map[string]string{} | ||
if values, ok := val.([]interface{}); ok { | ||
for _, v := range values { | ||
valueParam := v.(map[string]interface{}) | ||
|
||
if key, ok := valueParam["key"].(string); ok && key != "" { | ||
if value, ok := valueParam["value"].(string); ok && value != "" { | ||
queryStrings[key] = value | ||
} | ||
} | ||
} | ||
} | ||
if len(queryStrings) > 0 { | ||
parameters.QueryStringParameters = queryStrings | ||
} | ||
} | ||
} | ||
return ¶meters | ||
} | ||
|
||
func flattenEnrichmentParameters(enrichmentParameters *types.PipeEnrichmentParameters) []map[string]interface{} { | ||
config := make(map[string]interface{}) | ||
|
||
if enrichmentParameters.InputTemplate != nil { | ||
config["input_template"] = *enrichmentParameters.InputTemplate | ||
} | ||
|
||
if enrichmentParameters.HttpParameters != nil { | ||
httpParameters := make(map[string]interface{}) | ||
|
||
var headerParameters []map[string]interface{} | ||
for key, value := range enrichmentParameters.HttpParameters.HeaderParameters { | ||
header := make(map[string]interface{}) | ||
header["key"] = key | ||
header["value"] = value | ||
headerParameters = append(headerParameters, header) | ||
} | ||
httpParameters["header"] = headerParameters | ||
|
||
var queryStringParameters []map[string]interface{} | ||
for key, value := range enrichmentParameters.HttpParameters.QueryStringParameters { | ||
queryString := make(map[string]interface{}) | ||
queryString["key"] = key | ||
queryString["value"] = value | ||
queryStringParameters = append(queryStringParameters, queryString) | ||
} | ||
httpParameters["query_string"] = queryStringParameters | ||
httpParameters["path_parameters"] = flex.FlattenStringValueList(enrichmentParameters.HttpParameters.PathParameterValues) | ||
|
||
config["http_parameters"] = []map[string]interface{}{httpParameters} | ||
} | ||
|
||
if len(config) == 0 { | ||
return nil | ||
} | ||
|
||
result := []map[string]interface{}{config} | ||
return result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
package pipes | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go-v2/service/pipes/types" | ||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_expandEnrichmentParameters(t *testing.T) { | ||
tests := map[string]struct { | ||
config map[string]interface{} | ||
expected *types.PipeEnrichmentParameters | ||
}{ | ||
"input_template config": { | ||
config: map[string]interface{}{ | ||
"input_template": "some template", | ||
}, | ||
expected: &types.PipeEnrichmentParameters{ | ||
InputTemplate: aws.String("some template"), | ||
}, | ||
}, | ||
"http_parameters config": { | ||
config: map[string]interface{}{ | ||
"http_parameters": []interface{}{ | ||
map[string]interface{}{ | ||
"path_parameters": []interface{}{"a", "b"}, | ||
"header": []interface{}{ | ||
map[string]interface{}{ | ||
"key": "key1", | ||
"value": "value1", | ||
}, | ||
map[string]interface{}{ | ||
"key": "key2", | ||
"value": "value2", | ||
}, | ||
}, | ||
"query_string": []interface{}{ | ||
map[string]interface{}{ | ||
"key": "key3", | ||
"value": "value3", | ||
}, | ||
map[string]interface{}{ | ||
"key": "key4", | ||
"value": "value4", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
expected: &types.PipeEnrichmentParameters{ | ||
HttpParameters: &types.PipeEnrichmentHttpParameters{ | ||
PathParameterValues: []string{"a", "b"}, | ||
HeaderParameters: map[string]string{ | ||
"key1": "value1", | ||
"key2": "value2", | ||
}, | ||
QueryStringParameters: map[string]string{ | ||
"key3": "value3", | ||
"key4": "value4", | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
for name, tt := range tests { | ||
t.Run(name, func(t *testing.T) { | ||
got := expandEnrichmentParameters([]interface{}{tt.config}) | ||
|
||
assert.Equal(t, tt.expected, got) | ||
}) | ||
} | ||
} | ||
|
||
func Test_flattenEnrichmentParameters(t *testing.T) { | ||
tests := map[string]struct { | ||
config *types.PipeEnrichmentParameters | ||
expected []map[string]interface{} | ||
}{ | ||
"input_template config": { | ||
config: &types.PipeEnrichmentParameters{ | ||
InputTemplate: aws.String("some template"), | ||
}, | ||
expected: []map[string]interface{}{ | ||
{ | ||
"input_template": "some template", | ||
}, | ||
}, | ||
}, | ||
"http_parameters config": { | ||
config: &types.PipeEnrichmentParameters{ | ||
HttpParameters: &types.PipeEnrichmentHttpParameters{ | ||
PathParameterValues: []string{"a", "b"}, | ||
HeaderParameters: map[string]string{ | ||
"key1": "value1", | ||
"key2": "value2", | ||
}, | ||
QueryStringParameters: map[string]string{ | ||
"key3": "value3", | ||
"key4": "value4", | ||
}, | ||
}, | ||
}, | ||
expected: []map[string]interface{}{ | ||
{ | ||
"http_parameters": []map[string]interface{}{ | ||
{ | ||
"path_parameters": []interface{}{"a", "b"}, | ||
"header": []map[string]interface{}{ | ||
{ | ||
"key": "key1", | ||
"value": "value1", | ||
}, | ||
{ | ||
"key": "key2", | ||
"value": "value2", | ||
}, | ||
}, | ||
"query_string": []map[string]interface{}{ | ||
{ | ||
"key": "key3", | ||
"value": "value3", | ||
}, | ||
{ | ||
"key": "key4", | ||
"value": "value4", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
for name, tt := range tests { | ||
t.Run(name, func(t *testing.T) { | ||
got := flattenEnrichmentParameters(tt.config) | ||
|
||
assert.Equal(t, tt.expected, got) | ||
}) | ||
} | ||
} |
Oops, something went wrong.