|
| 1 | +// ---------------------------------------------------------------------------- |
| 2 | +// |
| 3 | +// *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** |
| 4 | +// |
| 5 | +// ---------------------------------------------------------------------------- |
| 6 | +// |
| 7 | +// This file is automatically generated by Sumo Logic and manual |
| 8 | +// changes will be clobbered when the file is regenerated. Do not submit |
| 9 | +// changes to this file. |
| 10 | +// |
| 11 | +// ---------------------------------------------------------------------------- |
| 12 | +package sumologic |
| 13 | + |
| 14 | +import ( |
| 15 | + "errors" |
| 16 | + "fmt" |
| 17 | + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" |
| 18 | + "log" |
| 19 | +) |
| 20 | + |
| 21 | +func resourceSumologicOTCollector() *schema.Resource { |
| 22 | + return &schema.Resource{ |
| 23 | + Read: resourceSumologicOTCollectorRead, |
| 24 | + Delete: resourceSumologicOTCollectorDelete, |
| 25 | + Update: resourceSumologicOTCollectorUpdate, |
| 26 | + Importer: &schema.ResourceImporter{ |
| 27 | + State: schema.ImportStatePassthrough, |
| 28 | + }, |
| 29 | + |
| 30 | + Schema: map[string]*schema.Schema{ |
| 31 | + |
| 32 | + "created_at": { |
| 33 | + Type: schema.TypeString, |
| 34 | + Computed: true, |
| 35 | + }, |
| 36 | + |
| 37 | + "modified_by": { |
| 38 | + Type: schema.TypeString, |
| 39 | + Computed: true, |
| 40 | + }, |
| 41 | + |
| 42 | + "created_by": { |
| 43 | + Type: schema.TypeString, |
| 44 | + Computed: true, |
| 45 | + }, |
| 46 | + |
| 47 | + "description": { |
| 48 | + Type: schema.TypeString, |
| 49 | + Optional: true, |
| 50 | + }, |
| 51 | + |
| 52 | + "alive": { |
| 53 | + Type: schema.TypeBool, |
| 54 | + Computed: true, |
| 55 | + }, |
| 56 | + |
| 57 | + "is_remotely_managed": { |
| 58 | + Type: schema.TypeBool, |
| 59 | + Optional: true, |
| 60 | + }, |
| 61 | + |
| 62 | + "name": { |
| 63 | + Type: schema.TypeString, |
| 64 | + Required: true, |
| 65 | + }, |
| 66 | + "time_zone": { |
| 67 | + Type: schema.TypeString, |
| 68 | + Optional: true, |
| 69 | + }, |
| 70 | + |
| 71 | + "modified_at": { |
| 72 | + Type: schema.TypeString, |
| 73 | + Computed: true, |
| 74 | + }, |
| 75 | + |
| 76 | + "category": { |
| 77 | + Type: schema.TypeString, |
| 78 | + Optional: true, |
| 79 | + }, |
| 80 | + |
| 81 | + "ephemeral": { |
| 82 | + Type: schema.TypeBool, |
| 83 | + Optional: true, |
| 84 | + }, |
| 85 | + |
| 86 | + "tags": { |
| 87 | + Type: schema.TypeMap, |
| 88 | + Elem: &schema.Schema{ |
| 89 | + Type: schema.TypeString, |
| 90 | + }, |
| 91 | + Optional: true, |
| 92 | + }, |
| 93 | + }, |
| 94 | + } |
| 95 | +} |
| 96 | + |
| 97 | +func resourceSumologicOTCollectorRead(d *schema.ResourceData, meta interface{}) error { |
| 98 | + c := meta.(*Client) |
| 99 | + |
| 100 | + id := d.Id() |
| 101 | + otCollector, err := c.GetOTCollector(id) |
| 102 | + if err != nil { |
| 103 | + return err |
| 104 | + } |
| 105 | + |
| 106 | + if otCollector == nil { |
| 107 | + log.Printf("[WARN] OTCollector not found, removing from state: %v - %v", id, err) |
| 108 | + d.SetId("") |
| 109 | + return nil |
| 110 | + } |
| 111 | + |
| 112 | + if err := d.Set("tags", otCollector.Tags); err != nil { |
| 113 | + return fmt.Errorf("error setting fields for resource %s: %s", d.Id(), err) |
| 114 | + } |
| 115 | + |
| 116 | + d.Set("alive", otCollector.IsAlive) |
| 117 | + d.Set("created_at", otCollector.CreatedAt) |
| 118 | + d.Set("description", otCollector.Description) |
| 119 | + d.Set("time_zone", otCollector.TimeZone) |
| 120 | + d.Set("category", otCollector.Category) |
| 121 | + d.Set("modified_at", otCollector.ModifiedAt) |
| 122 | + d.Set("is_remotely_managed", otCollector.IsRemotelyManaged) |
| 123 | + d.Set("created_by", otCollector.CreatedBy) |
| 124 | + d.Set("modified_by", otCollector.ModifiedBy) |
| 125 | + d.Set("ephemeral", otCollector.Ephemeral) |
| 126 | + d.Set("name", otCollector.Name) |
| 127 | + |
| 128 | + return nil |
| 129 | +} |
| 130 | + |
| 131 | +func resourceSumologicOTCollectorDelete(d *schema.ResourceData, meta interface{}) error { |
| 132 | + c := meta.(*Client) |
| 133 | + |
| 134 | + return c.DeleteOTCollector(d.Id()) |
| 135 | +} |
| 136 | + |
| 137 | +func resourceSumologicOTCollectorUpdate(d *schema.ResourceData, meta interface{}) error { |
| 138 | + return errors.New("Terraform does not support OTel collector updates") |
| 139 | +} |
| 140 | + |
| 141 | +func resourceToOTCollector(d *schema.ResourceData) OTCollector { |
| 142 | + |
| 143 | + return OTCollector{ |
| 144 | + IsAlive: d.Get("alive").(bool), |
| 145 | + CreatedBy: d.Get("created_by").(string), |
| 146 | + Ephemeral: d.Get("ephemeral").(bool), |
| 147 | + CreatedAt: d.Get("created_at").(string), |
| 148 | + Description: d.Get("description").(string), |
| 149 | + ModifiedBy: d.Get("modified_by").(string), |
| 150 | + ModifiedAt: d.Get("modified_at").(string), |
| 151 | + Category: d.Get("category").(string), |
| 152 | + IsRemotelyManaged: d.Get("is_remotely_managed").(bool), |
| 153 | + TimeZone: d.Get("time_zone").(string), |
| 154 | + ID: d.Id(), |
| 155 | + Name: d.Get("name").(string), |
| 156 | + Tags: d.Get("fields").(map[string]interface{}), |
| 157 | + } |
| 158 | +} |
0 commit comments