Skip to content

Commit

Permalink
SUMO-178423: adding TF support for data forwarding destinations
Browse files Browse the repository at this point in the history
  • Loading branch information
Naman Goyal committed Sep 17, 2024
1 parent 6b36856 commit 09cb92c
Show file tree
Hide file tree
Showing 5 changed files with 548 additions and 0 deletions.
1 change: 1 addition & 0 deletions sumologic/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func Provider() terraform.ResourceProvider {
"sumologic_content": resourceSumologicContent(),
"sumologic_scheduled_view": resourceSumologicScheduledView(),
"sumologic_partition": resourceSumologicPartition(),
"sumologic_data_forwarding_destination": resourceSumologicDataForwardingDestination(),
"sumologic_field_extraction_rule": resourceSumologicFieldExtractionRule(),
"sumologic_connection": resourceSumologicConnection(),
"sumologic_monitor": resourceSumologicMonitorsLibraryMonitor(),
Expand Down
151 changes: 151 additions & 0 deletions sumologic/resource_sumologic_data_forwarding_destination.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
package sumologic

import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"log"
)

func resourceSumologicDataForwardingDestination() *schema.Resource {
return &schema.Resource{
Create: resourceSumologicDataForwardingDestinationCreate,
Read: resourceSumologicDataForwardingDestinationRead,
Update: resourceSumologicDataForwardingDestinationUpdate,
Delete: resourceSumologicDataForwardingDestinationDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},

Schema: map[string]*schema.Schema{

"access_key_id": {
Type: schema.TypeString,
Optional: true,
},

"encrypted": {
Type: schema.TypeBool,
Optional: true,
},

"region": {
Type: schema.TypeString,
Optional: true,
},

"destination_name": {
Type: schema.TypeString,
Optional: true,
},

"enabled": {
Type: schema.TypeBool,
Optional: true,
},

"description": {
Type: schema.TypeString,
Optional: true,
},

"authentication_mode": {
Type: schema.TypeString,
Required: true,
},

"role_arn": {
Type: schema.TypeString,
Optional: true,
},

"bucket_name": {
Type: schema.TypeString,
Required: true,
},

"secret_access_key": {
Type: schema.TypeString,
Optional: true,
},
},
}
}

func resourceSumologicDataForwardingDestinationCreate(d *schema.ResourceData, meta interface{}) error {
c := meta.(*Client)

if d.Id() == "" {
dataForwardingDestination := resourceToDataForwardingDestination(d)
id, err := c.CreateDataForwardingDestination(dataForwardingDestination)
if err != nil {
return err
}

d.SetId(id)
}

return resourceSumologicDataForwardingDestinationRead(d, meta)
}

func resourceSumologicDataForwardingDestinationRead(d *schema.ResourceData, meta interface{}) error {
c := meta.(*Client)

id := d.Id()
dataForwardingDestination, err := c.GetDataForwardingDestination(id)
if err != nil {
return err
}

if dataForwardingDestination == nil {
log.Printf("[WARN] DataForwardingDestination not found, removing from state: %v - %v", id, err)
d.SetId("")
return nil
}

d.Set("destination_name", dataForwardingDestination.DestinationName)
d.Set("role_arn", dataForwardingDestination.RoleArn)
d.Set("authentication_mode", dataForwardingDestination.AuthenticationMode)
d.Set("region", dataForwardingDestination.Region)
d.Set("secret_access_key", dataForwardingDestination.SecretAccessKey)
d.Set("bucket_name", dataForwardingDestination.BucketName)
d.Set("enabled", dataForwardingDestination.Enabled)
d.Set("description", dataForwardingDestination.Description)
d.Set("access_key_id", dataForwardingDestination.AccessKeyId)
d.Set("encrypted", dataForwardingDestination.Encrypted)

return nil
}

func resourceSumologicDataForwardingDestinationDelete(d *schema.ResourceData, meta interface{}) error {
c := meta.(*Client)

return c.DeleteDataForwardingDestination(d.Id())
}

func resourceSumologicDataForwardingDestinationUpdate(d *schema.ResourceData, meta interface{}) error {
c := meta.(*Client)

dataForwardingDestination := resourceToDataForwardingDestination(d)
err := c.UpdateDataForwardingDestination(dataForwardingDestination)
if err != nil {
return err
}

return resourceSumologicDataForwardingDestinationRead(d, meta)
}

func resourceToDataForwardingDestination(d *schema.ResourceData) DataForwardingDestination {

return DataForwardingDestination{
BucketName: d.Get("bucket_name").(string),
DestinationName: d.Get("destination_name").(string),
ID: d.Id(),
RoleArn: d.Get("role_arn").(string),
Region: d.Get("region").(string),
Description: d.Get("description").(string),
Enabled: d.Get("enabled").(bool),
AccessKeyId: d.Get("access_key_id").(string),
Encrypted: d.Get("encrypted").(bool),
AuthenticationMode: d.Get("authentication_mode").(string),
SecretAccessKey: d.Get("secret_access_key").(string),
}
}
Loading

0 comments on commit 09cb92c

Please sign in to comment.