@@ -15,12 +15,15 @@ import (
1515 "github.com/hashicorp/go-azure-helpers/lang/response"
1616 "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
1717 "github.com/hashicorp/go-azure-helpers/resourcemanager/location"
18+ "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids"
1819 "github.com/hashicorp/go-azure-sdk/resource-manager/voiceservices/2023-04-03/communicationsgateways"
1920 "github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
2021 "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
2122 "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
2223)
2324
25+ //go:generate go run ../../tools/generator-tests resourceidentity -resource-name voice_services_communications_gateway -service-package-name voiceservices -properties "name,resource_group_name" -known-values "subscription_id:data.Subscriptions.Primary"
26+
2427type CommunicationsGatewayModel struct {
2528 Name string `tfschema:"name"`
2629 ResourceGroupName string `tfschema:"resource_group_name"`
@@ -50,9 +53,15 @@ type PrimaryRegionPropertiesModel struct{}
5053
5154type CommunicationsGatewayResource struct {}
5255
53- var _ sdk.ResourceWithUpdate = CommunicationsGatewayResource {}
56+ var (
57+ _ sdk.ResourceWithUpdate = CommunicationsGatewayResource {}
58+ _ sdk.ResourceWithCustomizeDiff = CommunicationsGatewayResource {}
59+ _ sdk.ResourceWithIdentity = CommunicationsGatewayResource {}
60+ )
5461
55- var _ sdk.ResourceWithCustomizeDiff = CommunicationsGatewayResource {}
62+ func (r CommunicationsGatewayResource ) Identity () resourceids.ResourceId {
63+ return & communicationsgateways.CommunicationsGatewayId {}
64+ }
5665
5766func (r CommunicationsGatewayResource ) ResourceType () string {
5867 return "azurerm_voice_services_communications_gateway"
@@ -296,6 +305,9 @@ func (r CommunicationsGatewayResource) Create() sdk.ResourceFunc {
296305 }
297306
298307 metadata .SetID (id )
308+ if err := pluginsdk .SetResourceIdentityData (metadata .ResourceData , & id ); err != nil {
309+ return err
310+ }
299311
300312 return nil
301313 },
@@ -410,63 +422,57 @@ func (r CommunicationsGatewayResource) Read() sdk.ResourceFunc {
410422 return fmt .Errorf ("retrieving %s: model was nil" , id )
411423 }
412424
413- state := CommunicationsGatewayModel {
414- Name : id .CommunicationsGatewayName ,
415- ResourceGroupName : id .ResourceGroupName ,
416- Location : location .Normalize (model .Location ),
417- }
425+ return r .flatten (metadata , id , model )
426+ },
427+ }
428+ }
418429
419- if properties := model .Properties ; properties != nil {
420- state .Connectivity = string (properties .Connectivity )
430+ func (r CommunicationsGatewayResource ) flatten (metadata sdk.ResourceMetaData , id * communicationsgateways.CommunicationsGatewayId , model * communicationsgateways.CommunicationsGateway ) error {
431+ state := CommunicationsGatewayModel {
432+ Name : id .CommunicationsGatewayName ,
433+ ResourceGroupName : id .ResourceGroupName ,
434+ Location : location .Normalize (model .Location ),
435+ }
421436
422- codecsValue := ""
423- if len (properties .Codecs ) > 0 {
424- codecsValue = string (properties .Codecs [0 ])
425- }
426- state .Codecs = codecsValue
437+ if properties := model .Properties ; properties != nil {
438+ state .Connectivity = string (properties .Connectivity )
427439
428- state .E911Type = properties .E911Type
440+ codecsValue := ""
441+ if len (properties .Codecs ) > 0 {
442+ codecsValue = string (properties .Codecs [0 ])
443+ }
444+ state .Codecs = codecsValue
429445
430- state .Platforms = flattenCommunicationsPlatformModel ( properties .Platforms )
446+ state .E911Type = properties .E911Type
431447
432- state .ServiceLocation = flattenServiceRegionPropertiesModel ( & properties .ServiceLocations )
448+ state .Platforms = flattenCommunicationsPlatformModel ( properties .Platforms )
433449
434- if properties .AutoGeneratedDomainNameLabelScope != nil {
435- state .AutoGeneratedDomainNameLabelScope = * properties .AutoGeneratedDomainNameLabelScope
436- }
450+ state .ServiceLocation = flattenServiceRegionPropertiesModel (& properties .ServiceLocations )
437451
438- if properties .ApiBridge != nil && * properties .ApiBridge != nil {
439- apiBridgeValue , err := json .Marshal (* properties .ApiBridge )
440- if err != nil {
441- return fmt .Errorf ("marshalling value for ApiBridge: %+v" , err )
442- }
443- state .ApiBridge = string (apiBridgeValue )
444- }
452+ state .AutoGeneratedDomainNameLabelScope = pointer .From (properties .AutoGeneratedDomainNameLabelScope )
445453
446- if properties .EmergencyDialStrings != nil {
447- state .EmergencyDialStrings = * properties .EmergencyDialStrings
448- }
454+ if properties .ApiBridge != nil && * properties .ApiBridge != nil {
455+ apiBridgeValue , err := json .Marshal (* properties .ApiBridge )
456+ if err != nil {
457+ return fmt .Errorf ("marshalling value for ApiBridge: %+v" , err )
458+ }
459+ state .ApiBridge = string (apiBridgeValue )
460+ }
449461
450- onPremMcpEnabled := false
451- if properties .OnPremMcpEnabled != nil {
452- onPremMcpEnabled = * properties .OnPremMcpEnabled
453- }
454- state .OnPremMcpEnabled = onPremMcpEnabled
462+ state .EmergencyDialStrings = pointer .From (properties .EmergencyDialStrings )
455463
456- v := ""
457- if properties .TeamsVoicemailPilotNumber != nil {
458- v = * properties .TeamsVoicemailPilotNumber
459- }
460- state .MicrosoftTeamsVoicemailPilotNumber = v
461- }
464+ state .OnPremMcpEnabled = pointer .From (properties .OnPremMcpEnabled )
462465
463- if model .Tags != nil {
464- state .Tags = * model .Tags
465- }
466+ state .MicrosoftTeamsVoicemailPilotNumber = pointer .From (properties .TeamsVoicemailPilotNumber )
467+ }
466468
467- return metadata .Encode (& state )
468- },
469+ state .Tags = pointer .From (model .Tags )
470+
471+ if err := pluginsdk .SetResourceIdentityData (metadata .ResourceData , id ); err != nil {
472+ return err
469473 }
474+
475+ return metadata .Encode (& state )
470476}
471477
472478func (r CommunicationsGatewayResource ) Delete () sdk.ResourceFunc {
0 commit comments