|
| 1 | +package sumologic |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + |
| 6 | + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" |
| 7 | +) |
| 8 | + |
| 9 | +func dataSourceSumologicPartition() *schema.Resource { |
| 10 | + return &schema.Resource{ |
| 11 | + Read: dataSourceSumologicPartitionRead, |
| 12 | + Schema: dataSourcePartitionSchema(), |
| 13 | + } |
| 14 | +} |
| 15 | + |
| 16 | +func dataSourcePartitionSchema() map[string]*schema.Schema { |
| 17 | + return map[string]*schema.Schema{ |
| 18 | + "id": { |
| 19 | + Type: schema.TypeString, |
| 20 | + Required: true, |
| 21 | + }, |
| 22 | + "name": { |
| 23 | + Type: schema.TypeString, |
| 24 | + Computed: true, |
| 25 | + }, |
| 26 | + "routing_expression": { |
| 27 | + Type: schema.TypeString, |
| 28 | + Computed: true, |
| 29 | + }, |
| 30 | + "analytics_tier": { |
| 31 | + Type: schema.TypeString, |
| 32 | + Computed: true, |
| 33 | + }, |
| 34 | + "retention_period": { |
| 35 | + Type: schema.TypeInt, |
| 36 | + Computed: true, |
| 37 | + }, |
| 38 | + "is_compliant": { |
| 39 | + Type: schema.TypeBool, |
| 40 | + Computed: true, |
| 41 | + }, |
| 42 | + "total_bytes": { |
| 43 | + Type: schema.TypeInt, |
| 44 | + Computed: true, |
| 45 | + }, |
| 46 | + "data_forwarding_id": { |
| 47 | + Type: schema.TypeString, |
| 48 | + Computed: true, |
| 49 | + }, |
| 50 | + "is_active": { |
| 51 | + Type: schema.TypeBool, |
| 52 | + Computed: true, |
| 53 | + }, |
| 54 | + "index_type": { |
| 55 | + Type: schema.TypeString, |
| 56 | + Computed: true, |
| 57 | + }, |
| 58 | + "reduce_retention_period_immediately": { |
| 59 | + Type: schema.TypeBool, |
| 60 | + Computed: true, |
| 61 | + }, |
| 62 | + "is_included_in_default_search": { |
| 63 | + Type: schema.TypeBool, |
| 64 | + Computed: true, |
| 65 | + }, |
| 66 | + } |
| 67 | +} |
| 68 | + |
| 69 | +func dataSourceSumologicPartitionRead(d *schema.ResourceData, meta interface{}) error { |
| 70 | + c := meta.(*Client) |
| 71 | + |
| 72 | + var err error |
| 73 | + var spartition *Partition |
| 74 | + |
| 75 | + rid, ok := d.GetOk("id") |
| 76 | + |
| 77 | + if !ok { |
| 78 | + return fmt.Errorf("please specify the partition id") |
| 79 | + } |
| 80 | + |
| 81 | + id := rid.(string) |
| 82 | + spartition, err = c.GetPartition(id) |
| 83 | + if err != nil { |
| 84 | + return fmt.Errorf("error retrieving partition with id %v: %v", id, err) |
| 85 | + } |
| 86 | + if spartition == nil { |
| 87 | + return fmt.Errorf("partition with id %v not found", id) |
| 88 | + } |
| 89 | + |
| 90 | + d.SetId(spartition.ID) |
| 91 | + d.Set("routing_expression", spartition.RoutingExpression) |
| 92 | + d.Set("name", spartition.Name) |
| 93 | + d.Set("analytics_tier", spartition.AnalyticsTier) |
| 94 | + d.Set("retention_period", spartition.RetentionPeriod) |
| 95 | + d.Set("is_compliant", spartition.IsCompliant) |
| 96 | + d.Set("data_forwarding_id", spartition.DataForwardingId) |
| 97 | + d.Set("is_active", spartition.IsActive) |
| 98 | + d.Set("total_bytes", spartition.TotalBytes) |
| 99 | + d.Set("index_type", spartition.IndexType) |
| 100 | + d.Set("reduce_retention_period_immediately", spartition.ReduceRetentionPeriodImmediately) |
| 101 | + d.Set("is_included_in_default_search", spartition.IsIncludedInDefaultSearch) |
| 102 | + |
| 103 | + return nil |
| 104 | +} |
0 commit comments