@@ -11,23 +11,27 @@ import (
1111
1212 "github.com/hashicorp/go-azure-helpers/lang/pointer"
1313 "github.com/hashicorp/go-azure-helpers/lang/response"
14- "github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2023-12-15-preview/namespaces"
15- "github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2023-12-15-preview/namespacetopics"
14+ "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids"
15+ "github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2025-02-15/namespaces"
16+ "github.com/hashicorp/go-azure-sdk/resource-manager/eventgrid/2025-02-15/namespacetopics"
1617 "github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
1718 "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
1819 "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
1920)
2021
21- var _ sdk.ResourceWithUpdate = EventGridNamespaceTopicResource {}
22+ //go:generate go run ../../tools/generator-tests resourceidentity -resource-name eventgrid_namespace_topic -properties "name" -compare-values "subscription_id:eventgrid_namespace_id,resource_group_name:eventgrid_namespace_id,namespace_name:eventgrid_namespace_id"
23+
24+ var (
25+ _ sdk.ResourceWithUpdate = EventGridNamespaceTopicResource {}
26+ _ sdk.ResourceWithIdentity = EventGridNamespaceTopicResource {}
27+ )
2228
2329type EventGridNamespaceTopicResource struct {}
2430
2531type EventGridNamespaceTopicResourceModel struct {
2632 Name string `tfschema:"name"`
27- NamespaceId string `tfschema:"namespace_id "`
33+ EventgridNamespaceId string `tfschema:"eventgrid_namespace_id "`
2834 EventRetentionInDays int64 `tfschema:"event_retention_in_days"`
29- InputSchema string `tfschema:"input_schema"`
30- PublisherType string `tfschema:"publisher_type"`
3135}
3236
3337func (r EventGridNamespaceTopicResource ) Arguments () map [string ]* pluginsdk.Schema {
@@ -45,7 +49,7 @@ func (r EventGridNamespaceTopicResource) Arguments() map[string]*pluginsdk.Schem
4549 ),
4650 },
4751
48- "namespace_id " : {
52+ "eventgrid_namespace_id " : {
4953 Type : pluginsdk .TypeString ,
5054 Required : true ,
5155 ForceNew : true ,
@@ -58,24 +62,6 @@ func (r EventGridNamespaceTopicResource) Arguments() map[string]*pluginsdk.Schem
5862 Default : 7 ,
5963 ValidateFunc : validation .IntBetween (1 , 7 ),
6064 },
61-
62- "input_schema" : {
63- Type : pluginsdk .TypeString ,
64- Optional : true ,
65- Default : "CloudEventSchemaV1_0" ,
66- ValidateFunc : validation .StringInSlice ([]string {
67- "CloudEventSchemaV1_0" ,
68- }, false ),
69- },
70-
71- "publisher_type" : {
72- Type : pluginsdk .TypeString ,
73- Optional : true ,
74- Default : "Custom" ,
75- ValidateFunc : validation .StringInSlice ([]string {
76- "Custom" ,
77- }, false ),
78- },
7965 }
8066}
8167
@@ -99,23 +85,15 @@ func (r EventGridNamespaceTopicResource) Create() sdk.ResourceFunc {
9985
10086 var model EventGridNamespaceTopicResourceModel
10187 if err := metadata .Decode (& model ); err != nil {
102- return fmt .Errorf ("decoding %+v" , err )
88+ return fmt .Errorf ("decoding: %+v" , err )
10389 }
10490
105- subscriptionId := ""
106- namespaceName := ""
107- resourceGroupName := ""
108- if v := model .NamespaceId ; v != "" {
109- namespaceId , err := namespaces .ParseNamespaceID (v )
110- if err != nil {
111- return err
112- }
113- subscriptionId = namespaceId .SubscriptionId
114- namespaceName = namespaceId .NamespaceName
115- resourceGroupName = namespaceId .ResourceGroupName
91+ namespaceId , err := namespaces .ParseNamespaceID (model .EventgridNamespaceId )
92+ if err != nil {
93+ return err
11694 }
11795
118- id := namespacetopics .NewNamespaceTopicID (subscriptionId , resourceGroupName , namespaceName , model .Name )
96+ id := namespacetopics .NewNamespaceTopicID (namespaceId . SubscriptionId , namespaceId . ResourceGroupName , namespaceId . NamespaceName , model .Name )
11997
12098 existing , err := client .Get (ctx , id )
12199 if err != nil {
@@ -132,8 +110,8 @@ func (r EventGridNamespaceTopicResource) Create() sdk.ResourceFunc {
132110 Name : pointer .To (model .Name ),
133111 Properties : & namespacetopics.NamespaceTopicProperties {
134112 EventRetentionInDays : pointer .To (model .EventRetentionInDays ),
135- InputSchema : pointer .To (namespacetopics .EventInputSchema ( model . InputSchema ) ),
136- PublisherType : pointer .To (namespacetopics .PublisherType ( model . PublisherType ) ),
113+ InputSchema : pointer .To (namespacetopics .EventInputSchemaCloudEventSchemaVOneZero ),
114+ PublisherType : pointer .To (namespacetopics .PublisherTypeCustom ),
137115 },
138116 }
139117
@@ -142,8 +120,7 @@ func (r EventGridNamespaceTopicResource) Create() sdk.ResourceFunc {
142120 }
143121
144122 metadata .SetID (id )
145-
146- return nil
123+ return pluginsdk .SetResourceIdentityData (metadata .ResourceData , & id )
147124 },
148125 }
149126}
@@ -156,7 +133,7 @@ func (r EventGridNamespaceTopicResource) Update() sdk.ResourceFunc {
156133
157134 var model EventGridNamespaceTopicResourceModel
158135 if err := metadata .Decode (& model ); err != nil {
159- return fmt .Errorf ("decoding %+v" , err )
136+ return fmt .Errorf ("decoding: %+v" , err )
160137 }
161138
162139 id , err := namespacetopics .ParseNamespaceTopicID (metadata .ResourceData .Id ())
@@ -173,11 +150,9 @@ func (r EventGridNamespaceTopicResource) Update() sdk.ResourceFunc {
173150 }
174151
175152 if err = client .UpdateThenPoll (ctx , * id , payload ); err != nil {
176- return fmt .Errorf ("creating %s: %+v" , * id , err )
153+ return fmt .Errorf ("updating %s: %+v" , id , err )
177154 }
178155
179- metadata .SetID (id )
180-
181156 return nil
182157 },
183158 }
@@ -203,18 +178,20 @@ func (r EventGridNamespaceTopicResource) Read() sdk.ResourceFunc {
203178 }
204179
205180 state := EventGridNamespaceTopicResourceModel {
206- Name : id .TopicName ,
207- NamespaceId : namespacetopics .NewNamespaceID (id .SubscriptionId , id .ResourceGroupName , id .NamespaceName ).ID (),
181+ Name : id .TopicName ,
182+ EventgridNamespaceId : namespacetopics .NewNamespaceID (id .SubscriptionId , id .ResourceGroupName , id .NamespaceName ).ID (),
208183 }
209184
210185 if model := resp .Model ; model != nil {
211186 if props := model .Properties ; props != nil {
212- state .EventRetentionInDays = int64 (pointer .From (props .EventRetentionInDays ))
213- state .InputSchema = string (pointer .From (props .InputSchema ))
214- state .PublisherType = string (pointer .From (props .PublisherType ))
187+ state .EventRetentionInDays = pointer .From (props .EventRetentionInDays )
215188 }
216189 }
217190
191+ if err := pluginsdk .SetResourceIdentityData (metadata .ResourceData , id ); err != nil {
192+ return err
193+ }
194+
218195 return metadata .Encode (& state )
219196 },
220197 }
@@ -243,3 +220,7 @@ func (r EventGridNamespaceTopicResource) Delete() sdk.ResourceFunc {
243220func (r EventGridNamespaceTopicResource ) IDValidationFunc () pluginsdk.SchemaValidateFunc {
244221 return namespacetopics .ValidateNamespaceTopicID
245222}
223+
224+ func (r EventGridNamespaceTopicResource ) Identity () resourceids.ResourceId {
225+ return new (namespacetopics.NamespaceTopicId )
226+ }
0 commit comments