@@ -134,64 +134,64 @@ func (r *referenceTableResource) Schema(_ context.Context, _ resource.SchemaRequ
134134 Description : "Cloud storage access configuration. Exactly one of aws_detail, gcp_detail, or azure_detail must be specified." ,
135135 Blocks : map [string ]schema.Block {
136136 "aws_detail" : schema.SingleNestedBlock {
137- Description : "AWS S3 access configuration." ,
137+ Description : "AWS S3 access configuration. Required when source is S3. " ,
138138 Attributes : map [string ]schema.Attribute {
139139 "aws_account_id" : schema.StringAttribute {
140- Required : true ,
140+ Optional : true ,
141141 Description : "The ID of the AWS account." ,
142142 },
143143 "aws_bucket_name" : schema.StringAttribute {
144- Required : true ,
144+ Optional : true ,
145145 Description : "The name of the Amazon S3 bucket." ,
146146 },
147147 "file_path" : schema.StringAttribute {
148- Required : true ,
148+ Optional : true ,
149149 Description : "The relative file path from the S3 bucket root to the CSV file." ,
150150 },
151151 },
152152 },
153153 "gcp_detail" : schema.SingleNestedBlock {
154- Description : "Google Cloud Storage access configuration." ,
154+ Description : "Google Cloud Storage access configuration. Required when source is GCS. " ,
155155 Attributes : map [string ]schema.Attribute {
156156 "gcp_project_id" : schema.StringAttribute {
157- Required : true ,
157+ Optional : true ,
158158 Description : "The ID of the GCP project." ,
159159 },
160160 "gcp_bucket_name" : schema.StringAttribute {
161- Required : true ,
161+ Optional : true ,
162162 Description : "The name of the GCP bucket." ,
163163 },
164164 "file_path" : schema.StringAttribute {
165- Required : true ,
165+ Optional : true ,
166166 Description : "The relative file path from the GCS bucket root to the CSV file." ,
167167 },
168168 "gcp_service_account_email" : schema.StringAttribute {
169- Required : true ,
169+ Optional : true ,
170170 Description : "The email of the GCP service account used to access the bucket." ,
171171 },
172172 },
173173 },
174174 "azure_detail" : schema.SingleNestedBlock {
175- Description : "Azure Blob Storage access configuration." ,
175+ Description : "Azure Blob Storage access configuration. Required when source is AZURE. " ,
176176 Attributes : map [string ]schema.Attribute {
177177 "azure_tenant_id" : schema.StringAttribute {
178- Required : true ,
178+ Optional : true ,
179179 Description : "The ID of the Azure tenant." ,
180180 },
181181 "azure_client_id" : schema.StringAttribute {
182- Required : true ,
182+ Optional : true ,
183183 Description : "The Azure client ID (application ID)." ,
184184 },
185185 "azure_storage_account_name" : schema.StringAttribute {
186- Required : true ,
186+ Optional : true ,
187187 Description : "The name of the Azure storage account." ,
188188 },
189189 "azure_container_name" : schema.StringAttribute {
190- Required : true ,
190+ Optional : true ,
191191 Description : "The name of the Azure container." ,
192192 },
193193 "file_path" : schema.StringAttribute {
194- Required : true ,
194+ Optional : true ,
195195 Description : "The relative file path from the Azure container root to the CSV file." ,
196196 },
197197 },
@@ -279,15 +279,64 @@ func (r *referenceTableResource) Create(ctx context.Context, request resource.Cr
279279 return
280280 }
281281
282- resp , _ , err := r .Api .CreateReferenceTable (r .Auth , * body )
282+ resp , httpResp , err := r .Api .CreateReferenceTable (r .Auth , * body )
283283 if err != nil {
284- response .Diagnostics .Append (utils .FrameworkErrorDiag (err , "error retrieving ReferenceTable" ))
284+ response .Diagnostics .Append (utils .FrameworkErrorDiag (err , "error creating ReferenceTable" ))
285285 return
286286 }
287287 if err := utils .CheckForUnparsed (resp ); err != nil {
288288 response .Diagnostics .AddError ("response contains unparsedObject" , err .Error ())
289289 return
290290 }
291+
292+ // If the create response doesn't include data, fetch it with a list+filter request
293+ if resp .Data == nil {
294+ if httpResp != nil && httpResp .StatusCode == 201 {
295+ // Table was created successfully, but response was empty - list tables and find by exact name
296+ tableName := state .TableName .ValueString ()
297+ listResp , _ , listErr := r .Api .ListTables (r .Auth )
298+ if listErr != nil {
299+ response .Diagnostics .Append (utils .FrameworkErrorDiag (listErr , "table created but error listing tables" ))
300+ return
301+ }
302+
303+ // Find the table by exact name match
304+ var foundTable * datadogV2.TableResultV2Data
305+ if listResp .Data != nil {
306+ for _ , table := range listResp .Data {
307+ if attrs , ok := table .GetAttributesOk (); ok {
308+ if name , nameOk := attrs .GetTableNameOk (); nameOk && * name == tableName {
309+ tableCopy := table
310+ foundTable = & tableCopy
311+ break
312+ }
313+ }
314+ }
315+ }
316+
317+ if foundTable == nil {
318+ response .Diagnostics .AddError ("API Error" , fmt .Sprintf ("Table %s was created but not found in list" , tableName ))
319+ return
320+ }
321+
322+ // Get the full table details by ID
323+ tableID := foundTable .GetId ()
324+ getResp , _ , getErr := r .Api .GetTable (r .Auth , tableID )
325+ if getErr != nil {
326+ response .Diagnostics .Append (utils .FrameworkErrorDiag (getErr , fmt .Sprintf ("table created but error fetching details for ID %s" , tableID )))
327+ return
328+ }
329+ resp = getResp
330+ } else {
331+ statusCode := 0
332+ if httpResp != nil {
333+ statusCode = httpResp .StatusCode
334+ }
335+ response .Diagnostics .AddError ("API Error" , fmt .Sprintf ("CreateReferenceTable returned an empty response (HTTP %d)." , statusCode ))
336+ return
337+ }
338+ }
339+
291340 r .updateState (ctx , & state , & resp )
292341
293342 // Save data into Terraform state
@@ -339,6 +388,11 @@ func (r *referenceTableResource) Delete(ctx context.Context, request resource.De
339388}
340389
341390func (r * referenceTableResource ) updateState (ctx context.Context , state * referenceTableModel , resp * datadogV2.TableResultV2 ) {
391+ // Check if Data is present
392+ if resp == nil || resp .Data == nil {
393+ return
394+ }
395+
342396 attributes := resp .Data .GetAttributes ()
343397
344398 state .ID = types .StringValue (* resp .GetData ().Id )
@@ -568,7 +622,7 @@ func (r *referenceTableResource) buildReferenceTableRequestBody(ctx context.Cont
568622 }
569623
570624 req := datadogV2 .NewCreateTableRequestWithDefaults ()
571- req .Data = datadogV2 .NewCreateTableRequestDataWithDefaults ( )
625+ req .Data = datadogV2 .NewCreateTableRequestData ( datadogV2 . CREATETABLEREQUESTDATATYPE_REFERENCE_TABLE )
572626 req .Data .SetAttributes (* attributes )
573627
574628 return req , diags
@@ -664,7 +718,7 @@ func (r *referenceTableResource) buildReferenceTableUpdateRequestBody(ctx contex
664718 }
665719
666720 req := datadogV2 .NewPatchTableRequestWithDefaults ()
667- req .Data = datadogV2 .NewPatchTableRequestDataWithDefaults ( )
721+ req .Data = datadogV2 .NewPatchTableRequestData ( datadogV2 . PATCHTABLEREQUESTDATATYPE_REFERENCE_TABLE )
668722 req .Data .SetAttributes (* attributes )
669723
670724 return req , diags
0 commit comments