Skip to content

Commit

Permalink
Add fields to site integrations (#231)
Browse files Browse the repository at this point in the history
* add fields to site integrations

* update docs for site_integration

* update go mod/sum

* tidy

* update main.tf
  • Loading branch information
jeremy-cxf authored Aug 21, 2024
1 parent 99249f7 commit 57f1c0f
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 9 deletions.
9 changes: 9 additions & 0 deletions docs/resources/site_integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,21 @@ resource "sigsci_site_integration" "test_integration" {
### Optional

- `events` (Set of String) Array of event types. Visit https://docs.fastly.com/signalsciences/integrations to find out which events the service you are connecting allows.
- `fields` (Block Set) (see [below for nested schema](#nestedblock--fields))

### Read-Only

- `id` (String) The ID of this resource.
- `name` (String) name

<a id="nestedblock--fields"></a>
### Nested Schema for `fields`

Required:

- `name` (String)
- `value` (String)

## Import

Import is supported using the following syntax:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/davecgh/go-spew v1.1.1
github.com/hashicorp/terraform-plugin-docs v0.14.1
github.com/hashicorp/terraform-plugin-sdk v1.14.0
github.com/signalsciences/go-sigsci v0.1.23
github.com/signalsciences/go-sigsci v0.1.24
golang.org/x/lint v0.0.0-20190409202823-959b441ac422
honnef.co/go/tools v0.4.2
)
Expand Down
10 changes: 2 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,8 @@ github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8=
github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
github.com/signalsciences/go-sigsci v0.1.20 h1:lMirioZwNWhnizOqryzvr1dsvOpmOn2e4MK+XEzlXrA=
github.com/signalsciences/go-sigsci v0.1.20/go.mod h1:CXwoXk81ZwFdne6o8cnAYwxvke5kcLg7zE6Bl/e1KUo=
github.com/signalsciences/go-sigsci v0.1.21 h1:5lkqv66jlPxqe7BHv46eEefttGo/6nRqLjqAqNuA5xA=
github.com/signalsciences/go-sigsci v0.1.21/go.mod h1:CXwoXk81ZwFdne6o8cnAYwxvke5kcLg7zE6Bl/e1KUo=
github.com/signalsciences/go-sigsci v0.1.22 h1:WDDYLS5sVbUcPgDAOrxjDfIWdfuBjISOtHvwDIR1U7M=
github.com/signalsciences/go-sigsci v0.1.22/go.mod h1:CXwoXk81ZwFdne6o8cnAYwxvke5kcLg7zE6Bl/e1KUo=
github.com/signalsciences/go-sigsci v0.1.23 h1:NrqxMi5JpNfpIUobbhnG/KDmNqM5h4/D/DVIqbyhN3k=
github.com/signalsciences/go-sigsci v0.1.23/go.mod h1:CXwoXk81ZwFdne6o8cnAYwxvke5kcLg7zE6Bl/e1KUo=
github.com/signalsciences/go-sigsci v0.1.24 h1:9KeviWFDsTo2N9vVBNcYlEMS7q2Lg50lLG40W1bGNAs=
github.com/signalsciences/go-sigsci v0.1.24/go.mod h1:CXwoXk81ZwFdne6o8cnAYwxvke5kcLg7zE6Bl/e1KUo=
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
github.com/spf13/afero v1.2.2 h1:5jhuqJyZCZf2JRofRvN/nIFgIWNzPa3/Vz8mYylgbWc=
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
Expand Down
17 changes: 17 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,23 @@ resource "sigsci_site_integration" "test_integration" {
events = ["listCreated"]
}

resource "sigsci_site_integration" "test_integration_datadog" {
site_short_name = sigsci_site.my-site.short_name
type = "datadog"
url = ""
events = ["flag", "agentAlert"]

fields {
name = "site"
value = "us1"
}

fields {
name = "apiKey"
value = "your_api_key"
}
}

resource "sigsci_corp_cloudwaf_certificate" "test_cloudwaf_certificate" {
name = "Certificate Name"
certificate_body = <<CERT
Expand Down
34 changes: 34 additions & 0 deletions provider/resource_site_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@ func resourceSiteIntegration() *schema.Resource {
Required: true,
ForceNew: true,
},
"fields": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
},
"value": {
Type: schema.TypeString,
Required: true,
},
},
},
},
"url": {
Type: schema.TypeString,
Description: "Integration URL",
Expand All @@ -51,10 +67,19 @@ func resourceSiteIntegrationCreate(d *schema.ResourceData, m interface{}) error
pm := m.(providerMetadata)
sc := pm.Client

fields := make(map[string]string)
if v, ok := d.GetOk("fields"); ok {
for _, item := range v.(*schema.Set).List() {
field := item.(map[string]interface{})
fields[field["name"].(string)] = field["value"].(string)
}
}

integrations, err := sc.AddIntegration(pm.Corp, d.Get("site_short_name").(string), sigsci.IntegrationBody{
Type: d.Get("type").(string),
URL: d.Get("url").(string),
Events: expandStringArray(d.Get("events").(*schema.Set)),
Fields: fields,
})
if err != nil {
return err
Expand Down Expand Up @@ -104,9 +129,18 @@ func resourceSiteIntegrationUpdate(d *schema.ResourceData, m interface{}) error
sc := pm.Client
site := d.Get("site_short_name").(string)

fields := make(map[string]string)
if v, ok := d.GetOk("fields"); ok {
for _, item := range v.(*schema.Set).List() {
field := item.(map[string]interface{})
fields[field["name"].(string)] = field["value"].(string)
}
}

err := sc.UpdateIntegration(pm.Corp, site, d.Id(), sigsci.UpdateIntegrationBody{
URL: d.Get("url").(string),
Events: expandStringArray(d.Get("events").(*schema.Set)),
Fields: fields,
})
if err != nil {
log.Printf("[ERROR] %s. Could not update integration with ID %s in corp %s site %s", err.Error(), d.Id(), pm.Corp, site)
Expand Down

0 comments on commit 57f1c0f

Please sign in to comment.