@@ -380,88 +380,85 @@ func dataSourceSysdigSecureCloudIngestionAssets() *schema.Resource {
380380
381381// Retrieves the information of a resource form the file and loads it in Terraform
382382func dataSourceSysdigSecureCloudIngestionAssetsRead (ctx context.Context , d * schema.ResourceData , meta interface {}) diag.Diagnostics {
383- var assets map [string ]any
384- var err error
385-
386383 client , err := getSecureOnboardingClient (meta .(SysdigClients ))
387384 if err != nil {
388385 return diag .FromErr (err )
389386 }
390387
391- cloudProvider , ok := d .GetOk ("cloud_provider" )
392- if ! ok {
393- // GCP case
394- assets , err = client .GetCloudIngestionAssetsSecure (ctx , "" , "" , "" )
395- if err != nil {
396- return diag .FromErr (err )
397- }
388+ cloudProvider := ""
389+ if v , ok := d .GetOk ("cloud_provider" ); ok {
390+ cloudProvider = v .(string )
391+ }
398392
399- d .SetId ("cloudIngestionAssets" )
400- assetsGcp , _ := assets ["gcp" ].(map [string ]interface {})
401- err = d .Set ("gcp_routing_key" , assetsGcp ["routingKey" ])
402- if err != nil {
403- return diag .FromErr (err )
393+ cloudProviderID := ""
394+ if v , ok := d .GetOk ("cloud_provider_id" ); ok {
395+ cloudProviderID = v .(string )
396+ }
397+
398+ componentType := ""
399+ if v , ok := d .GetOk ("component_type" ); ok {
400+ componentType = v .(string )
401+ }
402+
403+ assets , err := client .GetCloudIngestionAssetsSecure (ctx , cloudProvider , cloudProviderID , componentType )
404+ if err != nil {
405+ return diag .FromErr (err )
406+ }
407+
408+ d .SetId ("cloudIngestionAssets" )
409+
410+ // Set GCP data if available
411+ if gcpAssets , ok := assets ["gcp" ].(map [string ]interface {}); ok {
412+ if routingKey , exists := gcpAssets ["routingKey" ]; exists {
413+ if err := d .Set ("gcp_routing_key" , routingKey ); err != nil {
414+ return diag .FromErr (err )
415+ }
404416 }
405417
406- err = d .Set ("gcp_metadata" , assetsGcp ["metadata" ])
407- if err != nil {
408- return diag .FromErr (err )
418+ if metadata , exists := gcpAssets ["metadata" ]; exists {
419+ if err := d .Set ("gcp_metadata" , metadata ); err != nil {
420+ return diag .FromErr (err )
421+ }
409422 }
410- return nil
411423 }
412424
413- componentType , ok := d .GetOk ("component_type" )
414- if ! ok {
415- // AWS SNS case
416- assets , err = client .GetCloudIngestionAssetsSecure (ctx , cloudProvider .(string ), d .Get ("cloud_provider_id" ).(string ), "" )
417- if err != nil {
418- return diag .FromErr (err )
425+ // Set AWS data if available
426+ if awsAssets , ok := assets ["aws" ].(map [string ]interface {}); ok {
427+ awsData := map [string ]interface {}{
428+ "eventBusARN" : awsAssets ["eventBusARN" ],
429+ "eventBusARNGov" : awsAssets ["eventBusARNGov" ],
419430 }
420- assetsAws , _ := assets ["aws" ].(map [string ]interface {})
421431
422- var ingestionURL string
423- if assetsAws [ "snsMetadata " ] != nil {
424- ingestionURL = assetsAws [ "snsMetadata" ].( map [ string ] interface {})[ "ingestionURL" ].( string )
432+ // Add SNS specific fields if available
433+ if awsAssets [ "snsRoutingKey " ] != nil {
434+ awsData [ "sns_routing_key" ] = awsAssets [ "snsRoutingKey" ]
425435 }
426436
427- d .SetId ("cloudIngestionAssets" )
428- err = d .Set ("aws" , map [string ]interface {}{
429- "eventBusARN" : assetsAws ["eventBusARN" ],
430- "eventBusARNGov" : assetsAws ["eventBusARNGov" ],
431- "sns_routing_key" : assetsAws ["snsRoutingKey" ],
432- "sns_routing_url" : ingestionURL ,
433- })
434- if err != nil {
435- return diag .FromErr (err )
436- }
437- } else {
438- // AWS EventBridge case
439- assets , err = client .GetCloudIngestionAssetsSecure (ctx , d .Get ("cloud_provider" ).(string ), d .Get ("cloud_provider_id" ).(string ), componentType .(string ))
440- if err != nil {
441- return diag .FromErr (err )
437+ if snsMetadata , ok := awsAssets ["snsMetadata" ].(map [string ]interface {}); ok && snsMetadata != nil {
438+ if ingestionURL , exists := snsMetadata ["ingestionURL" ]; exists {
439+ awsData ["sns_routing_url" ] = ingestionURL
440+ }
442441 }
443442
444- assetsAws , _ := assets ["aws" ].(map [string ]interface {})
443+ // Add EventBridge specific fields if available
444+ if awsAssets ["ebRoutingKey" ] != nil {
445+ awsData ["eb_routing_key" ] = awsAssets ["ebRoutingKey" ]
446+ }
445447
446- var ingestionURL string
447- var apiKey string
448- if assetsAws ["ebMetadata" ] != nil {
449- ingestionURL = assetsAws ["ebMetadata" ].(map [string ]interface {})["ingestionURL" ].(string )
450- apiKey = assetsAws ["ebMetadata" ].(map [string ]interface {})["apiKey" ].(string )
448+ if ebMetadata , ok := awsAssets ["ebMetadata" ].(map [string ]interface {}); ok && ebMetadata != nil {
449+ if ingestionURL , exists := ebMetadata ["ingestionURL" ]; exists {
450+ awsData ["eb_routing_url" ] = ingestionURL
451+ }
452+ if apiKey , exists := ebMetadata ["apiKey" ]; exists {
453+ awsData ["eb_api_key" ] = apiKey
454+ }
451455 }
452456
453- d .SetId ("cloudIngestionAssets" )
454- err = d .Set ("aws" , map [string ]interface {}{
455- "eventBusARN" : assetsAws ["eventBusARN" ],
456- "eventBusARNGov" : assetsAws ["eventBusARNGov" ],
457- "eb_routing_key" : assetsAws ["ebRoutingKey" ],
458- "eb_routing_url" : ingestionURL ,
459- "eb_api_key" : apiKey ,
460- })
461- if err != nil {
457+ if err := d .Set ("aws" , awsData ); err != nil {
462458 return diag .FromErr (err )
463459 }
464460 }
461+
465462 return nil
466463}
467464
0 commit comments