Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: s3 data forwarding #636

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
29 changes: 12 additions & 17 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# This GitHub action can publish assets for release when a tag is created.
# Currently its setup to run on any tag that matches the pattern "v*" (ie. v0.1.0).
#
# This uses an action (paultyng/ghaction-import-gpg) that assumes you set your
# This uses an action (paultyng/ghaction-import-gpg) that assumes you set your
# private key in the `GPG_PRIVATE_KEY` secret and passphrase in the `PASSPHRASE`
# secret. If you would rather own your own GPG handling, please fork this action
# or use an alternative one for key handling.
#
# You will need to pass the `--batch` flag to `gpg` in your signing step
# You will need to pass the `--batch` flag to `gpg` in your signing step
# in `goreleaser` to indicate this is being used in a non-interactive mode.
#
name: release
Expand All @@ -18,27 +18,22 @@ jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
-
name: Checkout
- name: Checkout
uses: actions/checkout@v2
-
name: Unshallow
- name: Unshallow
run: git fetch --prune --unshallow
-
name: Set up Go
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17
-
name: Import GPG key
- name: Import GPG key
id: import_gpg
uses: paultyng/[email protected]
env:
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
PASSPHRASE: ${{ secrets.PASSPHRASE }}
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
uses: crazy-max/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.PASSPHRASE }}
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
version: 1.26.2
args: release --rm-dist
Expand Down
4 changes: 2 additions & 2 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ install: fmtcheck
install-dev: fmtcheck
mkdir -vp $(PLUGIN_DIR)
ifeq ($(UNAME), arm64)
go build ${DEBUG_FLAGS} -o $(PLUGIN_DIR)/sumologic.com/dev/sumologic/1.0.0/darwin_arm64/terraform-provider-sumologic
go build ${DEBUG_FLAGS} -o $(PLUGIN_DIR)/sumologic.com/dev/sumologic/1.0.0/darwin_arm64/terraform-provider-sumologic
else
go build ${DEBUG_FLAGS} -o $(PLUGIN_DIR)/sumologic.com/dev/sumologic/1.0.0/darwin_amd64/terraform-provider-sumologic
endif
Expand All @@ -49,7 +49,7 @@ fmtcheck:
lint:
@echo "==> Checking source code against linters..."
golangci-lint run ./...

test: fmtcheck
go test -i $(TEST) || exit 1
echo $(TEST) | \
Expand Down
95 changes: 95 additions & 0 deletions sumologic/data_source_sumologic_partition.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package sumologic

import (
"fmt"

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

func dataSourcePartitionSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Required: 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 dataSourceSumologicPartition() *schema.Resource {
return &schema.Resource{
Read: dataSourceSumologicPartitionRead,
Schema: dataSourcePartitionSchema(),
}
}

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)
d.Set("reduce_retention_period_immediately", spartition.ReduceRetentionPeriodImmediately)

return nil
}
58 changes: 58 additions & 0 deletions sumologic/data_source_sumologic_partitions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package sumologic

import (
"fmt"

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

func dataSourceSumologicPartitions() *schema.Resource {
return &schema.Resource{
Read: dataSourceSumologicPartitionsRead,

Schema: map[string]*schema.Schema{
"partitions": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: dataSourcePartitionSchema(),
Read: dataSourceSumologicPartitionRead,
},
},
},
}
}

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

spartitions, err := c.ListPartitions()
if err != nil {
return fmt.Errorf("error retrieving partitions: %v", err)
}

partitions := make([]map[string]interface{}, 0, len(spartitions))

for _, spartition := range spartitions {
partition := map[string]interface{}{
"id": spartition.ID,
"name": spartition.Name,
"routing_expression": spartition.RoutingExpression,
"analytics_tier": spartition.AnalyticsTier,
"retention_period": spartition.RetentionPeriod,
"is_compliant": spartition.IsCompliant,
"total_bytes": spartition.TotalBytes,
"data_forwarding_id": spartition.DataForwardingID,
"is_active": spartition.IsActive,
"index_type": spartition.IndexType,
"reduce_retention_period_immediately": spartition.ReduceRetentionPeriodImmediately,
}

partitions = append(partitions, partition)
}

d.Set("partitions", partitions)
d.SetId(c.BaseURL.Host)

return nil
}
4 changes: 4 additions & 0 deletions sumologic/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ func Provider() terraform.ResourceProvider {
"sumologic_s3_source": resourceSumologicGenericPollingSource(),
"sumologic_s3_audit_source": resourceSumologicGenericPollingSource(),
"sumologic_s3_archive_source": resourceSumologicGenericPollingSource(),
"sumologic_s3_data_forwarding_destination": resourceSumologicS3DataForwardingDestination(),
"sumologic_s3_data_forwarding_rule": resourceSumologicS3DataForwardingRule(),
"sumologic_cloudwatch_source": resourceSumologicGenericPollingSource(),
"sumologic_aws_inventory_source": resourceSumologicGenericPollingSource(),
"sumologic_aws_xray_source": resourceSumologicGenericPollingSource(),
Expand Down Expand Up @@ -132,6 +134,8 @@ func Provider() terraform.ResourceProvider {
"sumologic_role": dataSourceSumologicRole(),
"sumologic_role_v2": dataSourceSumologicRoleV2(),
"sumologic_user": dataSourceSumologicUser(),
"sumologic_partitions": dataSourceSumologicPartitions(),
"sumologic_partition": dataSourceSumologicPartition(),
},
ConfigureFunc: providerConfigure,
}
Expand Down
4 changes: 2 additions & 2 deletions sumologic/resource_sumologic_partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func resourceSumologicPartitionRead(d *schema.ResourceData, meta interface{}) er
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("data_forwarding_id", spartition.DataForwardingID)
d.Set("is_active", spartition.IsActive)
d.Set("total_bytes", spartition.TotalBytes)
d.Set("index_type", spartition.IndexType)
Expand Down Expand Up @@ -141,7 +141,7 @@ func resourceToPartition(d *schema.ResourceData) Partition {
AnalyticsTier: d.Get("analytics_tier").(string),
RetentionPeriod: d.Get("retention_period").(int),
IsCompliant: d.Get("is_compliant").(bool),
DataForwardingId: d.Get("data_forwarding_id").(string),
DataForwardingID: d.Get("data_forwarding_id").(string),
IsActive: d.Get("is_active").(bool),
TotalBytes: d.Get("total_bytes").(int),
IndexType: d.Get("index_type").(string),
Expand Down
Loading