Skip to content

Commit

Permalink
add fields to site integrations
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-cxf committed Aug 15, 2024
1 parent 99249f7 commit 552b368
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
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,

Check failure on line 82 in provider/resource_site_integration.go

View workflow job for this annotation

GitHub Actions / build

unknown field Fields in struct literal of type sigsci.IntegrationBody
})
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,

Check failure on line 143 in provider/resource_site_integration.go

View workflow job for this annotation

GitHub Actions / build

unknown field Fields in struct literal of type sigsci.UpdateIntegrationBody
})
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 552b368

Please sign in to comment.