Skip to content

Commit

Permalink
Add option attributes to destination references (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
idc101 authored Feb 7, 2023
2 parents 4ff173b + 7a50c75 commit 3fac59b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions client/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ type DestinationReference struct {
Topic string `json:"topic,omitempty"`
Format *KafkaFormat `json:"format,omitempty"`
Mode string `json:"saveMode,omitempty"`
Options []Attribute `json:"options,omitempty"`
}

// Cluster ...
Expand Down
4 changes: 4 additions & 0 deletions client/resource_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ func attributeSchema() *schema.Resource {

func expandAttributes(d *schema.ResourceData) []Attribute {
drs := d.Get("attribute").(*schema.Set).List()
return expandAttributesFromInterfaces(drs)
}

func expandAttributesFromInterfaces(drs []interface{}) []Attribute {
res := make([]Attribute, 0, len(drs))
for _, dr := range drs {
val, _ := dr.(map[string]interface{})
Expand Down
12 changes: 12 additions & 0 deletions client/resource_feature_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@ func destinationSchema() *schema.Resource {
MaxItems: 1,
Elem: topicDestinationSchema(),
},
"option": {
Type: schema.TypeSet,
Optional: true,
Description: "Attributes (key value pairs) to attach to the object",
Elem: attributeSchema(),
},
},
}
}
Expand Down Expand Up @@ -536,8 +542,11 @@ func expandDestinationReferences(d *schema.ResourceData) ([]DestinationReference
val, _ := dr.(map[string]interface{})

destID, _ := strconv.Atoi(val["destination"].(string))
options := expandAttributesFromInterfaces(val["option"].(*schema.Set).List())

parsed := DestinationReference{
DestinationID: destID,
Options: options,
}

if folder, _ := expandSingleMap(val["folder"]); folder != nil {
Expand Down Expand Up @@ -589,6 +598,9 @@ func flattenDestinationReferences(destinations []DestinationReference) ([]map[st
for _, destination := range destinations {
single := make(map[string]interface{})
single["destination"] = strconv.Itoa(destination.DestinationID)
if destination.Options != nil {
single["option"] = flattenAttributes(destination.Options)
}

if destination.Type == "folder" {
folder := make(map[string]interface{})
Expand Down

0 comments on commit 3fac59b

Please sign in to comment.