Skip to content

Commit

Permalink
Merge pull request #112 from signalsciences/edge-deployment
Browse files Browse the repository at this point in the history
add edge deployment provider resources
  • Loading branch information
shawnps authored Feb 15, 2023
2 parents 37613e4 + e2a33dd commit 4a931ee
Show file tree
Hide file tree
Showing 10 changed files with 206 additions and 14 deletions.
32 changes: 32 additions & 0 deletions docs/resources/edge_deployment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "sigsci_edge_deployment Resource - terraform-provider-sigsci"
subcategory: ""
description: |-
---

# sigsci_edge_deployment (Resource)



## Example Usage

```terraform
resource "sigsci_edge_deployment" {
site_short_name = "manual_test"
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `site_short_name` (String) Site short name

### Read-Only

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


34 changes: 34 additions & 0 deletions docs/resources/edge_deployment_service.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "sigsci_edge_deployment_service Resource - terraform-provider-sigsci"
subcategory: ""
description: |-
---

# sigsci_edge_deployment_service (Resource)



## Example Usage

```terraform
resource "sigsci_edge_deployment_service" "my-service" {
site_short_name = "manual_test"
fastly_sid = "test_sid"
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `fastly_sid` (String) Fastly service ID
- `site_short_name` (String) Site short name

### Read-Only

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


3 changes: 3 additions & 0 deletions examples/resources/sigsci_edge_deployment/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
resource "sigsci_edge_deployment" {
site_short_name = "manual_test"
}
4 changes: 4 additions & 0 deletions examples/resources/sigsci_edge_deployment_service/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resource "sigsci_edge_deployment_service" "my-service" {
site_short_name = "manual_test"
fastly_sid = "test_sid"
}
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.13.0
github.com/hashicorp/terraform-plugin-sdk v1.14.0
github.com/signalsciences/go-sigsci v0.1.8
github.com/signalsciences/go-sigsci v0.1.10
golang.org/x/lint v0.0.0-20190409202823-959b441ac422
honnef.co/go/tools v0.3.3
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@ github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNX
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.8 h1:vTWe3beT9lsaWnvoPsItPspk/9tKriDjeAJTruC4oo4=
github.com/signalsciences/go-sigsci v0.1.8/go.mod h1:9eUL/FIXlslxnqtsf0yk67CSBiYdL4ToYjYybzWQ77A=
github.com/signalsciences/go-sigsci v0.1.10 h1:3sv/ADf3p54X5gevHL54I9XDYVKzWgQiHabrJvzVKOU=
github.com/signalsciences/go-sigsci v0.1.10/go.mod h1:MjtGKaRj55suCf+CVUm4QN26wVn/2b1Syux/xU8/jOs=
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
31 changes: 24 additions & 7 deletions provider/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import (

//Config struct for email and password
type Config struct {
URL string
Email string
Password string
APIToken string
URL string
Email string
Password string
APIToken string
FastlyKey string
}

//Client returns a signal science client
Expand All @@ -24,11 +25,27 @@ func (c *Config) Client() (interface{}, error) {
return nil, fmt.Errorf("email cannot be empty")
}

if c.APIToken == "" && c.Password == "" {
return nil, fmt.Errorf("you must provide either password or api_token")
}

var (
client sigsci.Client
err error
)

if c.APIToken != "" {
return sigsci.NewTokenClient(c.Email, c.APIToken), nil
client = sigsci.NewTokenClient(c.Email, c.APIToken)
} else if c.Password != "" {
return sigsci.NewClient(c.Email, c.Password)
client, err = sigsci.NewClient(c.Email, c.Password)
if err != nil {
return nil, err
}
}

if c.FastlyKey != "" {
client.SetFastlyKey(c.FastlyKey)
}

return nil, fmt.Errorf("you must provide either password or api_token")
return client, nil
}
18 changes: 14 additions & 4 deletions provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ func Provider() terraform.ResourceProvider {
Sensitive: true,
AtLeastOneOf: []string{"password", "auth_token"},
},
"fastly_key": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("FASTLY_KEY", nil),
Description: "The Fastly API key used for deploying Signal Sciences as a Fastly edge security service. For edge deployment service calls, the Fastly key must have write access to the given service.",
Sensitive: true,
},
"api_url": {
Type: schema.TypeString,
Optional: true,
Expand All @@ -64,6 +71,8 @@ func Provider() terraform.ResourceProvider {
"sigsci_corp_integration": resourceCorpIntegration(),
"sigsci_corp_cloudwaf_instance": resourceCorpCloudWAFInstance(),
"sigsci_corp_cloudwaf_certificate": resourceCorpCloudWAFCertificate(),
"sigsci_edge_deployment": resourceEdgeDeployment(),
"sigsci_edge_deployment_service": resourceEdgeDeploymentService(),
},
}
provider.ConfigureFunc = providerConfigure()
Expand All @@ -73,10 +82,11 @@ func Provider() terraform.ResourceProvider {
func providerConfigure() schema.ConfigureFunc {
return func(d *schema.ResourceData) (interface{}, error) {
config := Config{
Email: d.Get("email").(string),
Password: d.Get("password").(string),
APIToken: d.Get("auth_token").(string),
URL: d.Get("api_url").(string),
Email: d.Get("email").(string),
Password: d.Get("password").(string),
APIToken: d.Get("auth_token").(string),
FastlyKey: d.Get("fastly_key").(string),
URL: d.Get("api_url").(string),
}
client, err := config.Client()
if err != nil {
Expand Down
40 changes: 40 additions & 0 deletions provider/resource_edge_deployment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package provider

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

func resourceEdgeDeployment() *schema.Resource {
return &schema.Resource{
Create: createOrUpdateEdgeDeployment,
Read: readEdgeDeployment,
Update: createOrUpdateEdgeDeployment,
Delete: deleteEdgeDeployment,
Importer: &schema.ResourceImporter{},
Schema: map[string]*schema.Schema{
"site_short_name": {
Type: schema.TypeString,
Description: "Site short name",
Required: true,
},
},
}
}

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

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

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

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

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

return pm.Client.DeleteEdgeDeployment(pm.Corp, d.Get("site_short_name").(string))
}
52 changes: 52 additions & 0 deletions provider/resource_edge_deployment_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package provider

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

func resourceEdgeDeploymentService() *schema.Resource {
return &schema.Resource{
Create: createOrUpdateEdgeDeploymentService,
Read: readEdgeDeploymentService,
Update: updateEdgeDeploymentBackends,
Delete: detachEdgeDeploymentService,
Importer: &schema.ResourceImporter{},
Schema: map[string]*schema.Schema{
"site_short_name": {
Type: schema.TypeString,
Description: "Site short name",
Required: true,
},

"fastly_sid": {
Type: schema.TypeString,
Description: "Fastly service ID",
Required: true,
},
},
}
}

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

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

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

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)

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

0 comments on commit 4a931ee

Please sign in to comment.