|
| 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 | + "log" |
| 16 | + |
| 17 | + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" |
| 18 | +) |
| 19 | + |
| 20 | +func resourceSumologicIngestBudgetV2() *schema.Resource { |
| 21 | + return &schema.Resource{ |
| 22 | + Create: resourceSumologicIngestBudgetV2Create, |
| 23 | + Read: resourceSumologicIngestBudgetV2Read, |
| 24 | + Update: resourceSumologicIngestBudgetV2Update, |
| 25 | + Delete: resourceSumologicIngestBudgetV2Delete, |
| 26 | + Importer: &schema.ResourceImporter{ |
| 27 | + State: schema.ImportStatePassthrough, |
| 28 | + }, |
| 29 | + |
| 30 | + Schema: map[string]*schema.Schema{ |
| 31 | + |
| 32 | + "description": { |
| 33 | + Type: schema.TypeString, |
| 34 | + Optional: true, |
| 35 | + ForceNew: false, |
| 36 | + }, |
| 37 | + |
| 38 | + "timezone": { |
| 39 | + Type: schema.TypeString, |
| 40 | + Required: true, |
| 41 | + ForceNew: false, |
| 42 | + }, |
| 43 | + |
| 44 | + "action": { |
| 45 | + Type: schema.TypeString, |
| 46 | + Required: true, |
| 47 | + ForceNew: false, |
| 48 | + }, |
| 49 | + |
| 50 | + "capacity_bytes": { |
| 51 | + Type: schema.TypeInt, |
| 52 | + Required: true, |
| 53 | + ForceNew: false, |
| 54 | + }, |
| 55 | + |
| 56 | + "reset_time": { |
| 57 | + Type: schema.TypeString, |
| 58 | + Required: true, |
| 59 | + ForceNew: false, |
| 60 | + }, |
| 61 | + |
| 62 | + "audit_threshold": { |
| 63 | + Type: schema.TypeInt, |
| 64 | + Optional: true, |
| 65 | + ForceNew: false, |
| 66 | + }, |
| 67 | + |
| 68 | + "scope": { |
| 69 | + Type: schema.TypeString, |
| 70 | + Required: true, |
| 71 | + ForceNew: false, |
| 72 | + }, |
| 73 | + |
| 74 | + "name": { |
| 75 | + Type: schema.TypeString, |
| 76 | + Required: true, |
| 77 | + ForceNew: false, |
| 78 | + }, |
| 79 | + }, |
| 80 | + } |
| 81 | +} |
| 82 | + |
| 83 | +func resourceSumologicIngestBudgetV2Create(d *schema.ResourceData, meta interface{}) error { |
| 84 | + c := meta.(*Client) |
| 85 | + |
| 86 | + if d.Id() == "" { |
| 87 | + ingestBudgetV2 := resourceToIngestBudgetV2(d) |
| 88 | + id, err := c.CreateIngestBudgetV2(ingestBudgetV2) |
| 89 | + if err != nil { |
| 90 | + return err |
| 91 | + } |
| 92 | + |
| 93 | + d.SetId(id) |
| 94 | + } |
| 95 | + |
| 96 | + return resourceSumologicIngestBudgetV2Read(d, meta) |
| 97 | +} |
| 98 | + |
| 99 | +func resourceSumologicIngestBudgetV2Read(d *schema.ResourceData, meta interface{}) error { |
| 100 | + c := meta.(*Client) |
| 101 | + |
| 102 | + id := d.Id() |
| 103 | + ingestBudgetV2, err := c.GetIngestBudgetV2(id) |
| 104 | + if err != nil { |
| 105 | + return err |
| 106 | + } |
| 107 | + |
| 108 | + if ingestBudgetV2 == nil { |
| 109 | + log.Printf("[WARN] IngestBudgetV2 not found, removing from state: %v - %v", id, err) |
| 110 | + d.SetId("") |
| 111 | + return nil |
| 112 | + } |
| 113 | + |
| 114 | + d.Set("name", ingestBudgetV2.Name) |
| 115 | + d.Set("scope", ingestBudgetV2.Scope) |
| 116 | + d.Set("timezone", ingestBudgetV2.Timezone) |
| 117 | + d.Set("reset_time", ingestBudgetV2.ResetTime) |
| 118 | + d.Set("audit_threshold", ingestBudgetV2.AuditThreshold) |
| 119 | + d.Set("description", ingestBudgetV2.Description) |
| 120 | + d.Set("action", ingestBudgetV2.Action) |
| 121 | + d.Set("capacity_bytes", ingestBudgetV2.CapacityBytes) |
| 122 | + |
| 123 | + return nil |
| 124 | +} |
| 125 | + |
| 126 | +func resourceSumologicIngestBudgetV2Delete(d *schema.ResourceData, meta interface{}) error { |
| 127 | + c := meta.(*Client) |
| 128 | + |
| 129 | + return c.DeleteIngestBudgetV2(d.Id()) |
| 130 | +} |
| 131 | + |
| 132 | +func resourceSumologicIngestBudgetV2Update(d *schema.ResourceData, meta interface{}) error { |
| 133 | + c := meta.(*Client) |
| 134 | + |
| 135 | + ingestBudgetV2 := resourceToIngestBudgetV2(d) |
| 136 | + err := c.UpdateIngestBudgetV2(ingestBudgetV2) |
| 137 | + if err != nil { |
| 138 | + return err |
| 139 | + } |
| 140 | + |
| 141 | + return resourceSumologicIngestBudgetV2Read(d, meta) |
| 142 | +} |
| 143 | + |
| 144 | +func resourceToIngestBudgetV2(d *schema.ResourceData) IngestBudgetV2 { |
| 145 | + |
| 146 | + return IngestBudgetV2{ |
| 147 | + Scope: d.Get("scope").(string), |
| 148 | + Name: d.Get("name").(string), |
| 149 | + ResetTime: d.Get("reset_time").(string), |
| 150 | + Timezone: d.Get("timezone").(string), |
| 151 | + ID: d.Id(), |
| 152 | + Action: d.Get("action").(string), |
| 153 | + Description: d.Get("description").(string), |
| 154 | + AuditThreshold: d.Get("audit_threshold").(int), |
| 155 | + CapacityBytes: d.Get("capacity_bytes").(int), |
| 156 | + } |
| 157 | +} |
0 commit comments