forked from SumoLogic/terraform-provider-sumologic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: support declaring data forwarding rule
- Loading branch information
1 parent
02001ee
commit b879ec0
Showing
8 changed files
with
373 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,91 @@ | ||
package sumologic | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
) | ||
|
||
func dataSourceSumologicPartition() *schema.Resource { | ||
resource := resourceSumologicPartition() | ||
return &schema.Resource{ | ||
Read: resource.Read, | ||
Schema: resource.Schema, | ||
Read: dataSourceSumologicPartitionRead, | ||
Schema: map[string]*schema.Schema{ | ||
"id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"routing_expression": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"analytics_tier": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"retention_period": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
"is_compliant": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
"total_bytes": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
"data_forwarding_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"is_active": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
"index_type": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"reduce_retention_period_immediately": { | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceSumologicPartitionRead(d *schema.ResourceData, meta interface{}) error { | ||
c := meta.(*Client) | ||
|
||
var err error | ||
var spartition *Partition | ||
|
||
if rid, ok := d.GetOk("id"); ok { | ||
id := rid.(string) | ||
spartition, err = c.GetPartition(id) | ||
if err != nil { | ||
return fmt.Errorf("partition with id %v not found: %v", id, err) | ||
} | ||
if spartition == nil { | ||
return fmt.Errorf("partition with id %v not found", id) | ||
} | ||
} | ||
|
||
d.SetId(spartition.ID) | ||
d.Set("routing_expression", spartition.RoutingExpression) | ||
d.Set("name", spartition.Name) | ||
d.Set("analytics_tier", spartition.AnalyticsTier) | ||
d.Set("retention_period", spartition.RetentionPeriod) | ||
d.Set("is_compliant", spartition.IsCompliant) | ||
d.Set("data_forwarding_id", spartition.DataForwardingId) | ||
d.Set("is_active", spartition.IsActive) | ||
d.Set("total_bytes", spartition.TotalBytes) | ||
d.Set("index_type", spartition.IndexType) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
sumologic/resource_sumologic_s3_data_forwarding_rule.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package sumologic | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
) | ||
|
||
func resourceSumologicS3DataForwardingRule() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceSumologicS3DataForwardingRuleCreate, | ||
Read: resourceSumologicS3DataForwardingRuleRead, | ||
Update: resourceSumologicS3DataForwardingRuleUpdate, | ||
Delete: resourceSumologicS3DataForwardingRuleDelete, | ||
Importer: &schema.ResourceImporter{ | ||
State: schema.ImportStatePassthrough, | ||
}, | ||
Schema: map[string]*schema.Schema{ | ||
"index_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"destination_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"enabled": { | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
Default: true, | ||
}, | ||
"file_format": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Default: "{index}_{day}_{hour}_{minute}_{second}", | ||
}, | ||
"format": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Default: "csv", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceSumologicS3DataForwardingRuleCreate(d *schema.ResourceData, meta interface{}) error { | ||
c := meta.(*Client) | ||
|
||
if d.Id() == "" { | ||
dfr := resourceToS3DataForwardingRule(d) | ||
createdDfd, err := c.CreateS3DataForwardingRule(dfr) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
d.SetId(createdDfd.ID) | ||
} | ||
|
||
return resourceSumologicS3DataForwardingRuleUpdate(d, meta) | ||
} | ||
|
||
func resourceSumologicS3DataForwardingRuleRead(d *schema.ResourceData, meta interface{}) error { | ||
c := meta.(*Client) | ||
dfr, err := c.GetS3DataForwardingRule(d.Id()) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
d.Set("index_id", dfr.IndexID) | ||
d.Set("destination_id", dfr.DestinationID) | ||
d.Set("enabled", dfr.Enabled) | ||
d.Set("file_format", dfr.FileFormat) | ||
d.Set("format", dfr.Format) | ||
|
||
return nil | ||
} | ||
|
||
func resourceSumologicS3DataForwardingRuleUpdate(d *schema.ResourceData, meta interface{}) error { | ||
c := meta.(*Client) | ||
dfr := resourceToS3DataForwardingRule(d) | ||
err := c.UpdateS3DataForwardingRule(dfr) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
return resourceSumologicS3DataForwardingRuleRead(d, meta) | ||
} | ||
|
||
func resourceSumologicS3DataForwardingRuleDelete(d *schema.ResourceData, meta interface{}) error { | ||
c := meta.(*Client) | ||
return c.DeleteS3DataForwardingRule(d.Id()) | ||
} | ||
|
||
func resourceToS3DataForwardingRule(d *schema.ResourceData) S3DataForwardingRule { | ||
return S3DataForwardingRule{ | ||
ID: d.Id(), | ||
IndexID: d.Get("index_id").(string), | ||
DestinationID: d.Get("destination_id").(string), | ||
Enabled: d.Get("enabled").(bool), | ||
FileFormat: d.Get("file_format").(string), | ||
Format: d.Get("format").(string), | ||
} | ||
} |
Oops, something went wrong.