Skip to content

Commit

Permalink
SUMO-251562 Adding open telemetry collector and source template resource
Browse files Browse the repository at this point in the history
  • Loading branch information
sangupta24 committed Dec 31, 2024
1 parent d3337b7 commit fac3210
Show file tree
Hide file tree
Showing 6 changed files with 700 additions and 3 deletions.
2 changes: 2 additions & 0 deletions sumologic/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ func Provider() terraform.ResourceProvider {
"sumologic_rum_source": resourceSumologicRumSource(),
"sumologic_role_v2": resourceSumologicRoleV2(),
"sumologic_azure_event_hub_log_source": resourceSumologicGenericPollingSource(),
"sumologic_ot_collector": resourceSumologicOTCollector(),
"sumologic_source_template": resourceSumologicSourceTemplate(),
},
DataSourcesMap: map[string]*schema.Resource{
"sumologic_cse_log_mapping_vendor_product": dataSourceCSELogMappingVendorAndProduct(),
Expand Down
158 changes: 158 additions & 0 deletions sumologic/resource_sumologic_ot_collector.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
// ----------------------------------------------------------------------------
//
// *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
//
// ----------------------------------------------------------------------------
//
// This file is automatically generated by Sumo Logic and manual
// changes will be clobbered when the file is regenerated. Do not submit
// changes to this file.
//
// ----------------------------------------------------------------------------
package sumologic

import (
"errors"
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"log"
)

func resourceSumologicOTCollector() *schema.Resource {
return &schema.Resource{
Read: resourceSumologicOTCollectorRead,
Delete: resourceSumologicOTCollectorDelete,
Update: resourceSumologicOTCollectorUpdate,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},

Schema: map[string]*schema.Schema{

"created_at": {
Type: schema.TypeString,
Computed: true,
},

"modified_by": {
Type: schema.TypeString,
Computed: true,
},

"created_by": {
Type: schema.TypeString,
Computed: true,
},

"description": {
Type: schema.TypeString,
Optional: true,
},

"alive": {
Type: schema.TypeBool,
Computed: true,
},

"is_remotely_managed": {
Type: schema.TypeBool,
Optional: true,
},

"name": {
Type: schema.TypeString,
Required: true,
},
"time_zone": {
Type: schema.TypeString,
Optional: true,
},

"modified_at": {
Type: schema.TypeString,
Computed: true,
},

"category": {
Type: schema.TypeString,
Optional: true,
},

"ephemeral": {
Type: schema.TypeBool,
Optional: true,
},

"tags": {
Type: schema.TypeMap,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Optional: true,
},
},
}
}

func resourceSumologicOTCollectorRead(d *schema.ResourceData, meta interface{}) error {
c := meta.(*Client)

id := d.Id()
otCollector, err := c.GetOTCollector(id)
if err != nil {
return err
}

if otCollector == nil {
log.Printf("[WARN] OTCollector not found, removing from state: %v - %v", id, err)
d.SetId("")
return nil
}

if err := d.Set("tags", otCollector.Tags); err != nil {
return fmt.Errorf("error setting fields for resource %s: %s", d.Id(), err)
}

d.Set("alive", otCollector.IsAlive)
d.Set("created_at", otCollector.CreatedAt)
d.Set("description", otCollector.Description)
d.Set("time_zone", otCollector.TimeZone)
d.Set("category", otCollector.Category)
d.Set("modified_at", otCollector.ModifiedAt)
d.Set("is_remotely_managed", otCollector.IsRemotelyManaged)
d.Set("created_by", otCollector.CreatedBy)
d.Set("modified_by", otCollector.ModifiedBy)
d.Set("ephemeral", otCollector.Ephemeral)
d.Set("name", otCollector.Name)

return nil
}

func resourceSumologicOTCollectorDelete(d *schema.ResourceData, meta interface{}) error {
c := meta.(*Client)

return c.DeleteOTCollector(d.Id())
}

func resourceSumologicOTCollectorUpdate(d *schema.ResourceData, meta interface{}) error {
return errors.New("Terraform does not support OTel collector updates")
}

func resourceToOTCollector(d *schema.ResourceData) OTCollector {

return OTCollector{
IsAlive: d.Get("alive").(bool),
CreatedBy: d.Get("created_by").(string),
Ephemeral: d.Get("ephemeral").(bool),
CreatedAt: d.Get("created_at").(string),
Description: d.Get("description").(string),
ModifiedBy: d.Get("modified_by").(string),
ModifiedAt: d.Get("modified_at").(string),
Category: d.Get("category").(string),
IsRemotelyManaged: d.Get("is_remotely_managed").(bool),
TimeZone: d.Get("time_zone").(string),
ID: d.Id(),
Name: d.Get("name").(string),
Tags: d.Get("fields").(map[string]interface{}),
}
}
Loading

0 comments on commit fac3210

Please sign in to comment.