|
| 1 | +package sumologic |
| 2 | + |
| 3 | +import ( |
| 4 | + "strconv" |
| 5 | + |
| 6 | + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" |
| 7 | +) |
| 8 | + |
| 9 | +func resourceSumologicInstalledCollector() *schema.Resource { |
| 10 | + return &schema.Resource{ |
| 11 | + Read: resourceSumologicCollectorRead, |
| 12 | + Delete: resourceSumologicCollectorDelete, |
| 13 | + Update: resourceSumologicInstalledCollectorUpdate, |
| 14 | + Importer: &schema.ResourceImporter{ |
| 15 | + State: schema.ImportStatePassthrough, |
| 16 | + }, |
| 17 | + |
| 18 | + Schema: map[string]*schema.Schema{ |
| 19 | + "name": { |
| 20 | + Type: schema.TypeString, |
| 21 | + Required: true, |
| 22 | + }, |
| 23 | + "description": { |
| 24 | + Type: schema.TypeString, |
| 25 | + Optional: true, |
| 26 | + }, |
| 27 | + "category": { |
| 28 | + Type: schema.TypeString, |
| 29 | + Optional: true, |
| 30 | + }, |
| 31 | + "cutoff_timestamp": { |
| 32 | + Type: schema.TypeInt, |
| 33 | + Optional: true, |
| 34 | + Default: 0, |
| 35 | + }, |
| 36 | + "timezone": { |
| 37 | + Type: schema.TypeString, |
| 38 | + Optional: true, |
| 39 | + Default: "Etc/UTC", |
| 40 | + }, |
| 41 | + "ephemeral": { |
| 42 | + Type: schema.TypeBool, |
| 43 | + Required: true, |
| 44 | + }, |
| 45 | + "fields": { |
| 46 | + Type: schema.TypeMap, |
| 47 | + Elem: &schema.Schema{ |
| 48 | + Type: schema.TypeString, |
| 49 | + }, |
| 50 | + Optional: true, |
| 51 | + }, |
| 52 | + "host_name": { |
| 53 | + Type: schema.TypeString, |
| 54 | + Optional: true, |
| 55 | + Default: "", |
| 56 | + }, |
| 57 | + "alive": { |
| 58 | + Type: schema.TypeBool, |
| 59 | + Computed: true, |
| 60 | + }, |
| 61 | + "last_seen_alive": { |
| 62 | + Type: schema.TypeInt, |
| 63 | + Computed: true, |
| 64 | + }, |
| 65 | + "source_sync_mode": { |
| 66 | + Type: schema.TypeString, |
| 67 | + Optional: true, |
| 68 | + Default: "UI", |
| 69 | + }, |
| 70 | + "target_cpu": { |
| 71 | + Type: schema.TypeInt, |
| 72 | + Optional: true, |
| 73 | + }, |
| 74 | + "collector_version": { |
| 75 | + Type: schema.TypeString, |
| 76 | + Computed: true, |
| 77 | + }, |
| 78 | + }, |
| 79 | + } |
| 80 | +} |
| 81 | + |
| 82 | +func resourceSumologicInstalledCollectorUpdate(d *schema.ResourceData, meta interface{}) error { |
| 83 | + |
| 84 | + collector := resourceToInstalledCollector(d) |
| 85 | + |
| 86 | + c := meta.(*Client) |
| 87 | + err := c.UpdateCollector(collector) |
| 88 | + |
| 89 | + if err != nil { |
| 90 | + return err |
| 91 | + } |
| 92 | + |
| 93 | + return resourceSumologicCollectorRead(d, meta) |
| 94 | +} |
| 95 | + |
| 96 | +func resourceToInstalledCollector(d *schema.ResourceData) Collector { |
| 97 | + id, _ := strconv.Atoi(d.Id()) |
| 98 | + |
| 99 | + return Collector{ |
| 100 | + ID: int64(id), |
| 101 | + CollectorType: "Installable", |
| 102 | + Name: d.Get("name").(string), |
| 103 | + Description: d.Get("description").(string), |
| 104 | + Category: d.Get("category").(string), |
| 105 | + TimeZone: d.Get("timezone").(string), |
| 106 | + HostName: d.Get("host_name").(string), |
| 107 | + Ephemeral: d.Get("ephemeral").(bool), |
| 108 | + SourceSyncMode: d.Get("source_sync_mode").(string), |
| 109 | + Targetcpu: d.Get("target_cpu").(int), |
| 110 | + Fields: d.Get("fields").(map[string]interface{}), |
| 111 | + CutoffTimestamp: d.Get("cutoff_timestamp").(int), |
| 112 | + Alive: d.Get("alive").(bool), |
| 113 | + LastSeenAlive: d.Get("last_seen_alive").(int), |
| 114 | + CollectorVersion: d.Get("collector_version").(string), |
| 115 | + } |
| 116 | +} |
0 commit comments