Skip to content

Commit

Permalink
eventgrid: re-introducing the config lookup, since the Hidden value…
Browse files Browse the repository at this point in the history
… is still returned from the API response
  • Loading branch information
tombuildsstuff committed Jul 25, 2023
1 parent 9163295 commit d763b23
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
12 changes: 10 additions & 2 deletions internal/services/eventgrid/event_subscription_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func expandEventSubscriptionDeliveryAttributeMappings(input []interface{}) []eve
return output
}

func flattenEventSubscriptionDeliveryAttributeMappings(input eventsubscriptions.EventSubscriptionDestination) []interface{} {
func flattenEventSubscriptionDeliveryAttributeMappings(input eventsubscriptions.EventSubscriptionDestination, mappingsFromState []eventsubscriptions.DeliveryAttributeMapping) []interface{} {
mappings := make([]eventsubscriptions.DeliveryAttributeMapping, 0)

if v, ok := input.(eventsubscriptions.AzureFunctionEventSubscriptionDestination); ok && v.Properties != nil && v.Properties.DeliveryAttributeMappings != nil {
Expand Down Expand Up @@ -298,7 +298,15 @@ func flattenEventSubscriptionDeliveryAttributeMappings(input eventsubscriptions.
secret = *val.Properties.IsSecret
}
if val.Properties.Value != nil {
value = *val.Properties.Value
// If this is a secret, the Azure API just returns a value of 'Hidden',
// so we need to lookup the value that was provided from config to return
for _, v := range mappingsFromState {
mapping, ok := v.(eventsubscriptions.StaticDeliveryAttributeMapping)
if ok && mapping.Name != nil && val.Name != nil && *mapping.Name == *val.Name && mapping.Properties != nil && mapping.Properties.Value != nil {
value = *mapping.Properties.Value
break
}
}
}
}
output = append(output, map[string]interface{}{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,8 @@ func resourceEventGridEventSubscriptionRead(d *pluginsdk.ResourceData, meta inte
return fmt.Errorf("setting `delivery_identity` for %s: %+v", *id, err)
}

deliveryMappings := flattenEventSubscriptionDeliveryAttributeMappings(destination)
existingMappingsFromState := expandEventSubscriptionDeliveryAttributeMappings(d.Get("delivery_property").([]interface{}))
deliveryMappings := flattenEventSubscriptionDeliveryAttributeMappings(destination, existingMappingsFromState)
if err := d.Set("delivery_property", deliveryMappings); err != nil {
return fmt.Errorf("setting `delivery_property` for %s: %+v", *id, err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,8 @@ func resourceEventGridSystemTopicEventSubscriptionRead(d *pluginsdk.ResourceData
return fmt.Errorf("setting `delivery_identity`: %+v", err)
}

deliveryMappings := flattenEventSubscriptionDeliveryAttributeMappings(destination)
existingMappingsFromState := expandEventSubscriptionDeliveryAttributeMappings(d.Get("delivery_property").([]interface{}))
deliveryMappings := flattenEventSubscriptionDeliveryAttributeMappings(destination, existingMappingsFromState)
if err := d.Set("delivery_property", deliveryMappings); err != nil {
return fmt.Errorf("setting `delivery_property` for %s: %+v", *id, err)
}
Expand Down

0 comments on commit d763b23

Please sign in to comment.