From 0f1bf9991255ca6d5f8791756aa4f47c21893095 Mon Sep 17 00:00:00 2001 From: Yury Mikhailenko <61891832+yurymikhailenko@users.noreply.github.com> Date: Sun, 30 May 2021 22:12:22 -0700 Subject: [PATCH] flow entry must work with core flows and all primitive types (#121) --- GNUmakefile | 12 +- .../customer_authentication_settings.md | 16 -- .../{account.md => epcc_account.md} | 2 +- ...> epcc_account_authentication_settings.md} | 15 +- .../{catalog.md => epcc_catalog.md} | 2 +- .../{catalog_rule.md => epcc_catalog_rule.md} | 2 +- .../{currency.md => epcc_currency.md} | 2 +- .../{customer.md => epcc_customer.md} | 2 +- .../epcc_customer_authentication_settings.md | 25 +++ docs/data-sources/{entry.md => epcc_entry.md} | 8 +- docs/data-sources/{field.md => epcc_field.md} | 2 +- docs/data-sources/{file.md => epcc_file.md} | 2 +- docs/data-sources/{flow.md => epcc_flow.md} | 2 +- .../{hierarchy.md => epcc_hierarchy.md} | 2 +- .../{integration.md => epcc_integration.md} | 2 +- docs/data-sources/{node.md => epcc_node.md} | 2 +- .../{node_product.md => epcc_node_product.md} | 2 +- ...ent_gateway.md => epcc_payment_gateway.md} | 2 +- .../{pricebook.md => epcc_pricebook.md} | 2 +- .../{product.md => epcc_product.md} | 2 +- ...product_price.md => epcc_product_price.md} | 2 +- .../{profile.md => epcc_profile.md} | 2 +- .../{promotion.md => epcc_promotion.md} | 2 +- docs/data-sources/{realm.md => epcc_realm.md} | 2 +- ...fo.md => epcc_user_authentication_info.md} | 2 +- docs/index.md | 18 +- .../resources/{account.md => epcc_account.md} | 2 +- .../resources/{catalog.md => epcc_catalog.md} | 2 +- .../{catalog_rule.md => epcc_catalog_rule.md} | 2 +- .../{currency.md => epcc_currency.md} | 2 +- .../{customer.md => epcc_customer.md} | 2 +- docs/resources/{entry.md => epcc_entry.md} | 10 +- docs/resources/{field.md => epcc_field.md} | 2 +- docs/resources/{file.md => epcc_file.md} | 6 +- docs/resources/{flow.md => epcc_flow.md} | 2 +- .../{hierarchy.md => epcc_hierarchy.md} | 2 +- .../{integration.md => epcc_integration.md} | 2 +- docs/resources/{node.md => epcc_node.md} | 2 +- .../{node_product.md => epcc_node_product.md} | 2 +- ...ent_gateway.md => epcc_payment_gateway.md} | 2 +- .../{pricebook.md => epcc_pricebook.md} | 2 +- .../resources/{product.md => epcc_product.md} | 2 +- ...product_price.md => epcc_product_price.md} | 2 +- .../resources/{profile.md => epcc_profile.md} | 2 +- .../{promotion.md => epcc_promotion.md} | 2 +- docs/resources/{realm.md => epcc_realm.md} | 2 +- ...fo.md => epcc_user_authentication_info.md} | 2 +- .../entry_data_source/datasource.tf | 12 +- examples/resources/entry_resource/resource.tf | 41 ++--- external/sdk/epcc/entry.go | 137 ++++++++++++--- external/sdk/epcc/field.go | 8 - external/sdk/epcc/resource_extension.go | 27 +-- internal/provider/data_source_epcc_entry.go | 59 +++++-- internal/provider/provider.go | 4 +- internal/provider/resource_epcc_entry.go | 156 +++++++++++++----- internal/provider/resource_epcc_entry_test.go | 123 ++++++++------ internal/provider/util.go | 16 ++ 57 files changed, 499 insertions(+), 272 deletions(-) delete mode 100644 docs/data-sources/customer_authentication_settings.md rename docs/data-sources/{account.md => epcc_account.md} (90%) rename docs/data-sources/{account_authentication_settings.md => epcc_account_authentication_settings.md} (54%) rename docs/data-sources/{catalog.md => epcc_catalog.md} (89%) rename docs/data-sources/{catalog_rule.md => epcc_catalog_rule.md} (89%) rename docs/data-sources/{currency.md => epcc_currency.md} (91%) rename docs/data-sources/{customer.md => epcc_customer.md} (89%) create mode 100644 docs/data-sources/epcc_customer_authentication_settings.md rename docs/data-sources/{entry.md => epcc_entry.md} (74%) rename docs/data-sources/{field.md => epcc_field.md} (94%) rename docs/data-sources/{file.md => epcc_file.md} (90%) rename docs/data-sources/{flow.md => epcc_flow.md} (90%) rename docs/data-sources/{hierarchy.md => epcc_hierarchy.md} (88%) rename docs/data-sources/{integration.md => epcc_integration.md} (90%) rename docs/data-sources/{node.md => epcc_node.md} (90%) rename docs/data-sources/{node_product.md => epcc_node_product.md} (89%) rename docs/data-sources/{payment_gateway.md => epcc_payment_gateway.md} (85%) rename docs/data-sources/{pricebook.md => epcc_pricebook.md} (88%) rename docs/data-sources/{product.md => epcc_product.md} (94%) rename docs/data-sources/{product_price.md => epcc_product_price.md} (91%) rename docs/data-sources/{profile.md => epcc_profile.md} (90%) rename docs/data-sources/{promotion.md => epcc_promotion.md} (95%) rename docs/data-sources/{realm.md => epcc_realm.md} (90%) rename docs/data-sources/{user_authentication_info.md => epcc_user_authentication_info.md} (79%) rename docs/resources/{account.md => epcc_account.md} (90%) rename docs/resources/{catalog.md => epcc_catalog.md} (90%) rename docs/resources/{catalog_rule.md => epcc_catalog_rule.md} (89%) rename docs/resources/{currency.md => epcc_currency.md} (91%) rename docs/resources/{customer.md => epcc_customer.md} (89%) rename docs/resources/{entry.md => epcc_entry.md} (64%) rename docs/resources/{field.md => epcc_field.md} (94%) rename docs/resources/{file.md => epcc_file.md} (70%) rename docs/resources/{flow.md => epcc_flow.md} (90%) rename docs/resources/{hierarchy.md => epcc_hierarchy.md} (89%) rename docs/resources/{integration.md => epcc_integration.md} (93%) rename docs/resources/{node.md => epcc_node.md} (90%) rename docs/resources/{node_product.md => epcc_node_product.md} (90%) rename docs/resources/{payment_gateway.md => epcc_payment_gateway.md} (87%) rename docs/resources/{pricebook.md => epcc_pricebook.md} (89%) rename docs/resources/{product.md => epcc_product.md} (94%) rename docs/resources/{product_price.md => epcc_product_price.md} (91%) rename docs/resources/{profile.md => epcc_profile.md} (90%) rename docs/resources/{promotion.md => epcc_promotion.md} (96%) rename docs/resources/{realm.md => epcc_realm.md} (91%) rename docs/resources/{user_authentication_info.md => epcc_user_authentication_info.md} (81%) diff --git a/GNUmakefile b/GNUmakefile index e0d5498..b284cbb 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -69,14 +69,14 @@ clean: .PHONY: testacc testacc: (\ - set -o allexport && [[ -f .env ]] && source ./.env && set +o allexport && \ + set -o allexport && [[ -f .env ]] && source .env && set +o allexport || true ; \ TF_ACC=1 go test ./... -v $(TESTARGS) -timeout 120m \ ) .PHONY: example example: install (\ - set -o allexport && [[ -f .env ]] && source ./.env && set +o allexport && \ + set -o allexport && [[ -f .env ]] && source .env && set +o allexport || true ; \ pushd $(EXAMPLE) && \ (rm .terraform.lock.hcl || true) && \ terraform init && \ @@ -87,7 +87,7 @@ example: install .PHONY: example resource: install (\ - set -o allexport && [[ -f .env ]] && source ./.env && set +o allexport && \ + set -o allexport && [[ -f .env ]] && source .env && set +o allexport || true ; \ pushd examples/resources/$(TYPE)_resource && \ (rm .terraform.lock.hcl || true) && \ terraform init && \ @@ -98,7 +98,7 @@ resource: install .PHONY: example data-source: install (\ - set -o allexport && [[ -f .env ]] && source ./.env && set +o allexport && \ + set -o allexport && [[ -f .env ]] && source .env && set +o allexport || true ; \ pushd examples/data-sources/$(TYPE)_data_source && \ (rm .terraform.lock.hcl || true) && \ terraform init && \ @@ -110,11 +110,11 @@ data-source: install .PHONY: docs docs: install (\ - set -o allexport && [[ -f .env ]] && source .env && set +o allexport && \ + set -o allexport && [[ -f .env ]] && source .env && set +o allexport || true ; \ (rm .terraform.lock.hcl || true) && \ terraform init && \ go generate \ ) prepare: - ( terraform fmt -recursive && go fmt ./... && go generate) \ No newline at end of file + ( terraform fmt -recursive && go fmt ./... && go generate) diff --git a/docs/data-sources/customer_authentication_settings.md b/docs/data-sources/customer_authentication_settings.md deleted file mode 100644 index e00deb2..0000000 --- a/docs/data-sources/customer_authentication_settings.md +++ /dev/null @@ -1,16 +0,0 @@ ---- -page_title: "epcc_customer_authentication_settings Data Source - terraform-provider-epcc" -subcategory: "" -description: |- Represents the EPCC API [Customer Authentication Settings] (https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/settings/customer-authentication-settings/index.html) ---- - -# Data Source `epcc_customer_authentication_settings` - -Represents the EPCC API Customer Authentication Settings - -## Schema - -### Read-only - -- **realm_id** (String) -- **client_id** (String) \ No newline at end of file diff --git a/docs/data-sources/account.md b/docs/data-sources/epcc_account.md similarity index 90% rename from docs/data-sources/account.md rename to docs/data-sources/epcc_account.md index 3766b52..8191033 100644 --- a/docs/data-sources/account.md +++ b/docs/data-sources/epcc_account.md @@ -1,5 +1,5 @@ --- -page_title: "epcc_account Data Source - terraform-provider-epcc" +page_title: "epcc_account Data Source - epcc-terraform-provider" subcategory: "" description: |- Represents the EPCC API Account resource https://documentation.elasticpath.com/commerce-cloud/docs/api/account-management/accounts/index.html#the-account-object. diff --git a/docs/data-sources/account_authentication_settings.md b/docs/data-sources/epcc_account_authentication_settings.md similarity index 54% rename from docs/data-sources/account_authentication_settings.md rename to docs/data-sources/epcc_account_authentication_settings.md index fba1fb5..5ce6d24 100644 --- a/docs/data-sources/account_authentication_settings.md +++ b/docs/data-sources/epcc_account_authentication_settings.md @@ -1,16 +1,25 @@ --- -page_title: "epcc_account_authentication_settings Data Source - terraform-provider-epcc" +page_title: "epcc_account_authentication_settings Data Source - epcc-terraform-provider" subcategory: "" -description: |- Represents the EPCC API Account Authentication Settings +description: |- + Represents the EPCC API Account Authentication Settings https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/settings/account-authentication-settings/index.html --- # Data Source `epcc_account_authentication_settings` Represents the EPCC API [Account Authentication Settings] (https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/settings/account-authentication-settings/index.html) + + ## Schema +### Optional + +- **id** (String) The ID of this resource. + ### Read-only +- **client_id** (String) - **realm_id** (String) -- **client_id** (String) \ No newline at end of file + + diff --git a/docs/data-sources/catalog.md b/docs/data-sources/epcc_catalog.md similarity index 89% rename from docs/data-sources/catalog.md rename to docs/data-sources/epcc_catalog.md index 3959c59..69ed472 100644 --- a/docs/data-sources/catalog.md +++ b/docs/data-sources/epcc_catalog.md @@ -1,5 +1,5 @@ --- -page_title: "epcc_catalog Data Source - terraform-provider-epcc" +page_title: "epcc_catalog Data Source - epcc-terraform-provider" subcategory: "" description: |- Represents the EPCC API PCM Catalog Object https://documentation.elasticpath.com/commerce-cloud/docs/api/pcm/catalogs/index.html#the-catalog-object. diff --git a/docs/data-sources/catalog_rule.md b/docs/data-sources/epcc_catalog_rule.md similarity index 89% rename from docs/data-sources/catalog_rule.md rename to docs/data-sources/epcc_catalog_rule.md index 04c1d00..c8f7b8b 100644 --- a/docs/data-sources/catalog_rule.md +++ b/docs/data-sources/epcc_catalog_rule.md @@ -1,5 +1,5 @@ --- -page_title: "epcc_catalog_rule Data Source - terraform-provider-epcc" +page_title: "epcc_catalog_rule Data Source - epcc-terraform-provider" subcategory: "" description: |- Represents the EPCC API PCM Catalog Rule Object https://documentation.elasticpath.com/commerce-cloud/docs/api/pcm/catalogs/rules/get-a-catalog-rule.html. diff --git a/docs/data-sources/currency.md b/docs/data-sources/epcc_currency.md similarity index 91% rename from docs/data-sources/currency.md rename to docs/data-sources/epcc_currency.md index d2599b6..5c105c1 100644 --- a/docs/data-sources/currency.md +++ b/docs/data-sources/epcc_currency.md @@ -1,5 +1,5 @@ --- -page_title: "epcc_currency Data Source - terraform-provider-epcc" +page_title: "epcc_currency Data Source - epcc-terraform-provider" subcategory: "" description: |- Represents the EPCC API Currency Object https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/currencies/index.html#the-currency-object. diff --git a/docs/data-sources/customer.md b/docs/data-sources/epcc_customer.md similarity index 89% rename from docs/data-sources/customer.md rename to docs/data-sources/epcc_customer.md index f1cdb20..e3890fa 100644 --- a/docs/data-sources/customer.md +++ b/docs/data-sources/epcc_customer.md @@ -1,5 +1,5 @@ --- -page_title: "epcc_customer Data Source - terraform-provider-epcc" +page_title: "epcc_customer Data Source - epcc-terraform-provider" subcategory: "" description: |- Represents the EPCC API Customer Object https://documentation.elasticpath.com/commerce-cloud/docs/api/orders-and-customers/customers/index.html#the-customer-object. diff --git a/docs/data-sources/epcc_customer_authentication_settings.md b/docs/data-sources/epcc_customer_authentication_settings.md new file mode 100644 index 0000000..74323d2 --- /dev/null +++ b/docs/data-sources/epcc_customer_authentication_settings.md @@ -0,0 +1,25 @@ +--- +page_title: "epcc_customer_authentication_settings Data Source - epcc-terraform-provider" +subcategory: "" +description: |- + Represents the EPCC API Customer Authentication Settings https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/settings/customer-authentication-settings/index.html +--- + +# Data Source `epcc_customer_authentication_settings` + +Represents the EPCC API [Customer Authentication Settings] (https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/settings/customer-authentication-settings/index.html) + + + +## Schema + +### Optional + +- **id** (String) The ID of this resource. + +### Read-only + +- **client_id** (String) +- **realm_id** (String) + + diff --git a/docs/data-sources/entry.md b/docs/data-sources/epcc_entry.md similarity index 74% rename from docs/data-sources/entry.md rename to docs/data-sources/epcc_entry.md index 77c8470..ebbeceb 100644 --- a/docs/data-sources/entry.md +++ b/docs/data-sources/epcc_entry.md @@ -1,5 +1,5 @@ --- -page_title: "epcc_entry Data Source - terraform-provider-epcc" +page_title: "epcc_entry Data Source - epcc-terraform-provider" subcategory: "" description: |- Represents the EPCC API Entry Object https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/custom-data/entries/index.html. @@ -16,10 +16,12 @@ Represents the EPCC API [Entry Object](https://documentation.elasticpath.com/com ### Required - **id** (String) The ID of this resource. -- **payload** (Map of String) +- **slug** (String) ### Read-only -- **slug** (String) +- **booleans** (Map of Boolean) +- **numbers** (Map of Number) +- **strings** (Map of String) diff --git a/docs/data-sources/field.md b/docs/data-sources/epcc_field.md similarity index 94% rename from docs/data-sources/field.md rename to docs/data-sources/epcc_field.md index 9d85959..ce967f6 100644 --- a/docs/data-sources/field.md +++ b/docs/data-sources/epcc_field.md @@ -1,5 +1,5 @@ --- -page_title: "epcc_field Data Source - terraform-provider-epcc" +page_title: "epcc_field Data Source - epcc-terraform-provider" subcategory: "" description: |- Represents the EPCC API Fields Object https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/custom-data/fields/index.html. diff --git a/docs/data-sources/file.md b/docs/data-sources/epcc_file.md similarity index 90% rename from docs/data-sources/file.md rename to docs/data-sources/epcc_file.md index 256e45b..b4ed5ee 100644 --- a/docs/data-sources/file.md +++ b/docs/data-sources/epcc_file.md @@ -1,5 +1,5 @@ --- -page_title: "epcc_file Data Source - terraform-provider-epcc" +page_title: "epcc_file Data Source - epcc-terraform-provider" subcategory: "" description: |- Represents the EPCC API File Object https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/files/index.html#the-file-object. diff --git a/docs/data-sources/flow.md b/docs/data-sources/epcc_flow.md similarity index 90% rename from docs/data-sources/flow.md rename to docs/data-sources/epcc_flow.md index 6f747a5..d784178 100644 --- a/docs/data-sources/flow.md +++ b/docs/data-sources/epcc_flow.md @@ -1,5 +1,5 @@ --- -page_title: "epcc_flow Data Source - terraform-provider-epcc" +page_title: "epcc_flow Data Source - epcc-terraform-provider" subcategory: "" description: |- Represents the EPCC API Flow Object https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/custom-data/flows/index.html#the-flow-object. diff --git a/docs/data-sources/hierarchy.md b/docs/data-sources/epcc_hierarchy.md similarity index 88% rename from docs/data-sources/hierarchy.md rename to docs/data-sources/epcc_hierarchy.md index 6af2390..5542a4c 100644 --- a/docs/data-sources/hierarchy.md +++ b/docs/data-sources/epcc_hierarchy.md @@ -1,5 +1,5 @@ --- -page_title: "epcc_hierarchy Data Source - terraform-provider-epcc" +page_title: "epcc_hierarchy Data Source - epcc-terraform-provider" subcategory: "" description: |- Represents the EPCC API Hierarchy Object https://documentation.elasticpath.com/commerce-cloud/docs/api/pcm/hierarchies/index.html#the-hierarchy-object. diff --git a/docs/data-sources/integration.md b/docs/data-sources/epcc_integration.md similarity index 90% rename from docs/data-sources/integration.md rename to docs/data-sources/epcc_integration.md index 679991a..e2b8075 100644 --- a/docs/data-sources/integration.md +++ b/docs/data-sources/epcc_integration.md @@ -1,5 +1,5 @@ --- -page_title: "epcc_integration Data Source - terraform-provider-epcc" +page_title: "epcc_integration Data Source - epcc-terraform-provider" subcategory: "" description: |- Allows to configure webhooks diff --git a/docs/data-sources/node.md b/docs/data-sources/epcc_node.md similarity index 90% rename from docs/data-sources/node.md rename to docs/data-sources/epcc_node.md index 07c99c7..3ca0813 100644 --- a/docs/data-sources/node.md +++ b/docs/data-sources/epcc_node.md @@ -1,5 +1,5 @@ --- -page_title: "epcc_node Data Source - terraform-provider-epcc" +page_title: "epcc_node Data Source - epcc-terraform-provider" subcategory: "" description: |- Represents the EPCC API Node Object https://documentation.elasticpath.com/commerce-cloud/docs/api/pcm/hierarchies/index.html#the-node-object. diff --git a/docs/data-sources/node_product.md b/docs/data-sources/epcc_node_product.md similarity index 89% rename from docs/data-sources/node_product.md rename to docs/data-sources/epcc_node_product.md index b3da614..be015aa 100644 --- a/docs/data-sources/node_product.md +++ b/docs/data-sources/epcc_node_product.md @@ -1,5 +1,5 @@ --- -page_title: "epcc_node_product Data Source - terraform-provider-epcc" +page_title: "epcc_node_product Data Source - epcc-terraform-provider" subcategory: "" description: |- Represents the EPCC API Node and Product Relationship https://documentation.elasticpath.com/commerce-cloud/docs/api/pcm/hierarchies/relationships/create-node-product-relationships.html. diff --git a/docs/data-sources/payment_gateway.md b/docs/data-sources/epcc_payment_gateway.md similarity index 85% rename from docs/data-sources/payment_gateway.md rename to docs/data-sources/epcc_payment_gateway.md index 85f3022..f2ef3ef 100644 --- a/docs/data-sources/payment_gateway.md +++ b/docs/data-sources/epcc_payment_gateway.md @@ -1,5 +1,5 @@ --- -page_title: "epcc_payment_gateway Data Source - terraform-provider-epcc" +page_title: "epcc_payment_gateway Data Source - epcc-terraform-provider" subcategory: "" description: |- Payment gateway connectivity configuration diff --git a/docs/data-sources/pricebook.md b/docs/data-sources/epcc_pricebook.md similarity index 88% rename from docs/data-sources/pricebook.md rename to docs/data-sources/epcc_pricebook.md index e21899c..69e0c85 100644 --- a/docs/data-sources/pricebook.md +++ b/docs/data-sources/epcc_pricebook.md @@ -1,5 +1,5 @@ --- -page_title: "epcc_pricebook Data Source - terraform-provider-epcc" +page_title: "epcc_pricebook Data Source - epcc-terraform-provider" subcategory: "" description: |- Represents the EPCC API PriceBook Object https://documentation.elasticpath.com/commerce-cloud/docs/api/pcm/pricebooks/index.html#the-pricebook-object. diff --git a/docs/data-sources/product.md b/docs/data-sources/epcc_product.md similarity index 94% rename from docs/data-sources/product.md rename to docs/data-sources/epcc_product.md index a898f49..30a2549 100644 --- a/docs/data-sources/product.md +++ b/docs/data-sources/epcc_product.md @@ -1,5 +1,5 @@ --- -page_title: "epcc_product Data Source - terraform-provider-epcc" +page_title: "epcc_product Data Source - epcc-terraform-provider" subcategory: "" description: |- Allows the caller to look up details of an Elastic Path Commerce Cloud PCM product https://documentation.elasticpath.com/commerce-cloud/docs/concepts/products-pcm.html. diff --git a/docs/data-sources/product_price.md b/docs/data-sources/epcc_product_price.md similarity index 91% rename from docs/data-sources/product_price.md rename to docs/data-sources/epcc_product_price.md index 843c78c..6e6cf6a 100644 --- a/docs/data-sources/product_price.md +++ b/docs/data-sources/epcc_product_price.md @@ -1,5 +1,5 @@ --- -page_title: "epcc_product_price Data Source - terraform-provider-epcc" +page_title: "epcc_product_price Data Source - epcc-terraform-provider" subcategory: "" description: |- Represents the EPCC API Price Object https://documentation.elasticpath.com/commerce-cloud/docs/api/pcm/pricebooks/prices/create-product-prices.html. diff --git a/docs/data-sources/profile.md b/docs/data-sources/epcc_profile.md similarity index 90% rename from docs/data-sources/profile.md rename to docs/data-sources/epcc_profile.md index 36a3adb..0c05aa9 100644 --- a/docs/data-sources/profile.md +++ b/docs/data-sources/epcc_profile.md @@ -1,5 +1,5 @@ --- -page_title: "epcc_profile Data Source - terraform-provider-epcc" +page_title: "epcc_profile Data Source - epcc-terraform-provider" subcategory: "" description: |- Represents the EPCC API OpenID Connect Profiles https://documentation.elasticpath.com/commerce-cloud/docs/api/single-sign-on/oidc-profiles/index.html. diff --git a/docs/data-sources/promotion.md b/docs/data-sources/epcc_promotion.md similarity index 95% rename from docs/data-sources/promotion.md rename to docs/data-sources/epcc_promotion.md index 395b94a..1186103 100644 --- a/docs/data-sources/promotion.md +++ b/docs/data-sources/epcc_promotion.md @@ -1,5 +1,5 @@ --- -page_title: "epcc_promotion Data Source - terraform-provider-epcc" +page_title: "epcc_promotion Data Source - epcc-terraform-provider" subcategory: "" description: |- Represents the EPCC API Promotion Object https://documentation.elasticpath.com/commerce-cloud/docs/api/carts-and-checkout/promotions/index.html#the-promotion-object. diff --git a/docs/data-sources/realm.md b/docs/data-sources/epcc_realm.md similarity index 90% rename from docs/data-sources/realm.md rename to docs/data-sources/epcc_realm.md index 876a5ca..32fa881 100644 --- a/docs/data-sources/realm.md +++ b/docs/data-sources/epcc_realm.md @@ -1,5 +1,5 @@ --- -page_title: "epcc_realm Data Source - terraform-provider-epcc" +page_title: "epcc_realm Data Source - epcc-terraform-provider" subcategory: "" description: |- Represents the EPCC API Authentication Realms https://documentation.elasticpath.com/commerce-cloud/docs/api/single-sign-on/authentication-realms/index.html. diff --git a/docs/data-sources/user_authentication_info.md b/docs/data-sources/epcc_user_authentication_info.md similarity index 79% rename from docs/data-sources/user_authentication_info.md rename to docs/data-sources/epcc_user_authentication_info.md index 28582de..24f8a4d 100644 --- a/docs/data-sources/user_authentication_info.md +++ b/docs/data-sources/epcc_user_authentication_info.md @@ -1,5 +1,5 @@ --- -page_title: "epcc_user_authentication_info Data Source - terraform-provider-epcc" +page_title: "epcc_user_authentication_info Data Source - epcc-terraform-provider" subcategory: "" description: |- Represents the EPCC API User Authentication Info diff --git a/docs/index.md b/docs/index.md index 589e4c5..c763960 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,19 +1,29 @@ --- -page_title: "epcc Provider" +page_title: "epcc-terraform-provider Provider" subcategory: "" description: |- --- -# epcc Provider +# epcc-terraform-provider Provider ## Example Usage ```terraform -provider "scaffolding" { - # example configuration here +provider "epcc" { + // Can set via `EPCC_CLIENT_ID` environment variable. + client_id = "some_client_id" + + // Can set via `EPCC_CLIENT_SECRET` environment variable. + client_secret = "some_client_secret" + + // Can set via `EPCC_API_BASE_URL` environment variable + api_base_url = "https://api.moltin.com/" + + // Can set via `EPCC_BETA_API_FEATURES` environment variable. + beta_features = "account-management" } ``` diff --git a/docs/resources/account.md b/docs/resources/epcc_account.md similarity index 90% rename from docs/resources/account.md rename to docs/resources/epcc_account.md index 227f2eb..1a8ed45 100644 --- a/docs/resources/account.md +++ b/docs/resources/epcc_account.md @@ -1,5 +1,5 @@ --- -page_title: "epcc_account Resource - terraform-provider-epcc" +page_title: "epcc_account Resource - epcc-terraform-provider" subcategory: "" description: |- Represents the EPCC API Account resource https://documentation.elasticpath.com/commerce-cloud/docs/api/account-management/accounts/index.html#the-account-object. diff --git a/docs/resources/catalog.md b/docs/resources/epcc_catalog.md similarity index 90% rename from docs/resources/catalog.md rename to docs/resources/epcc_catalog.md index f32c5be..7520a32 100644 --- a/docs/resources/catalog.md +++ b/docs/resources/epcc_catalog.md @@ -1,5 +1,5 @@ --- -page_title: "epcc_catalog Resource - terraform-provider-epcc" +page_title: "epcc_catalog Resource - epcc-terraform-provider" subcategory: "" description: |- Represents the EPCC API PCM Catalog Object https://documentation.elasticpath.com/commerce-cloud/docs/api/pcm/catalogs/index.html#the-catalog-object. diff --git a/docs/resources/catalog_rule.md b/docs/resources/epcc_catalog_rule.md similarity index 89% rename from docs/resources/catalog_rule.md rename to docs/resources/epcc_catalog_rule.md index df4f377..3b0b2aa 100644 --- a/docs/resources/catalog_rule.md +++ b/docs/resources/epcc_catalog_rule.md @@ -1,5 +1,5 @@ --- -page_title: "epcc_catalog_rule Resource - terraform-provider-epcc" +page_title: "epcc_catalog_rule Resource - epcc-terraform-provider" subcategory: "" description: |- Represents the EPCC API PCM Catalog Rule Object https://documentation.elasticpath.com/commerce-cloud/docs/api/pcm/catalogs/rules/get-a-catalog-rule.html. diff --git a/docs/resources/currency.md b/docs/resources/epcc_currency.md similarity index 91% rename from docs/resources/currency.md rename to docs/resources/epcc_currency.md index 8a15431..96a8f07 100644 --- a/docs/resources/currency.md +++ b/docs/resources/epcc_currency.md @@ -1,5 +1,5 @@ --- -page_title: "epcc_currency Resource - terraform-provider-epcc" +page_title: "epcc_currency Resource - epcc-terraform-provider" subcategory: "" description: |- Represents the EPCC API Currency Object https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/currencies/index.html#the-currency-object. diff --git a/docs/resources/customer.md b/docs/resources/epcc_customer.md similarity index 89% rename from docs/resources/customer.md rename to docs/resources/epcc_customer.md index 10741e1..3e347fd 100644 --- a/docs/resources/customer.md +++ b/docs/resources/epcc_customer.md @@ -1,5 +1,5 @@ --- -page_title: "epcc_customer Resource - terraform-provider-epcc" +page_title: "epcc_customer Resource - epcc-terraform-provider" subcategory: "" description: |- Represents the EPCC API Customer Object https://documentation.elasticpath.com/commerce-cloud/docs/api/orders-and-customers/customers/index.html#the-customer-object. diff --git a/docs/resources/entry.md b/docs/resources/epcc_entry.md similarity index 64% rename from docs/resources/entry.md rename to docs/resources/epcc_entry.md index d913ad0..f118b8e 100644 --- a/docs/resources/entry.md +++ b/docs/resources/epcc_entry.md @@ -1,5 +1,5 @@ --- -page_title: "epcc_entry Resource - terraform-provider-epcc" +page_title: "epcc_entry Resource - epcc-terraform-provider" subcategory: "" description: |- Represents the EPCC API Entry Object https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/custom-data/entries/index.html. @@ -15,9 +15,15 @@ Represents the EPCC API [Entry Object](https://documentation.elasticpath.com/com ### Required -- **payload** (Map of String) - **slug** (String) +### Optional + +- **booleans** (Map of Boolean) +- **numbers** (Map of Number) +- **strings** (Map of String) +- **target_id** (String) Target core object identifier (can only be used for core flows) + ### Read-only - **id** (String) The ID of this resource. diff --git a/docs/resources/field.md b/docs/resources/epcc_field.md similarity index 94% rename from docs/resources/field.md rename to docs/resources/epcc_field.md index 755468c..9776857 100644 --- a/docs/resources/field.md +++ b/docs/resources/epcc_field.md @@ -1,5 +1,5 @@ --- -page_title: "epcc_field Resource - terraform-provider-epcc" +page_title: "epcc_field Resource - epcc-terraform-provider" subcategory: "" description: |- Represents the EPCC API Fields Object https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/custom-data/fields/index.html. diff --git a/docs/resources/file.md b/docs/resources/epcc_file.md similarity index 70% rename from docs/resources/file.md rename to docs/resources/epcc_file.md index a9546c8..dd8dc4f 100644 --- a/docs/resources/file.md +++ b/docs/resources/epcc_file.md @@ -1,5 +1,5 @@ --- -page_title: "epcc_file Resource - terraform-provider-epcc" +page_title: "epcc_file Resource - epcc-terraform-provider" subcategory: "" description: |- Represents the EPCC API File Object https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/files/index.html#the-file-object. @@ -15,10 +15,10 @@ Represents the EPCC API [File Object](https://documentation.elasticpath.com/comm ### Optional -- **file** (String) +- **file_hash** (String) - **file_location** (String) - **file_name** (String) -- **public** (Boolean) TBD - But remember the behaviour of this differs from the API, in that terraform ignores this setting if you specify it for file_location. +- **public** (Boolean) TBD. ### Read-only diff --git a/docs/resources/flow.md b/docs/resources/epcc_flow.md similarity index 90% rename from docs/resources/flow.md rename to docs/resources/epcc_flow.md index d1ebdf1..73ae49a 100644 --- a/docs/resources/flow.md +++ b/docs/resources/epcc_flow.md @@ -1,5 +1,5 @@ --- -page_title: "epcc_flow Resource - terraform-provider-epcc" +page_title: "epcc_flow Resource - epcc-terraform-provider" subcategory: "" description: |- Represents the EPCC API Flow Object https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/custom-data/flows/index.html#the-flow-object. diff --git a/docs/resources/hierarchy.md b/docs/resources/epcc_hierarchy.md similarity index 89% rename from docs/resources/hierarchy.md rename to docs/resources/epcc_hierarchy.md index 4a6cb4d..f4d0f26 100644 --- a/docs/resources/hierarchy.md +++ b/docs/resources/epcc_hierarchy.md @@ -1,5 +1,5 @@ --- -page_title: "epcc_hierarchy Resource - terraform-provider-epcc" +page_title: "epcc_hierarchy Resource - epcc-terraform-provider" subcategory: "" description: |- Represents the EPCC API Hierarchy Object https://documentation.elasticpath.com/commerce-cloud/docs/api/pcm/hierarchies/index.html#the-hierarchy-object. diff --git a/docs/resources/integration.md b/docs/resources/epcc_integration.md similarity index 93% rename from docs/resources/integration.md rename to docs/resources/epcc_integration.md index 1533470..e974387 100644 --- a/docs/resources/integration.md +++ b/docs/resources/epcc_integration.md @@ -1,5 +1,5 @@ --- -page_title: "epcc_integration Resource - terraform-provider-epcc" +page_title: "epcc_integration Resource - epcc-terraform-provider" subcategory: "" description: |- Allows to configure webhooks, and corresponds to EPCC API Event (Webhooks) Object https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/events/index.html#event-object diff --git a/docs/resources/node.md b/docs/resources/epcc_node.md similarity index 90% rename from docs/resources/node.md rename to docs/resources/epcc_node.md index 39c5600..556face 100644 --- a/docs/resources/node.md +++ b/docs/resources/epcc_node.md @@ -1,5 +1,5 @@ --- -page_title: "epcc_node Resource - terraform-provider-epcc" +page_title: "epcc_node Resource - epcc-terraform-provider" subcategory: "" description: |- Represents the EPCC API Node Object https://documentation.elasticpath.com/commerce-cloud/docs/api/pcm/hierarchies/index.html#the-node-object. diff --git a/docs/resources/node_product.md b/docs/resources/epcc_node_product.md similarity index 90% rename from docs/resources/node_product.md rename to docs/resources/epcc_node_product.md index e98a3d1..8d58864 100644 --- a/docs/resources/node_product.md +++ b/docs/resources/epcc_node_product.md @@ -1,5 +1,5 @@ --- -page_title: "epcc_node_product Resource - terraform-provider-epcc" +page_title: "epcc_node_product Resource - epcc-terraform-provider" subcategory: "" description: |- Represents the EPCC API Node and Product Relationship https://documentation.elasticpath.com/commerce-cloud/docs/api/pcm/hierarchies/relationships/create-node-product-relationships.html. diff --git a/docs/resources/payment_gateway.md b/docs/resources/epcc_payment_gateway.md similarity index 87% rename from docs/resources/payment_gateway.md rename to docs/resources/epcc_payment_gateway.md index 66370bf..26d6fcf 100644 --- a/docs/resources/payment_gateway.md +++ b/docs/resources/epcc_payment_gateway.md @@ -1,5 +1,5 @@ --- -page_title: "epcc_payment_gateway Resource - terraform-provider-epcc" +page_title: "epcc_payment_gateway Resource - epcc-terraform-provider" subcategory: "" description: |- Payment gateway connectivity configuration diff --git a/docs/resources/pricebook.md b/docs/resources/epcc_pricebook.md similarity index 89% rename from docs/resources/pricebook.md rename to docs/resources/epcc_pricebook.md index c0dd63a..9f3f08b 100644 --- a/docs/resources/pricebook.md +++ b/docs/resources/epcc_pricebook.md @@ -1,5 +1,5 @@ --- -page_title: "epcc_pricebook Resource - terraform-provider-epcc" +page_title: "epcc_pricebook Resource - epcc-terraform-provider" subcategory: "" description: |- Represents the EPCC API PriceBook Object https://documentation.elasticpath.com/commerce-cloud/docs/api/pcm/pricebooks/index.html#the-pricebook-object. diff --git a/docs/resources/product.md b/docs/resources/epcc_product.md similarity index 94% rename from docs/resources/product.md rename to docs/resources/epcc_product.md index 338bfad..2c1f883 100644 --- a/docs/resources/product.md +++ b/docs/resources/epcc_product.md @@ -1,5 +1,5 @@ --- -page_title: "epcc_product Resource - terraform-provider-epcc" +page_title: "epcc_product Resource - epcc-terraform-provider" subcategory: "" description: |- Allows the caller to create, update or delete an Elastic Path Commerce Cloud PCM product https://documentation.elasticpath.com/commerce-cloud/docs/concepts/products-pcm.html. diff --git a/docs/resources/product_price.md b/docs/resources/epcc_product_price.md similarity index 91% rename from docs/resources/product_price.md rename to docs/resources/epcc_product_price.md index 2687870..d1609d7 100644 --- a/docs/resources/product_price.md +++ b/docs/resources/epcc_product_price.md @@ -1,5 +1,5 @@ --- -page_title: "epcc_product_price Resource - terraform-provider-epcc" +page_title: "epcc_product_price Resource - epcc-terraform-provider" subcategory: "" description: |- Represents the EPCC API Price Object https://documentation.elasticpath.com/commerce-cloud/docs/api/pcm/pricebooks/prices/create-product-prices.html. diff --git a/docs/resources/profile.md b/docs/resources/epcc_profile.md similarity index 90% rename from docs/resources/profile.md rename to docs/resources/epcc_profile.md index 1c09608..e79e610 100644 --- a/docs/resources/profile.md +++ b/docs/resources/epcc_profile.md @@ -1,5 +1,5 @@ --- -page_title: "epcc_profile Resource - terraform-provider-epcc" +page_title: "epcc_profile Resource - epcc-terraform-provider" subcategory: "" description: |- Represents the EPCC API OpenID Connect Profiles https://documentation.elasticpath.com/commerce-cloud/docs/api/single-sign-on/oidc-profiles/index.html. diff --git a/docs/resources/promotion.md b/docs/resources/epcc_promotion.md similarity index 96% rename from docs/resources/promotion.md rename to docs/resources/epcc_promotion.md index ab5a87e..0c5b696 100644 --- a/docs/resources/promotion.md +++ b/docs/resources/epcc_promotion.md @@ -1,5 +1,5 @@ --- -page_title: "epcc_promotion Resource - terraform-provider-epcc" +page_title: "epcc_promotion Resource - epcc-terraform-provider" subcategory: "" description: |- Represents the EPCC API Promotion Object https://documentation.elasticpath.com/commerce-cloud/docs/api/carts-and-checkout/promotions/index.html#the-promotion-object. diff --git a/docs/resources/realm.md b/docs/resources/epcc_realm.md similarity index 91% rename from docs/resources/realm.md rename to docs/resources/epcc_realm.md index 054341a..f7e79bf 100644 --- a/docs/resources/realm.md +++ b/docs/resources/epcc_realm.md @@ -1,5 +1,5 @@ --- -page_title: "epcc_realm Resource - terraform-provider-epcc" +page_title: "epcc_realm Resource - epcc-terraform-provider" subcategory: "" description: |- Represents the EPCC API Authentication Realms https://documentation.elasticpath.com/commerce-cloud/docs/api/single-sign-on/authentication-realms/index.html. diff --git a/docs/resources/user_authentication_info.md b/docs/resources/epcc_user_authentication_info.md similarity index 81% rename from docs/resources/user_authentication_info.md rename to docs/resources/epcc_user_authentication_info.md index 5eeb287..885c0ea 100644 --- a/docs/resources/user_authentication_info.md +++ b/docs/resources/epcc_user_authentication_info.md @@ -1,5 +1,5 @@ --- -page_title: "epcc_user_authentication_info Resource - terraform-provider-epcc" +page_title: "epcc_user_authentication_info Resource - epcc-terraform-provider" subcategory: "" description: |- Represents the EPCC API User Authentication Info diff --git a/examples/data-sources/entry_data_source/datasource.tf b/examples/data-sources/entry_data_source/datasource.tf index 1c5f386..91cce94 100644 --- a/examples/data-sources/entry_data_source/datasource.tf +++ b/examples/data-sources/entry_data_source/datasource.tf @@ -7,12 +7,12 @@ terraform { } } -data "epcc_entry" "example" { - id = "4f82aa4f-5ee8-478a-99ca-4a27f888d8ca" - slug = "place" +data "epcc_entry" "order_flow_entry" { + id = "8cd0a8ef-a5c4-49bb-8012-186fad3f7917" + slug = "orders" } -output "entry_name" { - value = data.epcc_entry.example +//noinspection HILUnresolvedReference +output "shipping" { + value = data.epcc_entry.order_flow_entry.strings.shipping } - diff --git a/examples/resources/entry_resource/resource.tf b/examples/resources/entry_resource/resource.tf index 05e539a..060cd21 100644 --- a/examples/resources/entry_resource/resource.tf +++ b/examples/resources/entry_resource/resource.tf @@ -7,41 +7,24 @@ terraform { } } -resource "epcc_flow" "tourism_flow" { - name = "Flow for tourism" - slug = "tourism" - description = "This is a Terraform test" - enabled = true -} - -resource "epcc_field" "tourism_season_field" { - name = "tourism season" - slug = "season" - field_type = "string" - description = "Season for travelling" - required = false - default = "summer" - omit_null = false - enabled = true - flow_id = epcc_flow.tourism_flow.id +data "epcc_flow" "orders" { + id = "79b9cf49-dba6-4575-91ff-d793b01f126e" } -resource "epcc_field" "tourism_place_field" { - name = "tourism place" - slug = "place" +resource "epcc_field" "shipping" { + name = "Shipping" + slug = "shipping" field_type = "string" - description = "place for travelling" + description = "Shipping option" required = false - default = "vancouver" - omit_null = false enabled = true - flow_id = epcc_flow.tourism_flow.id + flow_id = data.epcc_flow.orders.id } -resource "epcc_entry" "tourism_netherlands" { - slug = epcc_flow.tourism_flow.slug - payload = { - (epcc_field.tourism_season_field.slug) = "spring", - (epcc_field.tourism_place_field.slug) = "netherlands" +resource "epcc_entry" "shipping_record" { + slug = "orders" + target_id = "8cd0a8ef-a5c4-49bb-8012-186fad3f7917" + strings = { + (epcc_field.shipping.slug) = "shipping-id", } } diff --git a/external/sdk/epcc/entry.go b/external/sdk/epcc/entry.go index 4f607c4..cbe415d 100644 --- a/external/sdk/epcc/entry.go +++ b/external/sdk/epcc/entry.go @@ -11,15 +11,33 @@ var Entries entries type entries struct{} +type EntryData struct { + Data Entry `json:"data"` +} + +type EntryList struct { + Data []Entry +} + type Entry struct { - Id string `json:"id,omitempty"` - Type string `json:"type,omitempty"` + Id string `json:"id,omitempty"` + Type string `json:"type,omitempty"` + Strings map[string]string `json:"-"` + Numbers map[string]float64 `json:"-"` + Booleans map[string]bool `json:"-"` } func (entries) Get(ctx *context.Context, client *Client, flowSlug string, entryID string) (*EntryData, ApiErrors) { + if flowSlug == "" { + return nil, FromError(fmt.Errorf("slug is required")) + } + if entryID == "" { + return nil, FromError(fmt.Errorf("id is required")) + } + path := fmt.Sprintf("/v2/flows/%s/entries/%s", flowSlug, entryID) - body, apiError := client.DoRequest(ctx, "GET", path, "",nil) + body, apiError := client.DoRequest(ctx, "GET", path, "", nil) if apiError != nil { return nil, apiError } @@ -33,31 +51,37 @@ func (entries) Get(ctx *context.Context, client *Client, flowSlug string, entryI } func (entries) GetAll(ctx *context.Context, client *Client, flowSlug string) (*EntryList, ApiErrors) { + if flowSlug == "" { + return nil, FromError(fmt.Errorf("slug is required")) + } path := fmt.Sprintf("/v2/flows/%s/entries", flowSlug) - body, apiError := client.DoRequest(ctx, "GET", path, "",nil) + body, apiError := client.DoRequest(ctx, "GET", path, "", nil) if apiError != nil { return nil, apiError } - var entries EntryList - if err := json.Unmarshal(body, &entries); err != nil { + var list EntryList + if err := json.Unmarshal(body, &list); err != nil { return nil, FromError(err) } - return &entries, nil + return &list, nil } -func (entries) Create(ctx *context.Context, client *Client, flowSlug string, entry *Entry, payload map[string]interface{}) (*EntryData, ApiErrors) { +func (entries) Create(ctx *context.Context, client *Client, flowSlug string, entry *Entry) (*EntryData, ApiErrors) { entryData := EntryData{ Data: *entry, } - jsonPayload, err := ToJSON(entryData, payload) + jsonPayload, err := json.Marshal(entryData) if err != nil { return nil, FromError(err) } + if flowSlug == "" { + return nil, FromError(fmt.Errorf("slug is required")) + } path := fmt.Sprintf("/v2/flows/%s/entries", flowSlug) body, apiError := client.DoRequest(ctx, "POST", path, "", bytes.NewBuffer(jsonPayload)) @@ -74,29 +98,38 @@ func (entries) Create(ctx *context.Context, client *Client, flowSlug string, ent } func (entries) Delete(ctx *context.Context, client *Client, flowSlug string, entryID string) ApiErrors { + if flowSlug == "" { + return FromError(fmt.Errorf("slug is required")) + } + if entryID == "" { + return FromError(fmt.Errorf("id is required")) + } path := fmt.Sprintf("/v2/flows/%s/entries/%s", flowSlug, entryID) - if _, err := client.DoRequest(ctx, "DELETE", path, "",nil); err != nil { + if _, err := client.DoRequest(ctx, "DELETE", path, "", nil); err != nil { return err } return nil } -func (entries) Update(ctx *context.Context, client *Client, flowSlug string, entryID string, payload map[string]interface{}) (*EntryData, ApiErrors) { - +func (entries) Update(ctx *context.Context, client *Client, flowSlug string, entry *Entry) (*EntryData, ApiErrors) { entryData := EntryData{ - Data: Entry{ - Type: "entry", - }, + Data: *entry, } - jsonPayload, err := ToJSON(entryData, payload) + jsonPayload, err := json.Marshal(entryData) if err != nil { return nil, FromError(err) } - path := fmt.Sprintf("/v2/flows/%s/entries/%s", flowSlug, entryID) + if flowSlug == "" { + return nil, FromError(fmt.Errorf("slug is required")) + } + if entry.Id == "" { + return nil, FromError(fmt.Errorf("id is required")) + } + path := fmt.Sprintf("/v2/flows/%s/entries/%s", flowSlug, entry.Id) body, apiError := client.DoRequest(ctx, "PUT", path, "", bytes.NewBuffer(jsonPayload)) if apiError != nil { @@ -111,17 +144,69 @@ func (entries) Update(ctx *context.Context, client *Client, flowSlug string, ent return &updatedEntry, nil } -type EntryData struct { - Data Entry `json:"data"` +func (e Entry) MarshalJSON() ([]byte, error) { + out := map[string]interface{}{} + if e.Id != "" { + out["id"] = e.Id + } + out["type"] = e.Type + for k, v := range e.Strings { + out[k] = v + } + for k, v := range e.Numbers { + out[k] = v + } + for k, v := range e.Booleans { + out[k] = v + } + return json.Marshal(out) } -type EntryMeta struct { - Timestamps Timestamps `json:"timestamps,omitempty"` -} +func (e *Entry) UnmarshalJSON(body []byte) error { + var fieldRawMap map[string]*json.RawMessage + err := json.Unmarshal(body, &fieldRawMap) + if err != nil { + return err + } -type EntryDataList struct { -} + if err = unmarshalRaw(fieldRawMap, "id", &e.Id); err != nil { + return err + } + if err = unmarshalRaw(fieldRawMap, "type", &e.Type); err != nil { + return err + } -type EntryList struct { - Data [] Entry + e.Strings = map[string]string{} + e.Numbers = map[string]float64{} + e.Booleans = map[string]bool{} + + for key, message := range fieldRawMap { + if key == "id" || key == "type" || key == "meta" || key == "links" { + continue + } + + if message == nil { + continue + } + + var s string + if err = json.Unmarshal(*message, &s); err == nil { + e.Strings[key] = s + continue + } + + var f float64 + if err = json.Unmarshal(*message, &f); err == nil { + e.Numbers[key] = f + continue + } + + var b bool + if err = json.Unmarshal(*message, &b); err == nil { + e.Booleans[key] = b + continue + } + } + + return nil } diff --git a/external/sdk/epcc/field.go b/external/sdk/epcc/field.go index 523391d..4fc8665 100644 --- a/external/sdk/epcc/field.go +++ b/external/sdk/epcc/field.go @@ -345,11 +345,3 @@ func (f *Field) UnmarshalJSON(body []byte) error { return nil } - -func unmarshalRaw(m map[string]*json.RawMessage, key string, target interface{}) error { - data, ok := m[key] - if ok && data != nil { - return json.Unmarshal(*data, &target) - } - return nil -} diff --git a/external/sdk/epcc/resource_extension.go b/external/sdk/epcc/resource_extension.go index fedaa29..95c6b46 100644 --- a/external/sdk/epcc/resource_extension.go +++ b/external/sdk/epcc/resource_extension.go @@ -4,27 +4,10 @@ import ( "encoding/json" ) -func ToJSON(coreData interface{}, extension map[string]interface{}) ([]byte, error) { - // Convert core data to JSON byte array - core, err := json.Marshal(coreData) - if err != nil { - return nil, err +func unmarshalRaw(m map[string]*json.RawMessage, key string, target interface{}) error { + data, ok := m[key] + if ok && data != nil { + return json.Unmarshal(*data, &target) } - - // Convert core data JSON to dynamic map - out := map[string]interface{}{} - err = json.Unmarshal(core, &out) - if err != nil { - return nil, err - } - - // Merge both JSON data structures - // Add/Override keys from flows into the core resource properties - data := out["data"].(map[string]interface{}) - for k, v := range extension { - data[k] = v - } - - outputJSON, _ := json.Marshal(out) - return outputJSON, nil + return nil } diff --git a/internal/provider/data_source_epcc_entry.go b/internal/provider/data_source_epcc_entry.go index 4d05d4f..bbf895a 100644 --- a/internal/provider/data_source_epcc_entry.go +++ b/internal/provider/data_source_epcc_entry.go @@ -3,41 +3,74 @@ package provider import ( "context" "github.com/elasticpath/terraform-provider-epcc/external/sdk/epcc" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func dataSourceEpccEntry() *schema.Resource { +type EntryDataSourceProvider struct { +} + +func (p EntryDataSourceProvider) DataSource() *schema.Resource { return &schema.Resource{ - ReadContext: addDiagToContext(dataSourceEpccEntryRead), + ReadContext: addDiagToContext(p.read), Schema: map[string]*schema.Schema{ - "id": &schema.Schema{ + "id": { Type: schema.TypeString, Required: true, }, - "slug": &schema.Schema{ + "slug": { Type: schema.TypeString, - Computed: true, + Required: true, }, - "payload": &schema.Schema{ + "strings": { Type: schema.TypeMap, - Required: true, + Computed: true, Elem: &schema.Schema{ Type: schema.TypeString, }, }, + "numbers": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeFloat, + }, + }, + "booleans": { + Type: schema.TypeMap, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeBool, + }, + }, }, } } -func dataSourceEpccEntryRead(ctx context.Context, d *schema.ResourceData, m interface{}) { - +func (p EntryDataSourceProvider) read(ctx context.Context, d *schema.ResourceData, m interface{}) { client := m.(*epcc.Client) - entryId := d.Get("id").(string) + flowSlug := d.Get("slug").(string) - entry, err := epcc.Entries.Get(&ctx, client, flowSlug, entryId) + entryID := d.Get("id").(string) + + entry, err := epcc.Entries.Get(&ctx, client, flowSlug, entryID) if err != nil { ReportAPIError(ctx, err) - } else { - d.SetId(entry.Data.Id) + return + } + + if err := d.Set("strings", entry.Data.Strings); err != nil { + addToDiag(ctx, diag.FromErr(err)) + return } + if err := d.Set("numbers", entry.Data.Numbers); err != nil { + addToDiag(ctx, diag.FromErr(err)) + return + } + if err := d.Set("booleans", entry.Data.Booleans); err != nil { + addToDiag(ctx, diag.FromErr(err)) + return + } + + d.SetId(entryID) } diff --git a/internal/provider/provider.go b/internal/provider/provider.go index d03ca8e..f3dba6d 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -80,7 +80,7 @@ func New(version string) func() *schema.Provider { "epcc_catalog_rule": dataSourceEpccCatalogRule(), "epcc_currency": dataSourceEpccCurrency(), "epcc_customer": dataSourceEpccCustomer(), - "epcc_entry": dataSourceEpccEntry(), + "epcc_entry": EntryDataSourceProvider{}.DataSource(), "epcc_field": dataSourceEpccField(), "epcc_file": dataSourceEpccFile(), "epcc_flow": dataSourceEpccFlow(), @@ -106,7 +106,7 @@ func New(version string) func() *schema.Provider { "epcc_catalog_rule": resourceEpccCatalogRule(), "epcc_currency": resourceEpccCurrency(), "epcc_customer": resourceEpccCustomer(), - "epcc_entry": resourceEpccEntry(), + "epcc_entry": EntryResourceProvider{}.Resource(), "epcc_field": resourceEpccField(), "epcc_file": resourceEpccFile(), "epcc_flow": resourceEpccFlow(), diff --git a/internal/provider/resource_epcc_entry.go b/internal/provider/resource_epcc_entry.go index cf4d81a..b704a07 100644 --- a/internal/provider/resource_epcc_entry.go +++ b/internal/provider/resource_epcc_entry.go @@ -2,103 +2,175 @@ package provider import ( "context" + "fmt" "github.com/elasticpath/terraform-provider-epcc/external/sdk/epcc" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func resourceEpccEntry() *schema.Resource { +type EntryResourceProvider struct { +} + +func (p EntryResourceProvider) Resource() *schema.Resource { return &schema.Resource{ Description: "Represents the EPCC API [Entry Object](https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/custom-data/entries/index.html).", - CreateContext: addDiagToContext(resourceEpccEntryCreate), - ReadContext: addDiagToContext(resourceEpccEntryRead), - UpdateContext: addDiagToContext(resourceEpccEntryUpdate), - DeleteContext: addDiagToContext(resourceEpccEntryDelete), - Importer: &schema.ResourceImporter{ - StateContext: schema.ImportStatePassthroughContext, - }, + CreateContext: addDiagToContext(p.create), + ReadContext: addDiagToContext(p.read), + UpdateContext: addDiagToContext(p.update), + DeleteContext: addDiagToContext(p.delete), Schema: map[string]*schema.Schema{ - "id": &schema.Schema{ + "id": { Type: schema.TypeString, Computed: true, }, - "slug": &schema.Schema{ + "target_id": { + Description: "Target core object identifier (can only be used for core flows)", + Type: schema.TypeString, + Optional: true, + }, + "slug": { Type: schema.TypeString, Required: true, }, - "payload": &schema.Schema{ + "strings": { Type: schema.TypeMap, - Required: true, + Optional: true, Elem: &schema.Schema{ Type: schema.TypeString, }, }, + "numbers": { + Type: schema.TypeMap, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeFloat, + }, + }, + "booleans": { + Type: schema.TypeMap, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeBool, + }, + }, }, } } -func resourceEpccEntryDelete(ctx context.Context, d *schema.ResourceData, m interface{}) { +func (p EntryResourceProvider) create(ctx context.Context, d *schema.ResourceData, m interface{}) { + if id, ok := d.GetOk("target_id"); ok { + if err := checkCoreFlow(d); err != nil { + addToDiag(ctx, diag.FromErr(err)) + return + } + + d.SetId(id.(string)) + p.update(ctx, d, m) + return + } client := m.(*epcc.Client) + entry := &epcc.Entry{ + Type: "entry", + Strings: convertMapToStringMap(d.Get("strings").(map[string]interface{})), + Numbers: convertMapToFloatMap(d.Get("numbers").(map[string]interface{})), + Booleans: convertMapToBooleanMap(d.Get("booleans").(map[string]interface{})), + } + flowSlug := d.Get("slug").(string) - entryID := d.Id() - err := epcc.Entries.Delete(&ctx, client, flowSlug, entryID) + created, apiError := epcc.Entries.Create(&ctx, client, flowSlug, entry) - if err != nil { - ReportAPIError(ctx, err) + if apiError != nil { + ReportAPIError(ctx, apiError) + return } - d.SetId("") + d.SetId(created.Data.Id) +} + +func checkCoreFlow(d *schema.ResourceData) error { + slug := d.Get("slug").(string) + coreFlows := []string{ + "addresses", + "products", + "brands", + "collections", + "categories", + "customers", + "carts", + "cart_items", + "files", + "orders", + "order_items", + "promotions", + } + for _, coreFlow := range coreFlows { + if coreFlow == slug { + return nil + } + } + return fmt.Errorf("slug %v does not correspond to one of core flows: %v", slug, coreFlows) } -func resourceEpccEntryUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) { +func (p EntryResourceProvider) update(ctx context.Context, d *schema.ResourceData, m interface{}) { client := m.(*epcc.Client) flowSlug := d.Get("slug").(string) - entryID := d.Id() - - createdEntryData, apiError := epcc.Entries.Update(&ctx, client, flowSlug, entryID, d.Get("payload").(map[string]interface{})) + entry := &epcc.Entry{ + Id: d.Id(), + Type: "entry", + Strings: convertMapToStringMap(d.Get("strings").(map[string]interface{})), + Numbers: convertMapToFloatMap(d.Get("numbers").(map[string]interface{})), + Booleans: convertMapToBooleanMap(d.Get("booleans").(map[string]interface{})), + } - if apiError != nil { - ReportAPIError(ctx, apiError) + _, err := epcc.Entries.Update(&ctx, client, flowSlug, entry) + if err != nil { + ReportAPIError(ctx, err) return } - d.SetId(createdEntryData.Data.Id) - - resourceEpccEntryRead(ctx, d, m) + p.read(ctx, d, m) } -func resourceEpccEntryRead(ctx context.Context, d *schema.ResourceData, m interface{}) { +func (p EntryResourceProvider) delete(ctx context.Context, d *schema.ResourceData, m interface{}) { client := m.(*epcc.Client) - entryID := d.Id() flowSlug := d.Get("slug").(string) - _, err := epcc.Entries.Get(&ctx, client, flowSlug, entryID) + entryID := d.Id() + err := epcc.Entries.Delete(&ctx, client, flowSlug, entryID) if err != nil { ReportAPIError(ctx, err) return } + + d.SetId("") } -func resourceEpccEntryCreate(ctx context.Context, d *schema.ResourceData, m interface{}) { +func (p EntryResourceProvider) read(ctx context.Context, d *schema.ResourceData, m interface{}) { client := m.(*epcc.Client) - entry := &epcc.Entry{ - Type: "entry", - } - flowSlug := d.Get("slug").(string) + entryID := d.Id() - createdEntryData, apiError := epcc.Entries.Create(&ctx, client, flowSlug, entry, d.Get("payload").(map[string]interface{})) - - if apiError != nil { - ReportAPIError(ctx, apiError) + entry, err := epcc.Entries.Get(&ctx, client, flowSlug, entryID) + if err != nil { + ReportAPIError(ctx, err) return } - d.SetId(createdEntryData.Data.Id) - - resourceEpccEntryRead(ctx, d, m) + if err := d.Set("strings", entry.Data.Strings); err != nil { + addToDiag(ctx, diag.FromErr(err)) + return + } + if err := d.Set("numbers", entry.Data.Numbers); err != nil { + addToDiag(ctx, diag.FromErr(err)) + return + } + if err := d.Set("booleans", entry.Data.Booleans); err != nil { + addToDiag(ctx, diag.FromErr(err)) + return + } } diff --git a/internal/provider/resource_epcc_entry_test.go b/internal/provider/resource_epcc_entry_test.go index 574dab8..85e1e1a 100644 --- a/internal/provider/resource_epcc_entry_test.go +++ b/internal/provider/resource_epcc_entry_test.go @@ -1,7 +1,6 @@ package provider import ( - "regexp" "testing" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" @@ -13,56 +12,84 @@ func TestAccResourceEntry(t *testing.T) { ProviderFactories: providerFactories, Steps: []resource.TestStep{ { - Config: testAccResourceEntry, + Config: // language=HCL + ` + resource "epcc_flow" "test_flow" { + name = "Test flow" + slug = "test" + description = "This is a Terraform test" + enabled = true + } + + resource "epcc_field" "test_flow_string_field" { + name = "Test string field" + slug = "string" + field_type = "string" + description = "string field" + required = false + default = "default" + omit_null = false + enabled = true + flow_id = epcc_flow.test_flow.id + } + + resource "epcc_field" "test_flow_integer_field" { + name = "Test integer field" + slug = "integer" + field_type = "integer" + description = "integer field" + required = false + default = 1 + omit_null = false + enabled = true + flow_id = epcc_flow.test_flow.id + } + + resource "epcc_field" "test_flow_float_field" { + name = "Test float field" + slug = "float" + field_type = "float" + description = "float field" + required = false + default = 1.0 + omit_null = false + enabled = true + flow_id = epcc_flow.test_flow.id + } + + resource "epcc_field" "test_flow_boolean_field" { + name = "Test boolean field" + slug = "boolean" + field_type = "boolean" + description = "boolean field" + required = false + omit_null = false + enabled = true + flow_id = epcc_flow.test_flow.id + } + + resource "epcc_entry" "test_entry" { + slug = epcc_flow.test_flow.slug + strings = { + (epcc_field.test_flow_string_field.slug) = "netherlands" + } + numbers = { + (epcc_field.test_flow_integer_field.slug) = 2, + (epcc_field.test_flow_float_field.slug) = 3.1, + } + booleans = { + (epcc_field.test_flow_boolean_field.slug) = true + } + } + `, Check: resource.ComposeTestCheckFunc( - resource.TestMatchResourceAttr("epcc_entry.tourism_netherlands", "slug", regexp.MustCompile("tourism")), - resource.TestMatchResourceAttr("epcc_entry.tourism_netherlands", "payload.season", regexp.MustCompile("spring")), - resource.TestMatchResourceAttr("epcc_entry.tourism_netherlands", "payload.place", regexp.MustCompile("netherlands")), + resource.TestCheckResourceAttr("epcc_entry.test_entry", "slug", "test"), + resource.TestCheckResourceAttr("epcc_entry.test_entry", "strings.string", "netherlands"), + resource.TestCheckResourceAttr("epcc_entry.test_entry", "numbers.integer", "2"), + resource.TestCheckResourceAttr("epcc_entry.test_entry", "numbers.float", "3.1"), + resource.TestCheckResourceAttr("epcc_entry.test_entry", "booleans.boolean", "true"), ), }, }, }) } - -const testAccResourceEntry = -// language=HCL -` -resource "epcc_flow" "tourism_flow" { - name = "Flow for tourism" - slug = "tourism" - description = "This is a Terraform test" - enabled = true -} - -resource "epcc_field" "tourism_season_field" { - name = "tourism season" - slug = "season" - field_type = "string" - description = "Season for travelling" - required = false - default = "summer" - omit_null = false - enabled = true - flow_id = epcc_flow.tourism_flow.id -} - -resource "epcc_field" "tourism_place_field" { - name = "tourism place" - slug = "place" - field_type = "string" - description = "place for travelling" - required = false - default = "vancouver" - omit_null = false - enabled = true - flow_id = epcc_flow.tourism_flow.id -} - -resource "epcc_entry" "tourism_netherlands" { - slug = epcc_flow.tourism_flow.slug - payload = { - (epcc_field.tourism_season_field.slug) = "spring", - (epcc_field.tourism_place_field.slug) = "netherlands" - } -} -` diff --git a/internal/provider/util.go b/internal/provider/util.go index e0e898e..0b847f7 100644 --- a/internal/provider/util.go +++ b/internal/provider/util.go @@ -63,6 +63,22 @@ func convertArrayToFloatMaps(arr []interface{}) []map[string]float64 { return result } +func convertMapToStringMap(m map[string]interface{}) map[string]string { + result := make(map[string]string, len(m)) + for k, v := range m { + result[k] = v.(string) + } + return result +} + +func convertMapToBooleanMap(m map[string]interface{}) map[string]bool { + result := make(map[string]bool, len(m)) + for k, v := range m { + result[k] = v.(bool) + } + return result +} + func convertSetToStringSlice(s *schema.Set) []string { strings := make([]string, 0, s.Len())