Skip to content

Commit

Permalink
Add support for JSON arguments to EdgeDeployment (#143)
Browse files Browse the repository at this point in the history
* Add support for JSON arguments to EdgeDeployment

* Remove defaults to it defaults to API defaults

* updateEdgeDeploymentBackends needs to be rethought as terraform may not be the best
    place to trigger that from unless we are able to exploit dependency from a Fastly service

* Bump to go-sigsci to v0.1.14

* Revert "Remove defaults to it defaults to API defaults"

This reverts commit c304ffe.

---------

Co-authored-by: Vladimir Vuksan <[email protected]>
  • Loading branch information
vvuksan-fastly and vvuksan authored Mar 24, 2023
1 parent 706b5e0 commit 0288f6a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
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.13
github.com/signalsciences/go-sigsci v0.1.14
golang.org/x/lint v0.0.0-20190409202823-959b441ac422
honnef.co/go/tools v0.4.2
)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5g
github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
github.com/signalsciences/go-sigsci v0.1.13 h1:S8YVQ7ei0hybgWqGj0krle6GkA7l8k23VFgNP3ipQwc=
github.com/signalsciences/go-sigsci v0.1.13/go.mod h1:CXwoXk81ZwFdne6o8cnAYwxvke5kcLg7zE6Bl/e1KUo=
github.com/signalsciences/go-sigsci v0.1.14 h1:a2ucWDWDjXn93NXrVBcd7zyOMjxUcPEznTpCg0CLB+g=
github.com/signalsciences/go-sigsci v0.1.14/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
29 changes: 21 additions & 8 deletions provider/resource_edge_deployment_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package provider

import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/signalsciences/go-sigsci"
)

func resourceEdgeDeploymentService() *schema.Resource {
return &schema.Resource{
Create: createOrUpdateEdgeDeploymentService,
Read: readEdgeDeploymentService,
Update: updateEdgeDeploymentBackends,
Update: createOrUpdateEdgeDeploymentService,
Delete: detachEdgeDeploymentService,
Importer: &schema.ResourceImporter{},
Schema: map[string]*schema.Schema{
Expand All @@ -23,6 +24,20 @@ func resourceEdgeDeploymentService() *schema.Resource {
Description: "Fastly service ID",
Required: true,
},

"activate_version": {
Type: schema.TypeBool,
Description: "activate Fastly service version after clone. Possible values are true or false",
Optional: true,
Default: true,
},

"percent_enabled": {
Type: schema.TypeInt,
Description: "percentage of traffic to send to NGWAF@Edge. Possible values are integers values 0 to 100",
Optional: true,
Default: 0,
},
},
}
}
Expand All @@ -32,19 +47,17 @@ func createOrUpdateEdgeDeploymentService(d *schema.ResourceData, m interface{})

d.SetId(d.Get("fastly_sid").(string))

return pm.Client.CreateOrUpdateEdgeDeploymentService(pm.Corp, d.Get("site_short_name").(string), d.Get("fastly_sid").(string))
activateVersion := d.Get("activate_version").(bool)
return pm.Client.CreateOrUpdateEdgeDeploymentService(pm.Corp, d.Get("site_short_name").(string), d.Get("fastly_sid").(string), sigsci.CreateOrUpdateEdgeDeploymentServiceBody{
ActivateVersion: &activateVersion,
PercentEnabled: d.Get("percent_enabled").(int),
})
}

func readEdgeDeploymentService(d *schema.ResourceData, m interface{}) error {
return nil
}

func updateEdgeDeploymentBackends(d *schema.ResourceData, m interface{}) error {
pm := m.(providerMetadata)

return pm.Client.CreateOrUpdateEdgeDeploymentService(pm.Corp, d.Get("site_short_name").(string), d.Get("fastly_sid").(string))
}

func detachEdgeDeploymentService(d *schema.ResourceData, m interface{}) error {
pm := m.(providerMetadata)

Expand Down

0 comments on commit 0288f6a

Please sign in to comment.