diff --git a/internal/services/eventgrid/event_subscription_funcs.go b/internal/services/eventgrid/event_subscription_funcs.go index 16fcba04eeb2..7f34ddf7f7cc 100644 --- a/internal/services/eventgrid/event_subscription_funcs.go +++ b/internal/services/eventgrid/event_subscription_funcs.go @@ -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 { @@ -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{}{ diff --git a/internal/services/eventgrid/eventgrid_event_subscription_resource.go b/internal/services/eventgrid/eventgrid_event_subscription_resource.go index 9dc8959ae442..c529c45f8749 100644 --- a/internal/services/eventgrid/eventgrid_event_subscription_resource.go +++ b/internal/services/eventgrid/eventgrid_event_subscription_resource.go @@ -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) } diff --git a/internal/services/eventgrid/eventgrid_system_topic_event_subscription_resource.go b/internal/services/eventgrid/eventgrid_system_topic_event_subscription_resource.go index 5607922976f1..389bfbdd812d 100644 --- a/internal/services/eventgrid/eventgrid_system_topic_event_subscription_resource.go +++ b/internal/services/eventgrid/eventgrid_system_topic_event_subscription_resource.go @@ -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) }