terraform-provider-commercetools
terraform-provider-commercetools copied to clipboard
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}"
]
}
Would be really good to hear feedback about this issue :)
I've been thinking about this, and indeed there only seem to be two ways to solve this:
- Run terraform twice, once without the state transition restrictions and one with them.
- What you suggest, this would be similar to the tax category rate resource, which does not have an explicit endpoint in the Commercetools API. You have to make sure you lock the correct state ids to prevent concurrent modification of the same state.
Any updates on this? Would be a really helpful thing to have.
I'd definitely accept a pull request if someone made it like this. I do think there might be a creative solution using locks, creating the state resource and then updating the state resource.
However, given that this provider is far from feature complete I don't think I can prioritize creating this over making the provider more feature complete and general maintenance.
We are also running into this issue. Since there is a linked pull request, I can perhaps help with implementing the functionality if help is still required. Is there any update?
Same problem here, would love to have it solved. Thanks!
Agreed we need to fix this. As mentioned we need to support the following
resource "commercetools_state_transitions" "transition_1" {
from = commercetools_state.state_1.id
to = [
commercetools_state.state_2.id
]
}
resource "commercetools_state_transitions" "transition_2" {
from = commercetools_state.state_2.id
to = [
commercetools_state.state_1.id
]
}
I think the easiest approach is to then drop support for inline transitions, so that we only have to support transitions as a separate resource
@mvantellingen : Don't forget the state id, the transaction should be assigned to ;)
The transition is set to the state defined in the from
attribute. I've added a warning when multiple state_transitions are defined for the same from
since we can only define one set of transitions per state
@mvantellingen : is this some kind of provider/Terraform restriction? Because by API you can define multiple transitions per state...
Yes you can define multiple transitions per state, but only all at once via the setTransitions
action. So there is no addTransition
or removeTransition
.
When managing tax rates, or shipping zones this way we can use separate resources because for example the tax rate has actions like addTaxRate
, removeTaxRate
, replaceTaxRate
The commercetools API is unfortunately not always consistent :-)
@mvantellingen : Now I understand. Have you placed a feature request regarding the missing add/remove update actions? If not, I could do that..
Yeah would appreciate that. You can reference this issue
@mvantellingen : The feature request has now been recorded. We'll see if and when it will be implemented.
Will be fixed in 1.5.0