Code Monkey home page Code Monkey logo

terraform-provider-commercetools's Introduction

commercetools Terraform Provider

Test status codecov Go Report Card

The Terraform commercetools provider allows you to configure your commercetools project with infrastructure-as-code principles.

Commercial support

Need support implementing this terraform provider in your organization? Or are you missing features that need to be added, then we are able to offer support. Please contact us at [email protected]

Quick start

Read our documentation and check out the examples.

Usage

The provider is distributed via the Terraform registry. To use it you need to configure the required_provider block. For example:

terraform {
  required_providers {
    commercetools = {
      source = "labd/commercetools"

      # It's recommended to pin the version, e.g.:
      # version = "~> 1.4.0"
    }
  }
}

Binaries

Packages of the releases are available at https://github.com/labd/terraform-provider-commercetools/releases See the terraform documentation for more information about installing third-party providers.

Contributing

Requirements

Building the provider

Clone repository to: $GOPATH/src/github.com/labd/terraform-provider-commercetools

$ mkdir -p $GOPATH/src/github.com/labd; cd $GOPATH/src/github.com/labd
$ git clone [email protected]:labd/terraform-provider-commercetools

Enter the provider directory and build the provider

$ cd $GOPATH/src/github.com/labd/terraform-provider-commercetools
$ task build-local

A build is created terraform-provider-commercetools_99.0.0 in the root directory and added to plugin folder available locally:

~/.terraform.d/plugins/local/labd/commercetools/99.0.0/${OS_ARCH}/terraform-provider-commercetools_v99.0.0

Use version 99.0.0 in the provider to test your changes locally

terraform {
  required_providers {
    commercetools = {
      source  = "labd/commercetools"
      version = "99.0.0"
    }
  }
}

Adding new resources

When commercetools releases new features which include new resources these need to be implemented in terraform as new resources too. This provider is currently undergoing a migration path to move from terraform-plugin-sdk to the new terraform-plugin-framework. All new resources therefore need to be written using the terraform-plugin-framework module. See the subscription component as example.

Debugging / Troubleshooting

There are two environment settings for troubleshooting:

  • TF_LOG=INFO enables debug output for Terraform.
  • CTP_DEBUG=1 enables debug output for the Commercetools GO SDK this provider uses.

Note this generates a lot of output!

Releasing

When creating a PR with changes, please include a changie file in the changelogs/unreleased folder. This file can be interactively generated by running changie new in the root of the project. Pick a suitable category for the change. We recommend Fixed or Added for most cases. See the changie configuration for the full list of categories.

Once a new version is released all the unreleased changelog files will be merged and added to the general CHANGELOG.md file.

Testing

Running the unit tests

$ task test

Running the unit tests with coverage

$ task coverage

Running an Acceptance Test

In order to run the full suite of Acceptance tests, run task testacc.

NOTE: Acceptance tests create real resources.

Prior to running the tests provider configuration details such as access keys must be made available as environment variables.

Since we need to be able to create commercetools resources, we need the commercetools API credentials. So in order for the acceptance tests to run correctly please provide all the following:

export CTP_CLIENT_ID=...
export CTP_CLIENT_SECRET=...
export CTP_PROJECT_KEY=...
export CTP_SCOPES=...

For convenience, place a testenv.sh in your local folder (which is included in .gitignore) where you can store these environment variables.

Tests can then be started by running

$ source local/testenv.sh
$ task testacc

Authors

This project is developed by Lab Digital. We welcome additional contributors. Please see our GitHub repository for more information.

terraform-provider-commercetools's People

Contributors

adzanette avatar ardjan-aalberts avatar arnestaphorsius avatar bulat-khusnimardanov avatar cneijenhuis avatar davidweterings avatar demeyerthom avatar dependabot[bot] avatar emmenko avatar engerim avatar etiennetremel avatar harrykimpel avatar katmatt avatar labd-project-manager[bot] avatar lbacz avatar markkovari-commercetools avatar michielbijland avatar mikedebock avatar multiply avatar mvantellingen avatar okkevandereijk avatar onur9 avatar pimvernooij avatar pjstevns avatar qdegraaf avatar ranisputnik avatar sshibani avatar tleguijt avatar victoravelar avatar woutor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

terraform-provider-commercetools's Issues

Very long creation time when trying to create an already existing type

module.ct-dev.commercetools_type.category: Creating...
2019/10/31 13:02:47 [DEBUG] module.ct-dev.commercetools_type.category: applying the planned Create change
2019/10/31 13:02:47 [TRACE] GRPCProvider: ApplyResourceChange
2019-10-31T13:02:47.181+0100 [DEBUG] plugin.terraform-provider-commercetools_v0.19.0: 2019/10/31 13:02:47 [DEBUG] Waiting for state to become: [success]
2019-10-31T13:02:47.511+0100 [DEBUG] plugin.terraform-provider-commercetools_v0.19.0: 2019/10/31 13:02:47 [TRACE] Waiting 500ms before next try
2019-10-31T13:02:48.047+0100 [DEBUG] plugin.terraform-provider-commercetools_v0.19.0: 2019/10/31 13:02:48 [TRACE] Waiting 1s before next try
2019-10-31T13:02:49.081+0100 [DEBUG] plugin.terraform-provider-commercetools_v0.19.0: 2019/10/31 13:02:49 [TRACE] Waiting 2s before next try
2019-10-31T13:02:51.126+0100 [DEBUG] plugin.terraform-provider-commercetools_v0.19.0: 2019/10/31 13:02:51 [TRACE] Waiting 4s before next try
2019-10-31T13:02:55.172+0100 [DEBUG] plugin.terraform-provider-commercetools_v0.19.0: 2019/10/31 13:02:55 [TRACE] Waiting 8s before next try
module.ct-dev.commercetools_type.category: Still creating... [10s elapsed]
2019-10-31T13:03:03.220+0100 [DEBUG] plugin.terraform-provider-commercetools_v0.19.0: 2019/10/31 13:03:03 [TRACE] Waiting 10s before next try
module.ct-dev.commercetools_type.category: Still creating... [20s elapsed]
2019-10-31T13:03:13.266+0100 [DEBUG] plugin.terraform-provider-commercetools_v0.19.0: 2019/10/31 13:03:13 [TRACE] Waiting 10s before next try
module.ct-dev.commercetools_type.category: Still creating... [30s elapsed]
2019-10-31T13:03:23.303+0100 [DEBUG] plugin.terraform-provider-commercetools_v0.19.0: 2019/10/31 13:03:23 [TRACE] Waiting 10s before next try
module.ct-dev.commercetools_type.category: Still creating... [40s elapsed]
2019-10-31T13:03:33.357+0100 [DEBUG] plugin.terraform-provider-commercetools_v0.19.0: 2019/10/31 13:03:33 [TRACE] Waiting 10s before next try
module.ct-dev.commercetools_type.category: Still creating... [50s elapsed]
2019-10-31T13:03:43.400+0100 [DEBUG] plugin.terraform-provider-commercetools_v0.19.0: 2019/10/31 13:03:43 [TRACE] Waiting 10s before next try
module.ct-dev.commercetools_type.category: Still creating... [1m0s elapsed]
2019-10-31T13:03:47.181+0100 [DEBUG] plugin.terraform-provider-commercetools_v0.19.0: 2019/10/31 13:03:47 [WARN] WaitForState timeout after 1m0s
2019-10-31T13:03:47.181+0100 [DEBUG] plugin.terraform-provider-commercetools_v0.19.0: 2019/10/31 13:03:47 [WARN] WaitForState starting 30s refresh grace period
2019/10/31 13:03:47 [DEBUG] module.ct-dev.commercetools_type.category: apply errored, but we're indicating that via the Error pointer rather than returning it: A duplicate value '"category"' exists for field 'key'.
2019/10/31 13:03:47 [TRACE] module.ct-dev: eval: *terraform.EvalMaybeTainted
2019/10/31 13:03:47 [TRACE] EvalMaybeTainted: module.ct-dev.commercetools_type.category encountered an error during creation, so it is now marked as tainted
2019/10/31 13:03:47 [ERROR] module.ct-dev: eval: *terraform.EvalApplyPost, err: A duplicate value '"category"' exists for field 'key'.
2019/10/31 13:03:47 [ERROR] module.ct-dev: eval: *terraform.EvalSequence, err: A duplicate value '"category"' exists for field 'key'.
2019/10/31 13:03:47 [TRACE] [walkApply] Exiting eval tree: module.ct-dev.commercetools_type.category

Error: A duplicate value '"category"' exists for field 'key'.

  on terraform/ct-dev/main.tf line 1, in resource "commercetools_type" "category":
   1: resource "commercetools_type" "category" {

What do you expect?

Since my tf state is empty and the type already exists the command should immediately exit with type with key "foo" already exists! Remove it from commercetool or import the state

Product type attribute type change doesn't create attribute

F.e. changing from 'text' to 'ltext'. This would involve deleting the attribute and adding it again, since CT doesn't support changing the type. It would also mean the data on the original attribute is lost (but you're changing the type, so perhaps this is acceptable?).

Updating custom type enum key with new value

We have a customer that is attempting to update a custom type enum value. The provider will create a plan with the update but not actually perform the update.

Plan: 0 to add, 1 to change, 0 to destroy.

...
~ type {
name = "enum"
~ values =

{ "cal-king" = "Cal King" "full" = "Full" "king" = "King" "queen" = "Queen" "sp-king" = "Split King" "twin" = "Twin" ~ "twinxl" = "Twin" -> "Twin XL" }
}
}
...

The terraform plan completes without error but the value remains unchanged. Looking at go library it looks like updates to existing keys is not implemented. Am I correct?

Support for updating project API client

Hi, I'm hoping there is a simple way to do this that I'm missing but could do with a little guidance....

The Problem

We have decided to introduce stores in our commercetools project and the API client that used to launch and configure all the commercetools resources does not have the manage_stores scope.

I created a new API client with all the required scopes to create the stores and pass the new clientId and secret to the project resource in TF. It seems to lose the tracking of the TF resources:

...

 Error: Error refreshing state: 26 error(s) occurred:
 * commercetools_api_client.auth_api_client: 1 error(s) occurred:
 * commercetools_api_client.auth_api_client: commercetools_api_client.auth_api_client: connection is shut down
 * commercetools_api_client.introspect_tokens_client: 1 error(s) occurred:
 * commercetools_api_client.introspect_tokens_client: commercetools_api_client.introspect_tokens_client: unexpected EOF
 * commercetools_api_client.commerce_broker_client: 1 error(s) occurred:
 * commercetools_api_client.commerce_broker_client: commercetools_api_client.commerce_broker_client: connection is shut down

...

When trying to import the existing project I am receiving the following error:

Error: commercetools_project_settings.project (import id: xxxxxxxxxx): Can't import commercetools_project_settings.project, would collide with an existing resource.
 Please remove or rename this resource before continuing.

Is there a way we can migrate a commercetools project to manage it with a new API client?

Any feedback or guidance would be greatly appreciated, thanks in advance!

Don't remove empty localized value

I see the following updates

   ~ attribute {
            constraint = "SameForAll"
            input_hint = "SingleLine"
          ~ input_tip  = {
              - "de" = "" -> null
              - "en" = "" -> null
            }
          ~ label      = {
              - "de" = "" -> null
                "en" = "Defines in which category the product is displayed in the bundle"
            }
            name       = "bundle_category_ref"
            required   = true
            searchable = true

            type {
                name              = "reference"
                reference_type_id = "category"
                values            = {}
            }
        }

this must be a conversion issue in the provider because I didn't change anything. The state was imported via terraformer. I expect that an empty string is preserved.

If you run in debug mode TF_LOG=DEBUG you got:

2019/11/02 21:06:50 [WARN] Provider "commercetools" produced an invalid plan for commercetools_product_type.tfer--d-002D-camera, but we are tolerating it because it is using the legacy plugin SDK.
    The following problems may be the cause of any confusing errors from downstream operations:
      - .attribute[0].input_tip: planned value cty.MapValEmpty(cty.String) does not match config value cty.NullVal(cty.Map(cty.String)) nor prior value cty.MapVal(map[string]cty.Value{"de":cty.StringVal("")})

This could be related to hashicorp/terraform#21806

Incompatible API version with plugin. Plugin version: 4, Client versions: [5].

I recently ran on linux for circleci using Terraform v0.12.6:
brew tap labd/homebrew-terraform-provider-commercetools
brew install terraform-provider-commercetools.
and received this error:
Error: Failed to instantiate provider "commercetools" to obtain schema: Incompatible API version with plugin. Plugin version: 4, Client versions: [5].
Is there a simple workaround?

rpc error: code = Canceled desc = context canceled

I have just updated from 0.19 to 0.21 and my deployment is failing on terraform-plan at the stage of refreshing the current state.

I am using the provider to deploy

  • 2 x commercetools_api_client
  • 1 commercetools_subscription

The standard terraform log output shows:

 Error: rpc error: code = Canceled desc = context canceled
 Error: rpc error: code = Unavailable desc = transport is closing
 Error: rpc error: code = Unavailable desc = transport is closing

When I enable terraform debug logging it provides a little more info.

[DEBUG] ReferenceTransformer: "commercetools_subscription.product_changes" references: []
[ERROR] <root>: eval: *terraform.EvalReadState, err: rpc error: code = Canceled desc = context canceled
[ERROR] <root>: eval: *terraform.EvalSequence, err: rpc error: code = Canceled desc = context canceled

Add supply_channels to Store resource

Supply channels can now be configured on Stores.

Would it be fairly simple to create a similar mechanism to that of adding Distribution Channels (#126)? I can attempt a PR if it's simply a case of replicating prior art.

State transitions error: Cycle

Hi @davidweterings. We have faced a problem with a state transitioning.
We would like to transition from state_1 to state_2 (Just for example) and vice versa.

Here is an example:

resource "commercetools_state" "state_1" {
  key = "state_1"
  ...
  transitions = ["${commercetools_state.state_2.key}"]
}


resource "commercetools_state" "state_2" {
  key = "state_2"
   ....
  transitions = ["${commercetools_state.state_1.key}"]
}

We are getting an error on terraform validation step:
Error: Cycle: commercetools_state.step_1, commercetools_state.step_2
(Because both of them creating dependent resources in parallel)

We may suggest to create a separate resource for state transitioning.
This way we will have 2 separate resources: state and transition.

Example:

resource "commercetools_state" "state_1" {
  key = "state_1"
  ...
}

resource "commercetools_state" "state_2" {
  key = "state_2"
   ....
}

resource "commercetools_state_transition" "state_1_transition" {
 from = "${commercetools_state.state_1.key}"
 to = [
   "${commercetools_state.state_2.key}"
 ]
}

resource "commercetools_state_transition" "state_2_transition" {
 from = "${commercetools_state.state_2.key}"
 to = [
   "${commercetools_state.state_1.key}"
 ]
}

brew install has 404

==> Installing terraform-provider-commercetools from labd/terraform-provider-com
==> Downloading https://github.com/labd/terraform-provider-commercetools/release

curl: (22) The requested URL returned error: 404 Not Found
Error: An exception occurred within a child process:
DownloadError: Failed to download resource "terraform-provider-commercetools"
Download failed: https://github.com/labd/terraform-provider-commercetools/releases/download/0.18.1/terraform-provider-commercetools-0.18.1-linux-amd64.zip

make build doesn't exist

The README states that there is a command make build for building the project but it doesn't exist.

Error while installing hashicorp/commercetools: provider registry

Hi,

I get the following error when i run: terraform init

`Error: Failed to install provider

Error while installing hashicorp/commercetools: provider registry
registry.terraform.io does not have a provider named
registry.terraform.io/hashicorp/commercetools`

Trace log:
`2020/11/06 10:29:47 [INFO] Terraform version: 0.13.5
2020/11/06 10:29:47 [INFO] Go runtime version: go1.14.10
2020/11/06 10:29:47 [INFO] CLI args: []string{"/usr/local/bin/terraform", "init"}
2020/11/06 10:29:47 [DEBUG] Attempting to open CLI config file: /Users/mantonius/.terraformrc
2020/11/06 10:29:47 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2020/11/06 10:29:47 [DEBUG] checking for credentials in "/Users/mantonius/.terraform.d/plugins"
2020/11/06 10:29:47 [DEBUG] checking for credentials in "/Users/mantonius/.terraform.d/plugins/darwin_amd64"
2020/11/06 10:29:47 [DEBUG] ignoring non-existing provider search directory terraform.d/plugins
2020/11/06 10:29:47 [DEBUG] will search for provider plugins in /Users/mantonius/.terraform.d/plugins
2020/11/06 10:29:47 [TRACE] getproviders.SearchLocalDirectory: /Users/mantonius/.terraform.d/plugins is a symlink to /Users/mantonius/.terraform.d/plugins
2020/11/06 10:29:47 [DEBUG] ignoring non-existing provider search directory /Users/mantonius/Library/Application Support/io.terraform/plugins
2020/11/06 10:29:47 [DEBUG] ignoring non-existing provider search directory /Library/Application Support/io.terraform/plugins
2020/11/06 10:29:47 [INFO] CLI command args: []string{"init"}
2020/11/06 10:29:47 [TRACE] ModuleInstaller: installing child modules for . into .terraform/modules
Initializing modules...
2020/11/06 10:29:47 [DEBUG] Module installer: begin commercetools
2020/11/06 10:29:47 [TRACE] ModuleInstaller: Module installer: commercetools already installed in modules/commercetools
2020/11/06 10:29:47 [TRACE] modsdir: writing modules manifest to .terraform/modules/modules.json

Initializing the backend...
2020/11/06 10:29:48 [TRACE] Meta.Backend: no config given or present on disk, so returning nil config
2020/11/06 10:29:48 [TRACE] Meta.Backend: backend has not previously been initialized in this working directory
2020/11/06 10:29:48 [DEBUG] New state was assigned lineage "6eb2e5ac-a688-541e-9409-614a3a30cd02"
2020/11/06 10:29:48 [TRACE] Meta.Backend: using default local state only (no backend configuration, and no existing initialized backend)
2020/11/06 10:29:48 [TRACE] Meta.Backend: instantiated backend of type
2020/11/06 10:29:48 [TRACE] providercache.fillMetaCache: scanning directory .terraform/plugins
2020/11/06 10:29:48 [TRACE] getproviders.SearchLocalDirectory: .terraform/plugins is a symlink to .terraform/plugins
2020/11/06 10:29:48 [TRACE] getproviders.SearchLocalDirectory: found registry.terraform.io/labd/commercetools v0.23.0 for darwin_amd64 at .terraform/plugins/registry.terraform.io/labd/commercetools/0.23.0/darwin_amd64
2020/11/06 10:29:48 [TRACE] providercache.fillMetaCache: including .terraform/plugins/registry.terraform.io/labd/commercetools/0.23.0/darwin_amd64 as a candidate package for registry.terraform.io/labd/commercetools 0.23.0
2020/11/06 10:29:48 [DEBUG] checking for provisioner in "."
2020/11/06 10:29:48 [DEBUG] checking for provisioner in "/usr/local/bin"
2020/11/06 10:29:48 [DEBUG] checking for provisioner in "/Users/mantonius/.terraform.d/plugins"
2020/11/06 10:29:48 [DEBUG] checking for provisioner in "/Users/mantonius/.terraform.d/plugins/darwin_amd64"
2020/11/06 10:29:48 [INFO] Failed to read plugin lock file .terraform/plugins/darwin_amd64/lock.json: open .terraform/plugins/darwin_amd64/lock.json: no such file or directory
2020/11/06 10:29:48 [TRACE] Meta.Backend: backend does not support operations, so wrapping it in a local backend
2020/11/06 10:29:48 [TRACE] backend/local: state manager for workspace "default" will:

  • read initial snapshot from terraform.tfstate
  • write new snapshots to terraform.tfstate
  • create any backup at terraform.tfstate.backup
    2020/11/06 10:29:48 [TRACE] statemgr.Filesystem: reading initial snapshot from terraform.tfstate
    2020/11/06 10:29:48 [TRACE] statemgr.Filesystem: snapshot file has nil snapshot, but that's okay
    2020/11/06 10:29:48 [TRACE] statemgr.Filesystem: read nil snapshot
    2020/11/06 10:29:48 [TRACE] providercache.fillMetaCache: scanning directory .terraform/plugins

2020/11/06 10:29:48 [TRACE] getproviders.SearchLocalDirectory: .terraform/plugins is a symlink to .terraform/plugins
Initializing provider plugins...
2020/11/06 10:29:48 [TRACE] getproviders.SearchLocalDirectory: found registry.terraform.io/labd/commercetools v0.23.0 for darwin_amd64 at .terraform/plugins/registry.terraform.io/labd/commercetools/0.23.0/darwin_amd64
2020/11/06 10:29:48 [TRACE] providercache.fillMetaCache: including .terraform/plugins/registry.terraform.io/labd/commercetools/0.23.0/darwin_amd64 as a candidate package for registry.terraform.io/labd/commercetools 0.23.0

Can somebody point me in the right direction?

Kind regards

Error: rpc error: code = Unavailable desc = transport is closing

2019-09-26T14:50:57.341Z [DEBUG] plugin.terraform-provider-commercetools: 2019/09/26 14:50:57 Get https://abc: Post https://abc tcp 52.7.148.3:443: i/o timeout
2019-09-26T14:50:57.343Z [DEBUG] plugin: plugin process exited: path=/root/.terraform.d/plugins/terraform-provider-commercetools pid=2416 error="exit status 1"
2019/09/26 14:50:57 [ERROR] : eval: *terraform.EvalRefresh, err: rpc error: code = Unavailable desc = transport is closing
2019/09/26 14:50:57 [ERROR] : eval: *terraform.EvalRefresh, err: rpc error: code = Unavailable desc = transport is closing
2019/09/26 14:50:57 [ERROR] : eval: *terraform.EvalRefresh, err: rpc error: code = Unavailable desc = transport is closing
2019/09/26 14:50:57 [ERROR] : eval: *terraform.EvalSequence, err: rpc error: code = Unavailable desc = transport is closing
2019/09/26 14:50:57 [ERROR] : eval: *terraform.EvalRefresh, err: rpc error: code = Unavailable desc = transport is closing
2019/09/26 14:50:57 [ERROR] : eval: *terraform.EvalSequence, err: rpc error: code = Unavailable desc = transport is closing
2019/09/26 14:50:57 [TRACE] [walkRefresh] Exiting eval tree: commercetools_subscription.product_subscription
2019/09/26 14:50:57 [ERROR] : eval: *terraform.EvalSequence, err: rpc error: code = Unavailable desc = transport is closing
2019/09/26 14:50:57 [TRACE] [walkRefresh] Exiting eval tree: commercetools_subscription.sproduct_subscription
2019/09/26 14:50:57 [TRACE] vertex "commercetools_subscription.usubscription": visit complete
2019/09/26 14:50:57 [TRACE] [walkRefresh] Exiting eval tree: commercetools_subscription.subscription
2019/09/26 14:50:57 [TRACE] vertex "commercetools_subscription.subscription": visit complete
2019/09/26 14:50:57 [ERROR] : eval: *terraform.EvalRefresh, err: rpc error: code = Unavailable desc = transport is closing
2019/09/26 14:50:57 [TRACE] vertex "commercetools_subscription.updateState_subscription": visit complete
2019/09/26 14:50:57 [TRACE] vertex "commercetools_subscription.product_subscription": dynamic subgraph encountered errors
2019/09/26 14:50:57 [TRACE] vertex "commercetools_subscription.sproduct_subscription": dynamic subgraph encountered errors
2019/09/26 14:50:57 [ERROR] : eval: *terraform.EvalSequence, err: rpc error: code = Unavailable desc = transport is closing

Error: rpc error: code = Unavailable desc = transport is closing

Tax category import state

Import an existing tax category

terraform import commercetools_tax_category.high-tax-category <uuid>

Show state

terraform state show commercetools_tax_category.high-tax-category

The state in terraform is then missing all the lines, which causes problems later on trying to do a terraform apply

ShippingMethod Zones not set

The Zone set on the ShippingMethod is mandatory for setting ShippingMethodRates.

resource "commercetools_shipping_zone_rate" "standard-de" {
  shipping_method_id = "${commercetools_shipping_method.standard.id}"
  shipping_zone_id   = "${commercetools_shipping_zone.de.id}"

  price {
    cent_amount   = 5000
    currency_code = "EUR"
  }
}

shipping_zone_id Should be set on the ShippingMethod before the Rate can be set. commercetools action

When creating a new ShippingMethod the Zones Array is not set. I think it would make more sense to set the Zone when creating the Rate.

Enums are stored as a map

Enums and LocalizedEnums are stored as a map. This means that the order can't be guaranteed when iterating over it. This makes it impossible to implement. We need to store them in an array.

  • TypeChangeEnumValueOrderAction
  • TypeChangeLocalizedEnumValueOrderAction

e.g

func readCustomFieldLocalizedEnum(values []commercetools.CustomFieldLocalizedEnumValue) []interface{} {
enumValues := make([]interface{}, len(values))
for i, value := range values {
enumValues[i] = map[string]interface{}{
"key": value.Key,
"label": &value.Label,
}
}
return enumValues
}

Documentation issue with field from type "Enum"

According to the docs, this is the correct syntax to use a field from type Enum

      values {
        de = "German"
        en = "English"
        fr = "France"
      }

but I got:

in resource "commercetools_type" "product_asset":
  46:       values {

Blocks of type "values" are not expected here. Did you mean to define argument
"values"? If so, use the equals sign to assign it a value.

The correct syntax is e.g

      values = {
        de = "German"
        en = "English"
        fr = "France"
      }

Can I extend/configure a cart object?

I need to extend a cart object with this:

order: {
chargeName: "chargeName",
chargeCategory: "chargeCategory",
deliveryMethod: "deliveryMethod",
lineType: "lineType",
dateTypeId: "dateTypeId",
expectedDate: "2018-12-05T13:55:00.000Z"
}

How can I do this in a way like shipping methods/zones are extended?

export existing Commercetools environment to Terraform script

Thanks for your great work an effort by developing the terraform provider for Commercetools. This is an awesome solution to have a generic way to create consistent Commercetools environments.

I was wondering if it's also possible to automatically create terraform scripts from an existing CT environment, so we can easily do migrations if something changes, for instance in a Product Type. Or is there a proposed way or best practice to design this?

Thanks in advance!

Terraform import is not fetching current subscriptions state.

This is the subscription in Commercetools:

{
  "id": "2a97cded-7a1c-4ca1-8384-05b8a05335eb",
  "version": 1,
  "createdAt": "2019-06-20T11:00:25.725Z",
  "lastModifiedAt": "2019-06-20T11:00:25.725Z",
  "lastModifiedBy": {
    "clientId": "sphere.impex.1.0",
    "isPlatformClient": false,
    "user": {
      "typeId": "user",
      "id": "876a2e94-ee44-4f4d-a0d1-f710454a9cbe"
    }
  },
  "createdBy": {
    "clientId": "sphere.impex.1.0",
    "isPlatformClient": false,
    "user": {
      "typeId": "user",
      "id": "876a2e94-ee44-4f4d-a0d1-f710454a9cbe"
    }
  },
  "destination": {
    "type": "GoogleCloudPubSub",
    "projectId": "tottus-orion-staging",
    "topic": "commercetools.category-events-staging-pe"
  },
  "messages": [],
  "changes": [
    {
      "resourceTypeId": "category"
    }
  ],
  "format": {
    "type": "Platform"
  },
  "status": "Healthy",
  "key": "category-events"
}

this is the block of Terraform

resource "commercetools_subscription" "category-events" {
  key = "category-events"

  destination = {
    type       = "google_pubsub"
    project_id = "tottus-orion-staging"
    topic      = "commercetools.category-events-staging-pe"
  }

  changes {
    resource_type_ids = ["category"]
  }
}

this is the output of plan:

# commercetools_subscription.category-events will be updated in-place
  ~ resource "commercetools_subscription" "category-events" {
      + destination = {
          + "project_id" = "tottus-orion-staging"
          + "topic"      = "commercetools.category-events-staging-pe"
          + "type"       = "google_pubsub"
        }
        id          = "2a97cded-7a1c-4ca1-8384-05b8a05335eb"
        key         = "category-events"
        version     = 1

      + changes {
          + resource_type_ids = [
              + "category",
            ]
        }
    }

Terraform version: 0.12.9
Provider version: 0.18.3

Invalid type name condition

Hi,
if you look at that code the error is only returned when either the old or new field name is not empty. This looks odd to me. I think that can be removed so that an error is thrown as soon as a user try to change the type of field?

if oldType["name"] != newType["name"] {
if oldType["name"] != "" || newType["name"] == "" {
continue
}
return fmt.Errorf(
"Field '%s' type changed from %s to %s. Changing types is not supported; please remove the field first and re-define it later",
name, oldType["name"], newType["name"])

Adding an action to a `commercetools_api_extension` has no effect

Hi, I have an API extension with a Create action listed. I would like to add the Update action.

The terraform provider understands the update and lists it as a change during the plan stage. When applying the changes the API extension is not updated despite the terraform succeeding.

It seems like a bug. Can someone help me with a fix?

Unexpected EOF when creating Extension

Hi

I'm having an issue when registering an API extension.

I'm seeing a pretty generic error message related to the extension itself. I've turned on Debug logging and can't see any useful logs. I'm loading the accesskey/secret from Systems Manager.

My extension is defined as:

resource "commercetools_api_extension" "ct_extension" {
  key = "commerce-order-apiextension"

  destination {
    type          = "AWSLambda"
    arn           = "${aws_lambda_function.lambda.arn}"
    access_key    = "${aws_iam_access_key.ct_extension_user.id}"
    access_secret = "${aws_iam_access_key.ct_extension_user.secret}"
  }

  trigger {
    resource_type_id = "order"
    actions          = ["Create"]
  }
}

Error message:

Error: Error applying plan:

1 error(s) occurred:

* commercetools_api_extension.ct_extension: 1 error(s) occurred:

* commercetools_api_extension.ct_extension: unexpected EOF

Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.


2019/06/19 14:20:47 [DEBUG] plugin: waiting for all plugin processes to complete...
2019-06-19T14:20:47.652Z [WARN ] plugin: error closing client during Kill: err="connection is shut down"
[terragrunt] 2019/06/19 14:20:47 Hit multiple errors:
exit status 1

I expect the error message doesn't mean much to you either so is there anything else I can be doing to debug this?

Thanks!

Timeout creating a commercetools subscription with tf provider

Trying to create a subscription and it just times out with nothing returned from api :
resource "commercetools_subscription" "nameof_subscription" {
key = "nameof_subscription"
destination = {
type = "SQS"
queue_url = "${242341234}"
access_key = "${124134}"
access_secret = "${12341324134}"
region = "${var.aws_region}"
}
message {
resource_type_id = "product"
types = ["ProductStateTransition"]
}
}

Is this module actively maintained?

Hi, we use that module to manage our infrastructure changes and it looks like there is a lot of room for improvements. Is labd still interested in it or is it better to fork it? Thanks.

Invalid resource type

Hi,
Am trying to create commercetools_cart_discount via terraform and I used the latest plugin as downloaded in suggested(version - 0.21). after trying terraform plan I get a below error is that something can you help us

Issue : -
The provider provider.commercetools does not support resource type
"commercetools_cart_discount".

Terraform Version and commerce tools version used

  • provider.aws: version = "~> 2.60"
  • provider.commercetools: version = "~> 0.21"

Blocks of type "rate" are not expected here

Hi all,

I am trying to use the following TF file with a commercetools_tax_category

resource "commercetools_tax_category" "Medicinal" {
  name = "Medicinal"
  key =  "Medicinal"
  rate {
    name = "Medicinal"
    amount = 0.04
    included_in_price = true
    country = "IO"
  }
}

resource "commercetools_tax_category" "standard" {
  name = "standard"
  key =  "standard"
  rate {
    name = "standard"
    amount = 0.22
    included_in_price = true
    country = "IO"
  }
  rate {
    name = "standard-gb"
    amount = 0.23
    included_in_price = true
    country = "GB"
  }
}

Unfortunately I am bumping in to the following error:

Error: Unsupported block type

  on tax-categories.tf line 4, in resource "commercetools_tax_category" "Medicinal":
   4:   rate {

Blocks of type "rate" are not expected here.


Error: Unsupported block type

  on tax-categories.tf line 15, in resource "commercetools_tax_category" "standard":
  15:   rate {

Blocks of type "rate" are not expected here.


Error: Unsupported block type

  on tax-categories.tf line 21, in resource "commercetools_tax_category" "standard":
  21:   rate {

Blocks of type "rate" are not expected here.

Is there something I am doing wrong or is this a bug/TF versioning issues?

Acceptance tests failing locally

Trying to get the project running locally in order to PR some extra fields that we need (rather then keep creating issues for you guys) however i'm getting two failures in the acceptance tests and looking at the azure pipeline i'm not entirely sure how they're passing there. There are two failing tests, one of which I don't know why it's failing, and the second which is complaining about the key being "new key" instead of "new-key" which is invalid as far as i'm aware. I have included the test output below:


 === RUN   TestAccShippingMethod_createAndUpdateWithID
 --- FAIL: TestAccShippingMethod_createAndUpdateWithID (0.25s)
    testing.go:568: Step 0 error: errors during apply:
        
        Error: Request body does not contain valid JSON.
        
          on C:\Users\Zack\AppData\Local\Temp\tf-test637029460\main.tf line 8:
          (source code not available)

 === RUN   TestAccShippingZone_createAndUpdateWithID
 --- FAIL: TestAccShippingZone_createAndUpdateWithID (0.38s)
    testing.go:568: Step 1 error: errors during apply:
        
        Error: Invalid key 'new key'. Keys may only contain alphanumeric characters, underscores and hyphens and must have a minimum length of 2 characters and maximum length of 256 characters.
        
          on C:\Users\Zack\AppData\Local\Temp\tf-test917373831\main.tf line 2:
          (source code not available)

If you want anything else such as debug output from the tests, please let me know. These have all been run on a real commercetools environment that was created fresh just before the first run of these tests.

Triggers is a block instead of array in tf

For resource "commercetools_api_extension" it currently isn't possible to create a trigger for multiple resource_type_ids, which technically is possible through the commerceTools API.

It isn't a blocker since we can create multiple api_entension resources (1 per trigger)

commercetools api extension doc:
triggers - Array of Trigger - Describes what triggers the extension

Type change in custom type does not actually change the type in CT

Changing a custom type value from f.e. Enum -> String says it succeeded but doesn't actually change it in CommerceTools (formatting here is borked...):

Before

resource "commercetools_type" "custom-order-fields" {
  key = "custom-order-fields"
  name = {
    en = "Custom order fields"
  }

  description = {
    en = "Custom order fields"
  }

  resource_type_ids = ["order"]
  field {
    name = "shipwireServiceLevelCode"

    label = {
      en = "Shipwire service level code"
      nl = "Shipwire service level code"
    }

    type {
      name = "Enum"
      values {
        foo = "bar"
      }
    }
  }

After

resource "commercetools_type" "custom-order-fields" {
  key = "custom-order-fields"
  name = {
    en = "Custom order fields"
  }

  description = {
    en = "Custom order fields"
  }

  resource_type_ids = ["order"]
  field {
    name = "shipwireServiceLevelCode"

    label = {
      en = "Shipwire service level code"
      nl = "Shipwire service level code"
    }

    type {
      name = "String"
    }
  }

TF output:

  ~ commercetools_type.custom-order-fields
      field.1.type.0.name:                           "Enum" => "String"
      field.1.type.0.values.%:                       "7" => "0"
      field.1.type.0.values.economy_international:   "E-INTL" => ""
      field.1.type.0.values.ground_domestic:         "GD" => ""
      field.1.type.0.values.one_day_domestic:        "1D" => ""
      field.1.type.0.values.plus_international:      "PL-INTL" => ""
      field.1.type.0.values.premium_international:   "PM-INTL" => ""
      field.1.type.0.values.standard_international:  "INTL" => ""
      field.1.type.0.values.two_day_domestic:        "2D" => ""

No ability to configure zone rate and shipping rate

ShippingZone schema.Resource doesn't have possibility to configure zone Rates and shipping Rates.

F.E. ShiipingRate and ZoneRate should be configured in such way:

zoneRates: [{
    zone: {
        name: "Zone UK"
    },
    shippingRates: [{
        price: {
            currencyCode: "GBP",
            centAmount: 1000
        }
    }]
}]

Latest [0.5.4] version is not providing a way to configure Rates for zones and shippings.
Possible way of usage:

resource "commercetools_shipping_zone" "standart" {
  name = "Zone UK Test"
  key = "standart-shipping-zone"
  description = "Standard shipping method"
  location = {
      country = "GB"
  }
}

resource "commercetools_shipping_zone_rate" "standart-shipping-zone-rate-UK" {
  shipping_zone_key = "${commercetools_shipping_zone.standard.key}"
  price = {
    currencyCode = "GBP"
    centAmount = 1000
  }
}

Subscription Resource Stores Access Key Unencrypted in State

The subscription resource type requires a parameter access_secret which is stored in the state file in plaintext. While the state file can be encrypted, Terraform's own iam_access_key resource suggest supplying a PGP key that can be used to additionally encrypt the secret before storing it in state.

Terraforms management of secrets in state does seem to cause a fair bit of debate - and it has been proposed that some encrypt / decrypt interpolation functions should be added to Terraform core hashicorp/terraform#15434.

I'm not sure if maybe there is a middle-ground position that we could take in the meantime? Perhaps adding another optional parameters access_secret_encrypted?

Changing API client does not work

When changing the configuration of an API client, the terraform plan shows that it will make the change and the apply shows the change being made, but the change has not happened. I understand that this is probably due to API clients being immutable.

The way this should probably work is the terraform plan should show that the resource needs to be replaced (destroyed and recreated) and then the apply destroys the API client and creates a new one with the updated configuration.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.