|
| 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 | +func enrichmentParametersSchema() *schema.Schema { |
| 12 | + return &schema.Schema{ |
| 13 | + Type: schema.TypeList, |
| 14 | + Optional: true, |
| 15 | + MaxItems: 1, |
| 16 | + Elem: &schema.Resource{ |
| 17 | + Schema: map[string]*schema.Schema{ |
| 18 | + "http_parameters": { |
| 19 | + Type: schema.TypeList, |
| 20 | + Optional: true, |
| 21 | + MaxItems: 1, |
| 22 | + Elem: &schema.Resource{ |
| 23 | + Schema: map[string]*schema.Schema{ |
| 24 | + "header_parameters": { |
| 25 | + Type: schema.TypeMap, |
| 26 | + Optional: true, |
| 27 | + Elem: &schema.Schema{Type: schema.TypeString}, |
| 28 | + }, |
| 29 | + "path_parameter_values": { |
| 30 | + Type: schema.TypeList, |
| 31 | + Optional: true, |
| 32 | + MaxItems: 1, |
| 33 | + Elem: &schema.Schema{ |
| 34 | + Type: schema.TypeString, |
| 35 | + }, |
| 36 | + }, |
| 37 | + "query_string_parameters": { |
| 38 | + Type: schema.TypeMap, |
| 39 | + Optional: true, |
| 40 | + Elem: &schema.Schema{Type: schema.TypeString}, |
| 41 | + }, |
| 42 | + }, |
| 43 | + }, |
| 44 | + }, |
| 45 | + "input_template": { |
| 46 | + Type: schema.TypeString, |
| 47 | + Optional: true, |
| 48 | + ValidateFunc: validation.StringLenBetween(0, 8192), |
| 49 | + }, |
| 50 | + }, |
| 51 | + }, |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +func expandPipeEnrichmentParameters(tfMap map[string]interface{}) *types.PipeEnrichmentParameters { |
| 56 | + if tfMap == nil { |
| 57 | + return nil |
| 58 | + } |
| 59 | + |
| 60 | + apiObject := &types.PipeEnrichmentParameters{} |
| 61 | + |
| 62 | + if v, ok := tfMap["http_parameters"].([]interface{}); ok && len(v) > 0 && v[0] != nil { |
| 63 | + apiObject.HttpParameters = expandPipeEnrichmentHTTPParameters(v[0].(map[string]interface{})) |
| 64 | + } |
| 65 | + |
| 66 | + if v, ok := tfMap["input_template"].(string); ok && v != "" { |
| 67 | + apiObject.InputTemplate = aws.String(v) |
| 68 | + } |
| 69 | + |
| 70 | + return apiObject |
| 71 | +} |
| 72 | + |
| 73 | +func expandPipeEnrichmentHTTPParameters(tfMap map[string]interface{}) *types.PipeEnrichmentHttpParameters { |
| 74 | + if tfMap == nil { |
| 75 | + return nil |
| 76 | + } |
| 77 | + |
| 78 | + apiObject := &types.PipeEnrichmentHttpParameters{} |
| 79 | + |
| 80 | + if v, ok := tfMap["header_parameters"].(map[string]interface{}); ok && len(v) > 0 { |
| 81 | + apiObject.HeaderParameters = flex.ExpandStringValueMap(v) |
| 82 | + } |
| 83 | + |
| 84 | + if v, ok := tfMap["path_parameter_values"].([]interface{}); ok && len(v) > 0 { |
| 85 | + apiObject.PathParameterValues = flex.ExpandStringValueList(v) |
| 86 | + } |
| 87 | + |
| 88 | + if v, ok := tfMap["query_string_parameters"].(map[string]interface{}); ok && len(v) > 0 { |
| 89 | + apiObject.QueryStringParameters = flex.ExpandStringValueMap(v) |
| 90 | + } |
| 91 | + |
| 92 | + return apiObject |
| 93 | +} |
| 94 | + |
| 95 | +func flattenPipeEnrichmentParameters(apiObject *types.PipeEnrichmentParameters) map[string]interface{} { |
| 96 | + if apiObject == nil { |
| 97 | + return nil |
| 98 | + } |
| 99 | + |
| 100 | + tfMap := map[string]interface{}{} |
| 101 | + |
| 102 | + if v := apiObject.HttpParameters; v != nil { |
| 103 | + tfMap["http_parameters"] = []interface{}{flattenPipeEnrichmentHTTPParameters(v)} |
| 104 | + } |
| 105 | + |
| 106 | + if v := apiObject.InputTemplate; v != nil { |
| 107 | + tfMap["input_template"] = aws.ToString(v) |
| 108 | + } |
| 109 | + |
| 110 | + return tfMap |
| 111 | +} |
| 112 | + |
| 113 | +func flattenPipeEnrichmentHTTPParameters(apiObject *types.PipeEnrichmentHttpParameters) map[string]interface{} { |
| 114 | + if apiObject == nil { |
| 115 | + return nil |
| 116 | + } |
| 117 | + |
| 118 | + tfMap := map[string]interface{}{} |
| 119 | + |
| 120 | + if v := apiObject.HeaderParameters; v != nil { |
| 121 | + tfMap["header_parameters"] = v |
| 122 | + } |
| 123 | + |
| 124 | + if v := apiObject.PathParameterValues; v != nil { |
| 125 | + tfMap["path_parameter_values"] = v |
| 126 | + } |
| 127 | + |
| 128 | + if v := apiObject.QueryStringParameters; v != nil { |
| 129 | + tfMap["query_string_parameters"] = v |
| 130 | + } |
| 131 | + |
| 132 | + return tfMap |
| 133 | +} |
0 commit comments