Skip to content

Commit bd781d4

Browse files
jordanfinnersJordan
authored and
Jordan
committed
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
1 parent 4c0c86b commit bd781d4

15 files changed

+9644
-539
lines changed

go.mod

+3
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ require (
6868
github.com/mitchellh/go-testing-interface v1.14.1
6969
github.com/pquerna/otp v1.4.0
7070
github.com/shopspring/decimal v1.3.1
71+
github.com/stretchr/testify v1.8.2
7172
golang.org/x/crypto v0.8.0
7273
golang.org/x/exp v0.0.0-20230206171751-46f607a40771
7374
golang.org/x/tools v0.6.0
@@ -98,6 +99,7 @@ require (
9899
github.com/bgentry/speakeasy v0.1.0 // indirect
99100
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc // indirect
100101
github.com/cloudflare/circl v1.3.2 // indirect
102+
github.com/davecgh/go-spew v1.1.1 // indirect
101103
github.com/evanphx/json-patch v0.5.2 // indirect
102104
github.com/fatih/color v1.14.1 // indirect
103105
github.com/golang/protobuf v1.5.2 // indirect
@@ -122,6 +124,7 @@ require (
122124
github.com/mitchellh/mapstructure v1.5.0 // indirect
123125
github.com/mitchellh/reflectwalk v1.0.2 // indirect
124126
github.com/oklog/run v1.1.0 // indirect
127+
github.com/pmezard/go-difflib v1.0.0 // indirect
125128
github.com/posener/complete v1.1.1 // indirect
126129
github.com/rogpeppe/go-internal v1.9.0 // indirect
127130
github.com/spf13/cast v1.3.1 // indirect

go.sum

+5
Original file line numberDiff line numberDiff line change
@@ -329,14 +329,19 @@ github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng=
329329
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
330330
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
331331
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
332+
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
333+
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
332334
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
333335
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
334336
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
335337
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
336338
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
337339
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
340+
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
338341
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
342+
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
339343
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
344+
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
340345
github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
341346
github.com/vmihailenco/msgpack v4.0.4+incompatible h1:dSLoQfGFAo3F6OoNhwUmLwVgaUXK79GlxNBwueZn0xI=
342347
github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=

internal/service/pipes/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
* AWS Provider: [Contribution Guide](https://hashicorp.github.io/terraform-provider-aws/#contribute)
44
* Service User Guide: [Amazon EventBridge Pipes](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-pipes.html)
55
* Service API Guide: [Welcome](https://docs.aws.amazon.com/eventbridge/latest/pipes-reference/Welcome.html)
6+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
package pipes
2+
3+
import (
4+
"github.com/aws/aws-sdk-go-v2/aws"
5+
"github.com/aws/aws-sdk-go-v2/service/pipes/types"
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
8+
"github.com/hashicorp/terraform-provider-aws/internal/flex"
9+
)
10+
11+
var enrichment_parameters_schema = &schema.Schema{
12+
Type: schema.TypeList,
13+
Optional: true,
14+
MaxItems: 1,
15+
Elem: &schema.Resource{
16+
Schema: map[string]*schema.Schema{
17+
"input_template": {
18+
Type: schema.TypeString,
19+
Optional: true,
20+
ValidateFunc: validation.StringLenBetween(0, 8192),
21+
},
22+
"http_parameters": {
23+
Type: schema.TypeList,
24+
Optional: true,
25+
MaxItems: 1,
26+
Elem: &schema.Resource{
27+
Schema: map[string]*schema.Schema{
28+
"header": {
29+
Type: schema.TypeList,
30+
Optional: true,
31+
Elem: &schema.Resource{
32+
Schema: map[string]*schema.Schema{
33+
"key": {
34+
Type: schema.TypeString,
35+
Required: true,
36+
ValidateFunc: validation.StringLenBetween(0, 512),
37+
},
38+
"value": {
39+
Type: schema.TypeString,
40+
Required: true,
41+
ValidateFunc: validation.StringLenBetween(0, 512),
42+
},
43+
},
44+
},
45+
},
46+
"path_parameters": {
47+
Type: schema.TypeList,
48+
Optional: true,
49+
Elem: &schema.Schema{
50+
Type: schema.TypeString,
51+
},
52+
},
53+
"query_string": {
54+
Type: schema.TypeList,
55+
Optional: true,
56+
Elem: &schema.Resource{
57+
Schema: map[string]*schema.Schema{
58+
"key": {
59+
Type: schema.TypeString,
60+
Required: true,
61+
ValidateFunc: validation.StringLenBetween(0, 512),
62+
},
63+
"value": {
64+
Type: schema.TypeString,
65+
Required: true,
66+
ValidateFunc: validation.StringLenBetween(0, 512),
67+
},
68+
},
69+
},
70+
},
71+
},
72+
},
73+
},
74+
},
75+
},
76+
}
77+
78+
func expandEnrichmentParameters(config []interface{}) *types.PipeEnrichmentParameters {
79+
if len(config) == 0 {
80+
return nil
81+
}
82+
83+
var parameters types.PipeEnrichmentParameters
84+
for _, c := range config {
85+
param := c.(map[string]interface{})
86+
if val, ok := param["input_template"].(string); ok && val != "" {
87+
parameters.InputTemplate = aws.String(val)
88+
}
89+
if val, ok := param["http_parameters"]; ok {
90+
parameters.HttpParameters = expandEnrichmentHTTPParameters(val.([]interface{}))
91+
}
92+
}
93+
return &parameters
94+
}
95+
96+
func expandEnrichmentHTTPParameters(config []interface{}) *types.PipeEnrichmentHttpParameters {
97+
if len(config) == 0 {
98+
return nil
99+
}
100+
101+
var parameters types.PipeEnrichmentHttpParameters
102+
for _, c := range config {
103+
param := c.(map[string]interface{})
104+
if val, ok := param["path_parameters"]; ok {
105+
parameters.PathParameterValues = flex.ExpandStringValueList(val.([]interface{}))
106+
}
107+
108+
if val, ok := param["header"]; ok {
109+
headers := map[string]string{}
110+
if values, ok := val.([]interface{}); ok {
111+
for _, v := range values {
112+
valueParam := v.(map[string]interface{})
113+
114+
if key, ok := valueParam["key"].(string); ok && key != "" {
115+
if value, ok := valueParam["value"].(string); ok && value != "" {
116+
headers[key] = value
117+
}
118+
}
119+
}
120+
}
121+
if len(headers) > 0 {
122+
parameters.HeaderParameters = headers
123+
}
124+
}
125+
126+
if val, ok := param["query_string"]; ok {
127+
queryStrings := map[string]string{}
128+
if values, ok := val.([]interface{}); ok {
129+
for _, v := range values {
130+
valueParam := v.(map[string]interface{})
131+
132+
if key, ok := valueParam["key"].(string); ok && key != "" {
133+
if value, ok := valueParam["value"].(string); ok && value != "" {
134+
queryStrings[key] = value
135+
}
136+
}
137+
}
138+
}
139+
if len(queryStrings) > 0 {
140+
parameters.QueryStringParameters = queryStrings
141+
}
142+
}
143+
}
144+
return &parameters
145+
}
146+
147+
func flattenEnrichmentParameters(enrichmentParameters *types.PipeEnrichmentParameters) []map[string]interface{} {
148+
config := make(map[string]interface{})
149+
150+
if enrichmentParameters.InputTemplate != nil {
151+
config["input_template"] = *enrichmentParameters.InputTemplate
152+
}
153+
154+
if enrichmentParameters.HttpParameters != nil {
155+
httpParameters := make(map[string]interface{})
156+
157+
var headerParameters []map[string]interface{}
158+
for key, value := range enrichmentParameters.HttpParameters.HeaderParameters {
159+
header := make(map[string]interface{})
160+
header["key"] = key
161+
header["value"] = value
162+
headerParameters = append(headerParameters, header)
163+
}
164+
httpParameters["header"] = headerParameters
165+
166+
var queryStringParameters []map[string]interface{}
167+
for key, value := range enrichmentParameters.HttpParameters.QueryStringParameters {
168+
queryString := make(map[string]interface{})
169+
queryString["key"] = key
170+
queryString["value"] = value
171+
queryStringParameters = append(queryStringParameters, queryString)
172+
}
173+
httpParameters["query_string"] = queryStringParameters
174+
httpParameters["path_parameters"] = flex.FlattenStringValueList(enrichmentParameters.HttpParameters.PathParameterValues)
175+
176+
config["http_parameters"] = []map[string]interface{}{httpParameters}
177+
}
178+
179+
if len(config) == 0 {
180+
return nil
181+
}
182+
183+
result := []map[string]interface{}{config}
184+
return result
185+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
package pipes
2+
3+
import (
4+
"testing"
5+
6+
"github.com/aws/aws-sdk-go-v2/service/pipes/types"
7+
"github.com/aws/aws-sdk-go/aws"
8+
"github.com/stretchr/testify/assert"
9+
)
10+
11+
func Test_expandEnrichmentParameters(t *testing.T) {
12+
tests := map[string]struct {
13+
config map[string]interface{}
14+
expected *types.PipeEnrichmentParameters
15+
}{
16+
"input_template config": {
17+
config: map[string]interface{}{
18+
"input_template": "some template",
19+
},
20+
expected: &types.PipeEnrichmentParameters{
21+
InputTemplate: aws.String("some template"),
22+
},
23+
},
24+
"http_parameters config": {
25+
config: map[string]interface{}{
26+
"http_parameters": []interface{}{
27+
map[string]interface{}{
28+
"path_parameters": []interface{}{"a", "b"},
29+
"header": []interface{}{
30+
map[string]interface{}{
31+
"key": "key1",
32+
"value": "value1",
33+
},
34+
map[string]interface{}{
35+
"key": "key2",
36+
"value": "value2",
37+
},
38+
},
39+
"query_string": []interface{}{
40+
map[string]interface{}{
41+
"key": "key3",
42+
"value": "value3",
43+
},
44+
map[string]interface{}{
45+
"key": "key4",
46+
"value": "value4",
47+
},
48+
},
49+
},
50+
},
51+
},
52+
expected: &types.PipeEnrichmentParameters{
53+
HttpParameters: &types.PipeEnrichmentHttpParameters{
54+
PathParameterValues: []string{"a", "b"},
55+
HeaderParameters: map[string]string{
56+
"key1": "value1",
57+
"key2": "value2",
58+
},
59+
QueryStringParameters: map[string]string{
60+
"key3": "value3",
61+
"key4": "value4",
62+
},
63+
},
64+
},
65+
},
66+
}
67+
for name, tt := range tests {
68+
t.Run(name, func(t *testing.T) {
69+
got := expandEnrichmentParameters([]interface{}{tt.config})
70+
71+
assert.Equal(t, tt.expected, got)
72+
})
73+
}
74+
}
75+
76+
func Test_flattenEnrichmentParameters(t *testing.T) {
77+
tests := map[string]struct {
78+
config *types.PipeEnrichmentParameters
79+
expected []map[string]interface{}
80+
}{
81+
"input_template config": {
82+
config: &types.PipeEnrichmentParameters{
83+
InputTemplate: aws.String("some template"),
84+
},
85+
expected: []map[string]interface{}{
86+
{
87+
"input_template": "some template",
88+
},
89+
},
90+
},
91+
"http_parameters config": {
92+
config: &types.PipeEnrichmentParameters{
93+
HttpParameters: &types.PipeEnrichmentHttpParameters{
94+
PathParameterValues: []string{"a", "b"},
95+
HeaderParameters: map[string]string{
96+
"key1": "value1",
97+
"key2": "value2",
98+
},
99+
QueryStringParameters: map[string]string{
100+
"key3": "value3",
101+
"key4": "value4",
102+
},
103+
},
104+
},
105+
expected: []map[string]interface{}{
106+
{
107+
"http_parameters": []map[string]interface{}{
108+
{
109+
"path_parameters": []interface{}{"a", "b"},
110+
"header": []map[string]interface{}{
111+
{
112+
"key": "key1",
113+
"value": "value1",
114+
},
115+
{
116+
"key": "key2",
117+
"value": "value2",
118+
},
119+
},
120+
"query_string": []map[string]interface{}{
121+
{
122+
"key": "key3",
123+
"value": "value3",
124+
},
125+
{
126+
"key": "key4",
127+
"value": "value4",
128+
},
129+
},
130+
},
131+
},
132+
},
133+
},
134+
},
135+
}
136+
for name, tt := range tests {
137+
t.Run(name, func(t *testing.T) {
138+
got := flattenEnrichmentParameters(tt.config)
139+
140+
assert.Equal(t, tt.expected, got)
141+
})
142+
}
143+
}

0 commit comments

Comments
 (0)