diff --git a/.env.sample b/.env.sample
new file mode 100644
index 0000000..cb7f9be
--- /dev/null
+++ b/.env.sample
@@ -0,0 +1,5 @@
+BIGCOMMERCE_STORE_HASH=
+PREV_BIGCOMMERCE_CLIENT_ID=
+PREV_BIGCOMMERCE_ACCESS_TOKEN=
+BIGCOMMERCE_CLIENT_ID=
+BIGCOMMERCE_ACCESS_TOKEN=
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index 42579e0..e221457 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
.DS_Store
+.env
terraform-provider-bigcommerce
bin
diff --git a/Makefile b/Makefile
index 3b99d34..a5dbdf2 100644
--- a/Makefile
+++ b/Makefile
@@ -1,11 +1,14 @@
TEST?=$$(go list ./... | grep -v 'vendor')
-HOSTNAME=ashsmith.io
-NAMESPACE=test
+HOSTNAME=space48.com
+NAMESPACE=local
NAME=bigcommerce
BINARY=terraform-provider-${NAME}
-VERSION=0.2
+VERSION=0.1
OS_ARCH=darwin_amd64
+include .env
+export
+
default: install
build:
@@ -34,4 +37,4 @@ test:
echo $(TEST) | xargs -t -n4 go test $(TESTARGS) -timeout=30s -parallel=4
testacc:
- TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 120m
\ No newline at end of file
+ TF_ACC=1 go test -v ./...
\ No newline at end of file
diff --git a/README.md b/README.md
index d541097..678972d 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,7 @@
Terraform Provider for BigCommerce
-- [Bigcommerce Provider Documentation on Terraform](https://registry.terraform.io/providers/ashsmith/bigcommerce/latest)
+- [Bigcommerce Provider Documentation on Terraform](https://registry.terraform.io/providers/space48/bigcommerce/latest)
## Resources:
@@ -30,7 +30,7 @@ go generate
terraform {
required_providers {
bigcommerce = {
- source = "ashsmith/bigcommerce"
+ source = "space48/bigcommerce"
version = "0.1.0"
}
}
@@ -38,12 +38,12 @@ terraform {
provider "bigcommerce" {
store_hash = "your-hash"
- client_id = "your-client-id"
- access_token = "your-access-token"
}
resource "bigcommerce_webhook" "example" {
scope = "store/customer/*"
+ client_id = "your-client-id"
+ access_token = "your-access-token"
destination = "https://foo.bar/webhook"
is_active = true
diff --git a/bigcommerce/data_source_webhook.go b/bigcommerce/data_source_webhook.go
index 1cb3cba..174053b 100644
--- a/bigcommerce/data_source_webhook.go
+++ b/bigcommerce/data_source_webhook.go
@@ -2,7 +2,6 @@ package bigcommerce
import (
"context"
- "fmt"
"strconv"
"github.com/ashsmith/bigcommerce-api-go"
@@ -15,41 +14,33 @@ func dataSourceWebhook() *schema.Resource {
Description: "Provides information about a webhook ",
ReadContext: dataSourceWebhookRead,
Schema: map[string]*schema.Schema{
- "id": &schema.Schema{
+ "id": {
Type: schema.TypeString,
Required: true,
},
- "client_id": &schema.Schema{
+ "client_id": {
Type: schema.TypeString,
- Computed: true,
Sensitive: true,
+ Required: true,
},
- "store_hash": &schema.Schema{
+ "access_token": {
Type: schema.TypeString,
- Computed: true,
Sensitive: true,
+ Required: true,
},
- "created_at": &schema.Schema{
- Type: schema.TypeInt,
- Computed: true,
- },
- "updated_at": &schema.Schema{
- Type: schema.TypeInt,
- Computed: true,
- },
- "scope": &schema.Schema{
+ "scope": {
Type: schema.TypeString,
Computed: true,
},
- "destination": &schema.Schema{
+ "destination": {
Type: schema.TypeString,
Computed: true,
},
- "is_active": &schema.Schema{
+ "is_active": {
Type: schema.TypeBool,
Computed: true,
},
- "header": &schema.Schema{
+ "header": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
@@ -72,14 +63,15 @@ func dataSourceWebhook() *schema.Resource {
func dataSourceWebhookRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
// Warning or errors can be collected in a slice type
var diags diag.Diagnostics
+ storeHash := m.(string)
+ clientId := d.Get("client_id").(string)
+ accessToken := d.Get("access_token").(string)
- c := m.(*bigcommerce.Client)
+ client := createBigCommerceClient(storeHash, clientId, accessToken)
hookID := d.Get("id").(string)
- fmt.Println(c)
-
webhookID, _ := strconv.ParseInt(hookID, 10, 64)
- webhook, whErr := c.Webhooks.Get(webhookID)
+ webhook, whErr := client.Webhooks.Get(webhookID)
if whErr != nil {
return diag.FromErr(whErr)
@@ -99,18 +91,6 @@ func setWebhookData(webhook bigcommerce.Webhook, d *schema.ResourceData) diag.Di
if err := d.Set("id", strconv.FormatInt(webhook.ID, 10)); err != nil {
return diag.FromErr(err)
}
- if err := d.Set("client_id", webhook.ClientID); err != nil {
- return diag.FromErr(err)
- }
- if err := d.Set("store_hash", webhook.StoreHash); err != nil {
- return diag.FromErr(err)
- }
- if err := d.Set("created_at", int(webhook.CreatedAt)); err != nil {
- return diag.FromErr(err)
- }
- if err := d.Set("updated_at", int(webhook.UpdatedAt)); err != nil {
- return diag.FromErr(err)
- }
if err := d.Set("scope", webhook.Scope); err != nil {
return diag.FromErr(err)
}
diff --git a/bigcommerce/provider.go b/bigcommerce/provider.go
index 0b454c2..6892119 100644
--- a/bigcommerce/provider.go
+++ b/bigcommerce/provider.go
@@ -2,9 +2,7 @@ package bigcommerce
import (
"context"
- "net/http"
- "github.com/ashsmith/bigcommerce-api-go"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
@@ -13,23 +11,11 @@ import (
func Provider() *schema.Provider {
return &schema.Provider{
Schema: map[string]*schema.Schema{
- "store_hash": &schema.Schema{
+ "store_hash": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("BIGCOMMERCE_STORE_HASH", nil),
},
- "client_id": &schema.Schema{
- Type: schema.TypeString,
- Optional: true,
- Sensitive: true,
- DefaultFunc: schema.EnvDefaultFunc("BIGCOMMERCE_CLIENT_ID", nil),
- },
- "access_token": &schema.Schema{
- Type: schema.TypeString,
- Optional: true,
- Sensitive: true,
- DefaultFunc: schema.EnvDefaultFunc("BIGCOMMERCE_ACCESS_TOKEN", nil),
- },
},
ResourcesMap: map[string]*schema.Resource{
"bigcommerce_webhook": resourceWebhook(),
@@ -42,28 +28,10 @@ func Provider() *schema.Provider {
}
func providerConfigure(ctx context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) {
- clientID := d.Get("client_id").(string)
- accessToken := d.Get("access_token").(string)
storeHash := d.Get("store_hash").(string)
// Warning or errors can be collected in a slice type
var diags diag.Diagnostics
- if clientID == "" {
- diags = append(diags, diag.Diagnostic{
- Severity: diag.Error,
- Summary: "Missing client_id from provider configuration",
- Detail: "client_id is a required parmeter and must be defined, you can also use BIGCOMMERCE_CLIENT_ID environment variable.",
- })
- }
-
- if accessToken == "" {
- diags = append(diags, diag.Diagnostic{
- Severity: diag.Error,
- Summary: "Missing access_token from provider configuration",
- Detail: "access_token is a required parmeter and must be defined, you can also use BIGCOMMERCE_ACCESS_TOKEN environment variable.",
- })
- }
-
if storeHash == "" {
diags = append(diags, diag.Diagnostic{
Severity: diag.Error,
@@ -72,18 +40,9 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData) (interface{}
})
}
- if (clientID == "") || (accessToken == "") || (storeHash == "") {
+ if storeHash == "" {
return nil, diags
}
- app := bigcommerce.App{
- ClientID: clientID,
- StoreHash: storeHash,
- AccessToken: accessToken,
- }
-
- httpClient := http.Client{}
- bcClient := app.NewClient(httpClient)
-
- return bcClient, diags
+ return storeHash, diags
}
diff --git a/bigcommerce/provider_test.go b/bigcommerce/provider_test.go
new file mode 100644
index 0000000..6beef4d
--- /dev/null
+++ b/bigcommerce/provider_test.go
@@ -0,0 +1,30 @@
+package bigcommerce
+
+import (
+ "os"
+ "testing"
+
+ "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
+)
+
+var testAccProviders map[string]*schema.Provider
+var testAccProvider *schema.Provider
+
+func init() {
+ testAccProvider = Provider()
+ testAccProviders = map[string]*schema.Provider{
+ "bigcommerce": testAccProvider,
+ }
+}
+
+func TestProvider(t *testing.T) {
+ if err := Provider().InternalValidate(); err != nil {
+ t.Fatalf("err: %s", err)
+ }
+}
+
+func testAccPreCheck(t *testing.T) {
+ if v := os.Getenv("BIGCOMMERCE_STORE_HASH"); v == "" {
+ t.Fatal("BIGCOMMERCE_STORE_HASH must be set for acceptance tests")
+ }
+}
diff --git a/bigcommerce/resource_webhook.go b/bigcommerce/resource_webhook.go
index 59ce357..c314f9a 100644
--- a/bigcommerce/resource_webhook.go
+++ b/bigcommerce/resource_webhook.go
@@ -2,6 +2,7 @@ package bigcommerce
import (
"context"
+ "net/http"
"strconv"
"github.com/ashsmith/bigcommerce-api-go"
@@ -17,41 +18,33 @@ func resourceWebhook() *schema.Resource {
UpdateContext: resourceWebhookUpdate,
DeleteContext: resourceWebhookDelete,
Schema: map[string]*schema.Schema{
- "id": &schema.Schema{
+ "id": {
Type: schema.TypeString,
Computed: true,
},
- "client_id": &schema.Schema{
+ "client_id": {
Type: schema.TypeString,
- Computed: true,
Sensitive: true,
+ Required: true,
},
- "store_hash": &schema.Schema{
+ "access_token": {
Type: schema.TypeString,
- Computed: true,
Sensitive: true,
+ Required: true,
},
- "created_at": &schema.Schema{
- Type: schema.TypeInt,
- Computed: true,
- },
- "updated_at": &schema.Schema{
- Type: schema.TypeInt,
- Computed: true,
- },
- "scope": &schema.Schema{
+ "scope": {
Type: schema.TypeString,
Required: true,
},
- "destination": &schema.Schema{
+ "destination": {
Type: schema.TypeString,
Required: true,
},
- "is_active": &schema.Schema{
+ "is_active": {
Type: schema.TypeBool,
Required: true,
},
- "header": &schema.Schema{
+ "header": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
@@ -72,7 +65,11 @@ func resourceWebhook() *schema.Resource {
}
func resourceWebhookCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
- client := m.(*bigcommerce.Client)
+ storeHash := m.(string)
+ clientId := d.Get("client_id").(string)
+ accessToken := d.Get("access_token").(string)
+
+ client := createBigCommerceClient(storeHash, clientId, accessToken)
var diags diag.Diagnostics
scope := d.Get("scope").(string)
@@ -98,7 +95,11 @@ func resourceWebhookCreate(ctx context.Context, d *schema.ResourceData, m interf
}
func resourceWebhookRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
- client := m.(*bigcommerce.Client)
+ storeHash := m.(string)
+ clientId := d.Get("client_id").(string)
+ accessToken := d.Get("access_token").(string)
+
+ client := createBigCommerceClient(storeHash, clientId, accessToken)
var diags diag.Diagnostics
webhookID, _ := strconv.ParseInt(d.Id(), 10, 64)
@@ -117,30 +118,53 @@ func resourceWebhookRead(ctx context.Context, d *schema.ResourceData, m interfac
}
func resourceWebhookUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
- client := m.(*bigcommerce.Client)
-
+ prevClientId, currentClientId := d.GetChange("client_id")
+ prevAccessToken, currentAccessToken := d.GetChange("access_token")
webhookID, _ := strconv.ParseInt(d.Id(), 10, 64)
-
- if d.HasChange("scope") || d.HasChange("destination") || d.HasChange("is_active") || d.HasChange("header") {
- webhook := bigcommerce.Webhook{
- ID: webhookID,
- Scope: d.Get("scope").(string),
- Destination: d.Get("destination").(string),
- IsActive: d.Get("is_active").(bool),
+ storeHash := m.(string)
+ if d.HasChange("client_id") || d.HasChange("access_token") {
+ d.Set("access_token", prevAccessToken)
+ d.Set("client_id", prevClientId)
+ deleteDiag := resourceWebhookDelete(ctx, d, m)
+ if deleteDiag.HasError() {
+ return deleteDiag
}
-
- webhook.Headers = formatHeaders(d)
-
- _, err := client.Webhooks.Update(webhook)
- if err != nil {
- return diag.FromErr(err)
+ d.Set("access_token", currentAccessToken)
+ d.Set("client_id", currentClientId)
+ createDiag := resourceWebhookCreate(ctx, d, m)
+ if createDiag.HasError() {
+ return createDiag
+ }
+ } else {
+ if d.HasChange("scope") || d.HasChange("destination") || d.HasChange("is_active") || d.HasChange("header") {
+ clientId := d.Get("client_id").(string)
+ accessToken := d.Get("access_token").(string)
+
+ client := createBigCommerceClient(storeHash, clientId, accessToken)
+ webhook := bigcommerce.Webhook{
+ ID: webhookID,
+ Scope: d.Get("scope").(string),
+ Destination: d.Get("destination").(string),
+ IsActive: d.Get("is_active").(bool),
+ }
+
+ webhook.Headers = formatHeaders(d)
+
+ _, err := client.Webhooks.Update(webhook)
+ if err != nil {
+ return diag.FromErr(err)
+ }
}
}
return resourceWebhookRead(ctx, d, m)
}
func resourceWebhookDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
- client := m.(*bigcommerce.Client)
+ storeHash := m.(string)
+ clientId := d.Get("client_id").(string)
+ accessToken := d.Get("access_token").(string)
+
+ client := createBigCommerceClient(storeHash, clientId, accessToken)
var diags diag.Diagnostics
webhookID, _ := strconv.ParseInt(d.Id(), 10, 64)
@@ -157,6 +181,17 @@ func resourceWebhookDelete(ctx context.Context, d *schema.ResourceData, m interf
return diags
}
+func createBigCommerceClient(storeHash string, clientID string, accessToken string) *bigcommerce.Client {
+ app := bigcommerce.App{
+ ClientID: clientID,
+ StoreHash: storeHash,
+ AccessToken: accessToken,
+ }
+
+ httpClient := http.Client{}
+ return app.NewClient(httpClient)
+}
+
func formatHeaders(d *schema.ResourceData) map[string]string {
wbHeaders := make(map[string]string)
headers := d.Get("header").(*schema.Set).List()
diff --git a/bigcommerce/resource_webhook_test.go b/bigcommerce/resource_webhook_test.go
new file mode 100644
index 0000000..7d5c6ab
--- /dev/null
+++ b/bigcommerce/resource_webhook_test.go
@@ -0,0 +1,256 @@
+package bigcommerce
+
+import (
+ "fmt"
+ "os"
+ "regexp"
+ "strconv"
+ "testing"
+
+ "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
+ "github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
+)
+
+func TestAccWebhook_Basic(t *testing.T) {
+ resource.Test(t, resource.TestCase{
+ PreCheck: func() { testAccPreCheck(t) },
+ Providers: testAccProviders,
+ CheckDestroy: testAccCheckWebhookDestroy,
+ Steps: []resource.TestStep{
+ {
+ Config: testAccCheckWebhookBasic(),
+ Check: resource.ComposeTestCheckFunc(
+ testAccCheckExampleWebhookExists("bigcommerce_webhook.order_event"),
+ ),
+ },
+ },
+ })
+}
+
+func TestAccWebhook_Update_Credentials(t *testing.T) {
+ resource.Test(t, resource.TestCase{
+ PreCheck: func() { testAccPreCheck(t) },
+ Providers: testAccProviders,
+ CheckDestroy: testAccCheckWebhookDestroy,
+ Steps: []resource.TestStep{
+ {
+ Config: testAccCheckWebhookUpdatePre(),
+ Check: resource.ComposeTestCheckFunc(
+ testAccCheckExampleWebhookExists("bigcommerce_webhook.order_event_update"),
+ resource.TestCheckResourceAttr("bigcommerce_webhook.order_event_update", "access_token", os.Getenv("PREV_BIGCOMMERCE_ACCESS_TOKEN")),
+ resource.TestCheckResourceAttr("bigcommerce_webhook.order_event_update", "client_id", os.Getenv("PREV_BIGCOMMERCE_CLIENT_ID")),
+ ),
+ },
+ {
+ Config: testAccCheckWebhookUpdatePost(),
+ Check: resource.ComposeTestCheckFunc(
+ testAccCheckExampleWebhookExists("bigcommerce_webhook.order_event_update"),
+ resource.TestCheckResourceAttr("bigcommerce_webhook.order_event_update", "access_token", os.Getenv("BIGCOMMERCE_ACCESS_TOKEN")),
+ resource.TestCheckResourceAttr("bigcommerce_webhook.order_event_update", "client_id", os.Getenv("BIGCOMMERCE_CLIENT_ID")),
+ ),
+ },
+ },
+ })
+}
+
+func TestAccWebhook_Update_Simple(t *testing.T) {
+ resource.Test(t, resource.TestCase{
+ PreCheck: func() { testAccPreCheck(t) },
+ Providers: testAccProviders,
+ CheckDestroy: testAccCheckWebhookDestroy,
+ Steps: []resource.TestStep{
+ {
+ Config: testAccCheckSimpleWebhookUpdatePre(),
+ Check: resource.ComposeTestCheckFunc(
+ testAccCheckExampleWebhookExists("bigcommerce_webhook.order_event_update"),
+ resource.TestCheckResourceAttr("bigcommerce_webhook.order_event_update", "is_active", "true"),
+ ),
+ },
+ {
+ Config: testAccCheckSimpleWebhookUpdatePost(),
+ Check: resource.ComposeTestCheckFunc(
+ testAccCheckExampleWebhookExists("bigcommerce_webhook.order_event_update"),
+ resource.TestCheckResourceAttr("bigcommerce_webhook.order_event_update", "is_active", "false"),
+ ),
+ },
+ },
+ })
+}
+
+func TestAccWebhook_Multiple(t *testing.T) {
+ resource.Test(t, resource.TestCase{
+ PreCheck: func() { testAccPreCheck(t) },
+ Providers: testAccProviders,
+ CheckDestroy: testAccCheckWebhookDestroy,
+ Steps: []resource.TestStep{
+ {
+ Config: testAccCheckWebhooksMultiple(),
+ Check: resource.ComposeTestCheckFunc(
+ testAccCheckExampleWebhookExists("bigcommerce_webhook.order_event_multiple"),
+ testAccCheckExampleWebhookExists("bigcommerce_webhook.refund_event_multiple"),
+ ),
+ },
+ },
+ })
+}
+
+func testAccCheckWebhookDestroy(s *terraform.State) error {
+ storeHash := testAccProvider.Meta().(string)
+ for _, rs := range s.RootModule().Resources {
+ if rs.Type != "bigcommerce_webhook" {
+ continue
+ }
+ accessToken := rs.Primary.Attributes["access_token"]
+ clientId := rs.Primary.Attributes["client_id"]
+ client := createBigCommerceClient(storeHash, clientId, accessToken)
+ webhookID, _ := strconv.ParseInt(rs.Primary.ID, 10, 64)
+ _, err := client.Webhooks.Get(webhookID)
+ if err == nil {
+ return fmt.Errorf("Webhookd still exists")
+ }
+ notFoundErr := "not found"
+ expectedErr := regexp.MustCompile(notFoundErr)
+ if !expectedErr.Match([]byte(err.Error())) {
+ return fmt.Errorf("expected %s, got %s", notFoundErr, err)
+ }
+ }
+
+ return nil
+}
+
+func testAccCheckExampleWebhookExists(resource string) resource.TestCheckFunc {
+ return func(state *terraform.State) error {
+ rs, ok := state.RootModule().Resources[resource]
+ if !ok {
+ return fmt.Errorf("Not found: %s", resource)
+ }
+ if rs.Primary.ID == "" {
+ return fmt.Errorf("No Record ID is set")
+ }
+ storeHash := testAccProvider.Meta().(string)
+ accessToken := rs.Primary.Attributes["access_token"]
+ clientId := rs.Primary.Attributes["client_id"]
+ client := createBigCommerceClient(storeHash, clientId, accessToken)
+ webhookID, _ := strconv.ParseInt(rs.Primary.ID, 10, 64)
+ _, err := client.Webhooks.Get(webhookID)
+ if err != nil {
+ return fmt.Errorf("error fetching webhook with resource %s. %s", resource, err)
+ }
+ return nil
+ }
+}
+
+func testAccCheckWebhookBasic() string {
+ return fmt.Sprintf(`
+resource "bigcommerce_webhook" "order_event" {
+ scope = "store/order/created"
+ client_id = "%s"
+ access_token = "%s"
+ destination = "https://127.0.0.1/test123"
+ is_active = true
+
+ header {
+ key = "X-Functions-Key"
+ value = "test123"
+ }
+}
+`, os.Getenv("BIGCOMMERCE_CLIENT_ID"), os.Getenv("BIGCOMMERCE_ACCESS_TOKEN"))
+}
+
+func testAccCheckSimpleWebhookUpdatePre() string {
+ return fmt.Sprintf(`
+resource "bigcommerce_webhook" "order_event_update" {
+ scope = "store/order/created"
+ client_id = "%s"
+ access_token = "%s"
+ destination = "https://127.0.0.1/test123"
+ is_active = true
+
+ header {
+ key = "X-Functions-Key"
+ value = "test123"
+ }
+}
+`, os.Getenv("BIGCOMMERCE_CLIENT_ID"), os.Getenv("BIGCOMMERCE_ACCESS_TOKEN"))
+}
+
+func testAccCheckSimpleWebhookUpdatePost() string {
+ return fmt.Sprintf(`
+resource "bigcommerce_webhook" "order_event_update" {
+ scope = "store/order/created"
+ client_id = "%s"
+ access_token = "%s"
+ destination = "https://127.0.0.1/test123"
+ is_active = false
+
+ header {
+ key = "X-Functions-Key"
+ value = "test123"
+ }
+}
+`, os.Getenv("BIGCOMMERCE_CLIENT_ID"), os.Getenv("BIGCOMMERCE_ACCESS_TOKEN"))
+}
+
+func testAccCheckWebhookUpdatePre() string {
+ return fmt.Sprintf(`
+resource "bigcommerce_webhook" "order_event_update" {
+ scope = "store/order/created"
+ client_id = "%s"
+ access_token = "%s"
+ destination = "https://127.0.0.1/test123"
+ is_active = true
+
+ header {
+ key = "X-Functions-Key"
+ value = "test123"
+ }
+}
+`, os.Getenv("PREV_BIGCOMMERCE_CLIENT_ID"), os.Getenv("PREV_BIGCOMMERCE_ACCESS_TOKEN"))
+}
+
+func testAccCheckWebhookUpdatePost() string {
+ return fmt.Sprintf(`
+resource "bigcommerce_webhook" "order_event_update" {
+ scope = "store/order/created"
+ client_id = "%s"
+ access_token = "%s"
+ destination = "https://127.0.0.1/test123"
+ is_active = true
+
+ header {
+ key = "X-Functions-Key"
+ value = "test123"
+ }
+}
+`, os.Getenv("BIGCOMMERCE_CLIENT_ID"), os.Getenv("BIGCOMMERCE_ACCESS_TOKEN"))
+}
+
+func testAccCheckWebhooksMultiple() string {
+ return fmt.Sprintf(`
+resource "bigcommerce_webhook" "order_event_multiple" {
+ scope = "store/order/created"
+ client_id = "%s"
+ access_token = "%s"
+ destination = "https://127.0.0.1/test123"
+ is_active = true
+
+ header {
+ key = "X-Functions-Key"
+ value = "test123"
+ }
+}
+
+resource "bigcommerce_webhook" "refund_event_multiple" {
+ scope = "store/order/refund/created"
+ client_id = "%s"
+ access_token = "%s"
+ destination = "https://127.0.0.1/test123"
+ is_active = true
+
+ header {
+ key = "X-Functions-Key"
+ value = "test123"
+ }
+ }
+`, os.Getenv("BIGCOMMERCE_CLIENT_ID"), os.Getenv("BIGCOMMERCE_ACCESS_TOKEN"), os.Getenv("BIGCOMMERCE_CLIENT_ID"), os.Getenv("BIGCOMMERCE_ACCESS_TOKEN"))
+}
diff --git a/docs/data-sources/webhook.md b/docs/data-sources/webhook.md
index f5f26e6..9a04ed1 100644
--- a/docs/data-sources/webhook.md
+++ b/docs/data-sources/webhook.md
@@ -23,18 +23,16 @@ data "bigcommerce_webhook" "example" {
### Required
+- **access_token** (String, Sensitive)
+- **client_id** (String, Sensitive)
- **id** (String) The ID of this resource.
### Read-only
-- **client_id** (String, Sensitive)
-- **created_at** (Number)
- **destination** (String)
- **header** (Block Set) (see [below for nested schema](#nestedblock--header))
- **is_active** (Boolean)
- **scope** (String)
-- **store_hash** (String, Sensitive)
-- **updated_at** (Number)
### Nested Schema for `header`
diff --git a/docs/index.md b/docs/index.md
index 1e059e9..3a4ecca 100644
--- a/docs/index.md
+++ b/docs/index.md
@@ -15,16 +15,12 @@ description: |-
```terraform
provider "bigcommerce" {
store_hash = "your-hash"
- client_id = "your-client-id"
- access_token = "your-access-token"
}
```
## Schema
-### Optional
+### Required
-- **access_token** (String, Sensitive)
-- **client_id** (String, Sensitive)
- **store_hash** (String)
diff --git a/docs/resources/webhook.md b/docs/resources/webhook.md
index 4dd3865..19b981c 100644
--- a/docs/resources/webhook.md
+++ b/docs/resources/webhook.md
@@ -15,6 +15,8 @@ Provides a BigCommerce Webhook resource.
```terraform
resource "bigcommerce_webhook" "example" {
scope = "store/customer/*"
+ access_token = "123123123"
+ client_id = "321321321"
destination = "https://foo.bar/webhook"
is_active = true
@@ -35,6 +37,8 @@ resource "bigcommerce_webhook" "example" {
### Required
+- **access_token** (String, Sensitive)
+- **client_id** (String, Sensitive)
- **destination** (String)
- **is_active** (Boolean)
- **scope** (String)
@@ -45,11 +49,7 @@ resource "bigcommerce_webhook" "example" {
### Read-only
-- **client_id** (String, Sensitive)
-- **created_at** (Number)
- **id** (String) The ID of this resource.
-- **store_hash** (String, Sensitive)
-- **updated_at** (Number)
### Nested Schema for `header`
diff --git a/go.mod b/go.mod
index 3aeecdd..729cb88 100644
--- a/go.mod
+++ b/go.mod
@@ -5,5 +5,5 @@ go 1.15
require (
github.com/ashsmith/bigcommerce-api-go v0.0.0-20210201235609-50ab2dc67830
github.com/hashicorp/terraform-plugin-docs v0.3.1
- github.com/hashicorp/terraform-plugin-sdk/v2 v2.4.1
+ github.com/hashicorp/terraform-plugin-sdk/v2 v2.4.4
)
diff --git a/go.sum b/go.sum
index 8157d4b..5a3f3ae 100644
--- a/go.sum
+++ b/go.sum
@@ -185,10 +185,13 @@ github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/hcl/v2 v2.3.0 h1:iRly8YaMwTBAKhn1Ybk7VSdzbnopghktCD031P8ggUE=
github.com/hashicorp/hcl/v2 v2.3.0/go.mod h1:d+FwDBbOLvpAM3Z6J7gPj/VoAGkNe/gm352ZhjJ/Zv8=
+github.com/hashicorp/logutils v1.0.0 h1:dLEQVugN8vlakKOUE3ihGLTZJRB4j+M2cdTm/ORI65Y=
github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64=
github.com/hashicorp/terraform-exec v0.9.0/go.mod h1:tOT8j1J8rP05bZBGWXfMyU3HkLi1LWyqL3Bzsc3CJjo=
github.com/hashicorp/terraform-exec v0.12.0 h1:Tb1VC2gqArl9EJziJjoazep2MyxMk00tnNKV/rgMba0=
github.com/hashicorp/terraform-exec v0.12.0/go.mod h1:SGhto91bVRlgXQWcJ5znSz+29UZIa8kpBbkGwQ+g9E8=
+github.com/hashicorp/terraform-exec v0.13.0 h1:1Pth+pdWJAufJuWWjaVOVNEkoRTOjGn3hQpAqj4aPdg=
+github.com/hashicorp/terraform-exec v0.13.0/go.mod h1:SGhto91bVRlgXQWcJ5znSz+29UZIa8kpBbkGwQ+g9E8=
github.com/hashicorp/terraform-json v0.5.0/go.mod h1:eAbqb4w0pSlRmdvl8fOyHAi/+8jnkVYN28gJkSJrLhU=
github.com/hashicorp/terraform-json v0.8.0 h1:XObQ3PgqU52YLQKEaJ08QtUshAfN3yu4u8ebSW0vztc=
github.com/hashicorp/terraform-json v0.8.0/go.mod h1:3defM4kkMfttwiE7VakJDwCd4R+umhSQnvJwORXbprE=
@@ -198,6 +201,8 @@ github.com/hashicorp/terraform-plugin-go v0.2.1 h1:EW/R8bB2Zbkjmugzsy1d27yS8/045
github.com/hashicorp/terraform-plugin-go v0.2.1/go.mod h1:10V6F3taeDWVAoLlkmArKttR3IULlRWFAGtQIQTIDr4=
github.com/hashicorp/terraform-plugin-sdk/v2 v2.4.1 h1:k2rpom9wG2cdi5iLRH80EdQB7UX/E6UzYzUfzgsNLuU=
github.com/hashicorp/terraform-plugin-sdk/v2 v2.4.1/go.mod h1:jgCWyjKf1BRqzuA3IPJb6PJ2YY86ePJurX9xfJtuYNU=
+github.com/hashicorp/terraform-plugin-sdk/v2 v2.4.4 h1:6k0WcxFgVqF/GUFHPvAH8FIrCkoA1RInXzSxhkKamPg=
+github.com/hashicorp/terraform-plugin-sdk/v2 v2.4.4/go.mod h1:z+cMZ0iswzZOahBJ3XmNWgWkVnAd2bl8g+FhyyuPDH4=
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d h1:kJCB4vdITiW1eC1vq2e6IsrXKrZit1bv/TDYFGMp4BQ=
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=