diff --git a/docs/resources/edge_deployment.md b/docs/resources/edge_deployment.md new file mode 100644 index 0000000..8d50b1f --- /dev/null +++ b/docs/resources/edge_deployment.md @@ -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 + +### Required + +- `site_short_name` (String) Site short name + +### Read-Only + +- `id` (String) The ID of this resource. + + diff --git a/docs/resources/edge_deployment_service.md b/docs/resources/edge_deployment_service.md new file mode 100644 index 0000000..63ba3ef --- /dev/null +++ b/docs/resources/edge_deployment_service.md @@ -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 + +### Required + +- `fastly_sid` (String) Fastly service ID +- `site_short_name` (String) Site short name + +### Read-Only + +- `id` (String) The ID of this resource. + + diff --git a/examples/resources/sigsci_edge_deployment/resource.tf b/examples/resources/sigsci_edge_deployment/resource.tf new file mode 100644 index 0000000..75b78c4 --- /dev/null +++ b/examples/resources/sigsci_edge_deployment/resource.tf @@ -0,0 +1,3 @@ +resource "sigsci_edge_deployment" { + site_short_name = "manual_test" +} diff --git a/examples/resources/sigsci_edge_deployment_service/resource.tf b/examples/resources/sigsci_edge_deployment_service/resource.tf new file mode 100644 index 0000000..a2e3fcf --- /dev/null +++ b/examples/resources/sigsci_edge_deployment_service/resource.tf @@ -0,0 +1,4 @@ +resource "sigsci_edge_deployment_service" "my-service" { + site_short_name = "manual_test" + fastly_sid = "test_sid" +} diff --git a/go.mod b/go.mod index 84f1c25..94c80e3 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index dba6048..6e2c3f7 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/provider/config.go b/provider/config.go index 02251fc..b78dcb5 100644 --- a/provider/config.go +++ b/provider/config.go @@ -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 @@ -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 } diff --git a/provider/provider.go b/provider/provider.go index a93940f..3b5f881 100644 --- a/provider/provider.go +++ b/provider/provider.go @@ -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, @@ -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() @@ -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 { diff --git a/provider/resource_edge_deployment.go b/provider/resource_edge_deployment.go new file mode 100644 index 0000000..891204d --- /dev/null +++ b/provider/resource_edge_deployment.go @@ -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)) +} diff --git a/provider/resource_edge_deployment_service.go b/provider/resource_edge_deployment_service.go new file mode 100644 index 0000000..80c262c --- /dev/null +++ b/provider/resource_edge_deployment_service.go @@ -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)) +}