Skip to content

Commit

Permalink
Resolves #151 - Adds support for integrations (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
steve-r-west authored Nov 15, 2021
1 parent b0d2827 commit 21cf136
Show file tree
Hide file tree
Showing 13 changed files with 246 additions and 63 deletions.
32 changes: 16 additions & 16 deletions docs/data-sources/field.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,26 @@ Represents the EPCC API [Fields Object](https://documentation.elasticpath.com/co

### Required

- **id** (String) The ID for the field you are requesting.
- **id** (String) The unique identifier for this field.

### Read-Only

- **default** (String)
- **description** (String)
- **enabled** (Boolean)
- **field_type** (String)
- **flow_id** (String)
- **name** (String)
- **omit_null** (Boolean)
- **order** (Number)
- **default** (String) A default value if none is supplied and field is not required.
- **description** (String) Any description for this field.
- **enabled** (Boolean) If this field is enabled on the flow this should be true, otherwise false.
- **field_type** (String) Specifies the type of field, such as string, integer, boolean, float, date, relationship.
- **flow_id** (String) The id of the flow that this field applies to.
- **name** (String) The name of the field.
- **omit_null** (Boolean) Hide this field from responses if the value is null.
- **order** (Number) Denotes the order in which this field is returned relative to the rest of the flow fields.
- **relationship_to_many** (String)
- **relationship_to_one** (String)
- **required** (Boolean)
- **slug** (String)
- **valid_float_enum** (List of Number)
- **required** (Boolean) true if required on input, false if not. Always false if the field_type is a relationship.
- **slug** (String) A unique slug identifier for the field.
- **valid_float_enum** (List of Number) A predefined collection of floats that represent the allowed value for this float field.
- **valid_float_range** (List of Map of Number)
- **valid_int_enum** (List of Number)
- **valid_int_range** (List of Map of Number)
- **valid_string_enum** (List of String)
- **valid_string_format** (String)
- **valid_int_enum** (List of Number) A predefined collection of integer that represent the allowed value for this integer field.
- **valid_int_range** (List of Map of Number) A list of integers specified with from= and to= that represent the range of this value
- **valid_string_enum** (List of String) A predefined collection of strings that represent the allowed value for this string field.
- **valid_string_format** (String) Corresponds to the field validation rules for string, one of "email", "slug", or "uuid".

10 changes: 5 additions & 5 deletions docs/data-sources/flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ Represents the EPCC API [Flow Object](https://documentation.elasticpath.com/comm

### Required

- **id** (String) The ID of this resource.
- **id** (String) The unique identifier for this flow.

### Read-Only

- **description** (String)
- **enabled** (Boolean)
- **name** (String)
- **slug** (String)
- **description** (String) Any description for this flow.
- **enabled** (Boolean) true if enabled, false if not.
- **name** (String) The name of the flow.
- **slug** (String) A unique slug identifier for the flow.

4 changes: 4 additions & 0 deletions docs/data-sources/integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ Allows to configure webhooks

### Read-Only

- **aws_access_key_id** (String) The required AWS access key ID. Note: The EPCC API only returns the 4 characters of this value
- **aws_secret_access_key** (String, Sensitive) The required AWS secret key ID. Note: The EPCC API only returns the 4 characters of this value
- **description** (String)
- **enabled** (Boolean) Should the event trigger or not. Default: `false`
- **integration_type** (String) Specifies how the event is delivered, either webhook or aws_sqs
- **name** (String)
- **observes** (List of String) [observable event type](https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/events/create-an-event.html)
- **region** (String) The required AWS region.
- **secret_key** (String) Value that is passed to webhook as `X-Moltin-Secret-Key` header
- **url** (String) Webhook endpoint

10 changes: 5 additions & 5 deletions docs/resources/account.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ Represents the EPCC API [Account resource](https://documentation.elasticpath.com

### Required

- **legal_name** (String)
- **name** (String)
- **legal_name** (String) The legal name of the account.
- **name** (String) The name of the account.

### Optional

- **parent_id** (String)
- **registration_id** (String)
- **parent_id** (String) Specifies the ID of the parent account.
- **registration_id** (String) The registration ID of the account.

### Read-Only

- **id** (String) The ID of this resource.
- **id** (String) The unique identifier for an Account

32 changes: 16 additions & 16 deletions docs/resources/field.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,29 @@ Represents the EPCC API [Fields Object](https://documentation.elasticpath.com/co

### Required

- **description** (String)
- **enabled** (Boolean)
- **field_type** (String)
- **flow_id** (String)
- **name** (String)
- **required** (Boolean)
- **slug** (String)
- **description** (String) Any description for this field.
- **enabled** (Boolean) If this field is enabled on the flow this should be true, otherwise false.
- **field_type** (String) Specifies the type of field, such as string, integer, boolean, float, date, relationship.
- **flow_id** (String) The id of the flow that this field applies to.
- **name** (String) The name of the field.
- **required** (Boolean) true if required on input, false if not. Always false if the field_type is a relationship.
- **slug** (String) A unique slug identifier for the field.

### Optional

- **default** (String)
- **omit_null** (Boolean)
- **order** (Number)
- **default** (String) A default value if none is supplied and field is not required.
- **omit_null** (Boolean) Hide this field from responses if the value is null.
- **order** (Number) Denotes the order in which this field is returned relative to the rest of the flow fields.
- **relationship_to_many** (String)
- **relationship_to_one** (String)
- **valid_float_enum** (List of Number)
- **valid_float_enum** (List of Number) A predefined collection of floats that represent the allowed value for this float field.
- **valid_float_range** (List of Map of Number)
- **valid_int_enum** (List of Number)
- **valid_int_range** (List of Map of Number)
- **valid_string_enum** (List of String)
- **valid_string_format** (String)
- **valid_int_enum** (List of Number) A predefined collection of integer that represent the allowed value for this integer field.
- **valid_int_range** (List of Map of Number) A list of integers specified with from= and to= that represent the range of this value
- **valid_string_enum** (List of String) A predefined collection of strings that represent the allowed value for this string field.
- **valid_string_format** (String) Corresponds to the field validation rules for string, one of "email", "slug", or "uuid".

### Read-Only

- **id** (String) The ID of this resource.
- **id** (String) The unique identifier for this field.

10 changes: 5 additions & 5 deletions docs/resources/flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ Represents the EPCC API [Flow Object](https://documentation.elasticpath.com/comm

### Required

- **description** (String)
- **enabled** (Boolean)
- **name** (String)
- **slug** (String)
- **description** (String) Any description for this flow.
- **enabled** (Boolean) true if enabled, false if not.
- **name** (String) The name of the flow.
- **slug** (String) A unique slug identifier for the flow.

### Read-Only

- **id** (String) The ID of this resource.
- **id** (String) The unique identifier for this flow.

4 changes: 4 additions & 0 deletions docs/resources/integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@ Allows to configure webhooks, and corresponds to EPCC API [Event (Webhooks) Obje

### Required

- **integration_type** (String) Specifies how the event is delivered, either webhook or aws_sqs
- **name** (String)
- **url** (String) Webhook endpoint

### Optional

- **aws_access_key_id** (String) The required AWS access key ID. Note: The EPCC API only returns the 4 characters of this value
- **aws_secret_access_key** (String, Sensitive) The required AWS secret key ID. Note: The EPCC API only returns the 4 characters of this value
- **description** (String)
- **enabled** (Boolean) Should the event trigger or not. Default: `false`
- **observes** (List of String) [observable event type](https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/events/create-an-event.html)
- **region** (String) The required AWS region.
- **secret_key** (String) Value that is passed to webhook as `X-Moltin-Secret-Key` header

### Read-Only
Expand Down
7 changes: 6 additions & 1 deletion examples/resources/integration_resource/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ terraform {

resource "epcc_integration" "cart_observer" {
name = "Cart Observer"
url = "http://localhost"
url = "https://sqs.us-east-2.amazonaws.com/123456789012/MyQueue"
observes = [
"cart.updated",
"cart.deleted",
]
integration_type = "aws_sqs"
region = "us-east-2"
aws_access_key_id = "foofoofoofoofoo"
aws_secret_access_key = "barbarbarbarbar"
enabled = true
}
17 changes: 8 additions & 9 deletions external/sdk/epcc/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,21 @@ type IntegrationData struct {
}

type IntegrationConfiguration struct {
Url string `json:"url"`
SecretKey string `json:"secret_key,omitempty"`
Url string `json:"url"`
SecretKey string `json:"secret_key,omitempty"`
AwsAccessKeyId string `json:"aws_access_key_id,omitempty"`
AwsSecretAccessKey string `json:"aws_secret_access_key,omitempty"`
Region string `json:"region,omitempty"`
}

type integrationObjectType string
type integrationType string

const (
IntegrationType integrationObjectType = "integration"
Webhook integrationType = "webhook"
IntegrationType string = "integration"
)

type Integration struct {
Id string `json:"id,omitempty"`
Type integrationObjectType `json:"type"`
IntegrationType integrationType `json:"integration_type"`
Type string `json:"type"`
IntegrationType string `json:"integration_type"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
Enabled bool `json:"enabled"`
Expand Down
41 changes: 41 additions & 0 deletions internal/provider/data_source_epcc_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,27 @@ func (ds IntegrationDataSourceProvider) DataSource() *schema.Resource {
Description: "[observable event type](https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/events/create-an-event.html)",
Computed: true,
},
"integration_type": {
Type: schema.TypeString,
Description: "Specifies how the event is delivered, either webhook or aws_sqs",
Computed: true,
},
"aws_access_key_id": {
Type: schema.TypeString,
Description: "The required AWS access key ID. Note: The EPCC API only returns the 4 characters of this value",
Computed: true,
},
"aws_secret_access_key": {
Type: schema.TypeString,
Description: "The required AWS secret key ID. Note: The EPCC API only returns the 4 characters of this value",
Computed: true,
Sensitive: true,
},
"region": {
Type: schema.TypeString,
Description: "The required AWS region.",
Computed: true,
},
},
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
Expand Down Expand Up @@ -96,5 +117,25 @@ func (ds IntegrationDataSourceProvider) read(ctx context.Context, data *schema.R
return
}

if err := data.Set("integration_type", result.Data.IntegrationType); err != nil {
addToDiag(ctx, diag.FromErr(err))
return
}

if err := data.Set("aws_access_key_id", result.Data.Configuration.AwsAccessKeyId); err != nil {
addToDiag(ctx, diag.FromErr(err))
return
}

if err := data.Set("aws_secret_access_key", result.Data.Configuration.AwsSecretAccessKey); err != nil {
addToDiag(ctx, diag.FromErr(err))
return
}

if err := data.Set("region", result.Data.Configuration.Region); err != nil {
addToDiag(ctx, diag.FromErr(err))
return
}

data.SetId(result.Data.Id)
}
Loading

0 comments on commit 21cf136

Please sign in to comment.