1. Packages
  2. Commercetools Provider
  3. API Docs
  4. State
commercetools 1.19.3 published on Friday, Apr 4, 2025 by labd

commercetools.State

Explore with Pulumi AI

The commercetools platform allows you to model states of certain objects, such as orders, line items, products, reviews, and payments to define finite state machines reflecting the business logic you’d like to implement.

See also the State API Documentation

Example Usage

import * as pulumi from "@pulumi/pulumi";
import * as commercetools from "@pulumi/commercetools";

const reviewUnreviewed = new commercetools.State("reviewUnreviewed", {
    description: {
        en: "Not reviewed yet",
    },
    initial: true,
    key: "review-unreviewed",
    name: {
        en: "Unreviewed",
    },
    roles: ["ReviewIncludedInStatistics"],
    type: "ReviewState",
});
const productForSale = new commercetools.State("productForSale", {
    description: {
        en: "Regularly stocked product.",
    },
    initial: true,
    key: "product-for-sale",
    name: {
        en: "For Sale",
    },
    type: "ProductState",
});
const productClearance = new commercetools.State("productClearance", {
    description: {
        en: "The product line will not be ordered again.",
    },
    key: "product-clearance",
    name: {
        en: "On Clearance",
    },
    type: "ProductState",
});
Copy
import pulumi
import pulumi_commercetools as commercetools

review_unreviewed = commercetools.State("reviewUnreviewed",
    description={
        "en": "Not reviewed yet",
    },
    initial=True,
    key="review-unreviewed",
    name={
        "en": "Unreviewed",
    },
    roles=["ReviewIncludedInStatistics"],
    type="ReviewState")
product_for_sale = commercetools.State("productForSale",
    description={
        "en": "Regularly stocked product.",
    },
    initial=True,
    key="product-for-sale",
    name={
        "en": "For Sale",
    },
    type="ProductState")
product_clearance = commercetools.State("productClearance",
    description={
        "en": "The product line will not be ordered again.",
    },
    key="product-clearance",
    name={
        "en": "On Clearance",
    },
    type="ProductState")
Copy
package main

import (
	"github.com/pulumi/pulumi-terraform-provider/sdks/go/commercetools/commercetools"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := commercetools.NewState(ctx, "reviewUnreviewed", &commercetools.StateArgs{
			Description: pulumi.StringMap{
				"en": pulumi.String("Not reviewed yet"),
			},
			Initial: pulumi.Bool(true),
			Key:     pulumi.String("review-unreviewed"),
			Name: pulumi.StringMap{
				"en": pulumi.String("Unreviewed"),
			},
			Roles: pulumi.StringArray{
				pulumi.String("ReviewIncludedInStatistics"),
			},
			Type: pulumi.String("ReviewState"),
		})
		if err != nil {
			return err
		}
		_, err = commercetools.NewState(ctx, "productForSale", &commercetools.StateArgs{
			Description: pulumi.StringMap{
				"en": pulumi.String("Regularly stocked product."),
			},
			Initial: pulumi.Bool(true),
			Key:     pulumi.String("product-for-sale"),
			Name: pulumi.StringMap{
				"en": pulumi.String("For Sale"),
			},
			Type: pulumi.String("ProductState"),
		})
		if err != nil {
			return err
		}
		_, err = commercetools.NewState(ctx, "productClearance", &commercetools.StateArgs{
			Description: pulumi.StringMap{
				"en": pulumi.String("The product line will not be ordered again."),
			},
			Key: pulumi.String("product-clearance"),
			Name: pulumi.StringMap{
				"en": pulumi.String("On Clearance"),
			},
			Type: pulumi.String("ProductState"),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
Copy
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Commercetools = Pulumi.Commercetools;

return await Deployment.RunAsync(() => 
{
    var reviewUnreviewed = new Commercetools.State("reviewUnreviewed", new()
    {
        Description = 
        {
            { "en", "Not reviewed yet" },
        },
        Initial = true,
        Key = "review-unreviewed",
        Name = 
        {
            { "en", "Unreviewed" },
        },
        Roles = new[]
        {
            "ReviewIncludedInStatistics",
        },
        Type = "ReviewState",
    });

    var productForSale = new Commercetools.State("productForSale", new()
    {
        Description = 
        {
            { "en", "Regularly stocked product." },
        },
        Initial = true,
        Key = "product-for-sale",
        Name = 
        {
            { "en", "For Sale" },
        },
        Type = "ProductState",
    });

    var productClearance = new Commercetools.State("productClearance", new()
    {
        Description = 
        {
            { "en", "The product line will not be ordered again." },
        },
        Key = "product-clearance",
        Name = 
        {
            { "en", "On Clearance" },
        },
        Type = "ProductState",
    });

});
Copy
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.commercetools.State;
import com.pulumi.commercetools.StateArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        var reviewUnreviewed = new State("reviewUnreviewed", StateArgs.builder()
            .description(Map.of("en", "Not reviewed yet"))
            .initial(true)
            .key("review-unreviewed")
            .name(Map.of("en", "Unreviewed"))
            .roles("ReviewIncludedInStatistics")
            .type("ReviewState")
            .build());

        var productForSale = new State("productForSale", StateArgs.builder()
            .description(Map.of("en", "Regularly stocked product."))
            .initial(true)
            .key("product-for-sale")
            .name(Map.of("en", "For Sale"))
            .type("ProductState")
            .build());

        var productClearance = new State("productClearance", StateArgs.builder()
            .description(Map.of("en", "The product line will not be ordered again."))
            .key("product-clearance")
            .name(Map.of("en", "On Clearance"))
            .type("ProductState")
            .build());

    }
}
Copy
resources:
  reviewUnreviewed:
    type: commercetools:State
    properties:
      description:
        en: Not reviewed yet
      initial: true
      key: review-unreviewed
      name:
        en: Unreviewed
      roles:
        - ReviewIncludedInStatistics
      type: ReviewState
  productForSale:
    type: commercetools:State
    properties:
      description:
        en: Regularly stocked product.
      initial: true
      key: product-for-sale
      name:
        en: For Sale
      type: ProductState
  productClearance:
    type: commercetools:State
    properties:
      description:
        en: The product line will not be ordered again.
      key: product-clearance
      name:
        en: On Clearance
      type: ProductState
Copy

Create State Resource

Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.

Constructor syntax

new State(name: string, args: StateArgs, opts?: CustomResourceOptions);
@overload
def State(resource_name: str,
          args: StateArgs,
          opts: Optional[ResourceOptions] = None)

@overload
def State(resource_name: str,
          opts: Optional[ResourceOptions] = None,
          type: Optional[str] = None,
          description: Optional[Mapping[str, str]] = None,
          initial: Optional[bool] = None,
          key: Optional[str] = None,
          name: Optional[Mapping[str, str]] = None,
          roles: Optional[Sequence[str]] = None)
func NewState(ctx *Context, name string, args StateArgs, opts ...ResourceOption) (*State, error)
public State(string name, StateArgs args, CustomResourceOptions? opts = null)
public State(String name, StateArgs args)
public State(String name, StateArgs args, CustomResourceOptions options)
type: commercetools:State
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.

Parameters

name This property is required. string
The unique name of the resource.
args This property is required. StateArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name This property is required. str
The unique name of the resource.
args This property is required. StateArgs
The arguments to resource properties.
opts ResourceOptions
Bag of options to control resource's behavior.
ctx Context
Context object for the current deployment.
name This property is required. string
The unique name of the resource.
args This property is required. StateArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name This property is required. string
The unique name of the resource.
args This property is required. StateArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
name This property is required. String
The unique name of the resource.
args This property is required. StateArgs
The arguments to resource properties.
options CustomResourceOptions
Bag of options to control resource's behavior.

Constructor example

The following reference example uses placeholder values for all input properties.

var stateResource = new Commercetools.State("stateResource", new()
{
    Type = "string",
    Description = 
    {
        { "string", "string" },
    },
    Initial = false,
    Key = "string",
    Name = 
    {
        { "string", "string" },
    },
    Roles = new[]
    {
        "string",
    },
});
Copy
example, err := commercetools.NewState(ctx, "stateResource", &commercetools.StateArgs{
Type: pulumi.String("string"),
Description: pulumi.StringMap{
"string": pulumi.String("string"),
},
Initial: pulumi.Bool(false),
Key: pulumi.String("string"),
Name: pulumi.StringMap{
"string": pulumi.String("string"),
},
Roles: pulumi.StringArray{
pulumi.String("string"),
},
})
Copy
var stateResource = new State("stateResource", StateArgs.builder()
    .type("string")
    .description(Map.of("string", "string"))
    .initial(false)
    .key("string")
    .name(Map.of("string", "string"))
    .roles("string")
    .build());
Copy
state_resource = commercetools.State("stateResource",
    type="string",
    description={
        "string": "string",
    },
    initial=False,
    key="string",
    name={
        "string": "string",
    },
    roles=["string"])
Copy
const stateResource = new commercetools.State("stateResource", {
    type: "string",
    description: {
        string: "string",
    },
    initial: false,
    key: "string",
    name: {
        string: "string",
    },
    roles: ["string"],
});
Copy
type: commercetools:State
properties:
    description:
        string: string
    initial: false
    key: string
    name:
        string: string
    roles:
        - string
    type: string
Copy

State Resource Properties

To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

Inputs

In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.

The State resource accepts the following input properties:

Type This property is required. string
StateType
Description Dictionary<string, string>
Description of the State as localized string.
Initial bool
A state can be declared as an initial state for any state machine. When a workflow starts, this first state must be an initial state
Key string
Name Dictionary<string, string>
Name of the State as localized string.
Roles List<string>
State Role
Type This property is required. string
StateType
Description map[string]string
Description of the State as localized string.
Initial bool
A state can be declared as an initial state for any state machine. When a workflow starts, this first state must be an initial state
Key string
Name map[string]string
Name of the State as localized string.
Roles []string
State Role
type This property is required. String
StateType
description Map<String,String>
Description of the State as localized string.
initial Boolean
A state can be declared as an initial state for any state machine. When a workflow starts, this first state must be an initial state
key String
name Map<String,String>
Name of the State as localized string.
roles List<String>
State Role
type This property is required. string
StateType
description {[key: string]: string}
Description of the State as localized string.
initial boolean
A state can be declared as an initial state for any state machine. When a workflow starts, this first state must be an initial state
key string
name {[key: string]: string}
Name of the State as localized string.
roles string[]
State Role
type This property is required. str
StateType
description Mapping[str, str]
Description of the State as localized string.
initial bool
A state can be declared as an initial state for any state machine. When a workflow starts, this first state must be an initial state
key str
name Mapping[str, str]
Name of the State as localized string.
roles Sequence[str]
State Role
type This property is required. String
StateType
description Map<String>
Description of the State as localized string.
initial Boolean
A state can be declared as an initial state for any state machine. When a workflow starts, this first state must be an initial state
key String
name Map<String>
Name of the State as localized string.
roles List<String>
State Role

Outputs

All input properties are implicitly available as output properties. Additionally, the State resource produces the following output properties:

Id string
The provider-assigned unique ID for this managed resource.
Version double
Id string
The provider-assigned unique ID for this managed resource.
Version float64
id String
The provider-assigned unique ID for this managed resource.
version Double
id string
The provider-assigned unique ID for this managed resource.
version number
id str
The provider-assigned unique ID for this managed resource.
version float
id String
The provider-assigned unique ID for this managed resource.
version Number

Look up Existing State Resource

Get an existing State resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

public static get(name: string, id: Input<ID>, state?: StateState, opts?: CustomResourceOptions): State
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        description: Optional[Mapping[str, str]] = None,
        initial: Optional[bool] = None,
        key: Optional[str] = None,
        name: Optional[Mapping[str, str]] = None,
        roles: Optional[Sequence[str]] = None,
        type: Optional[str] = None,
        version: Optional[float] = None) -> State
func GetState(ctx *Context, name string, id IDInput, state *StateState, opts ...ResourceOption) (*State, error)
public static State Get(string name, Input<string> id, StateState? state, CustomResourceOptions? opts = null)
public static State get(String name, Output<String> id, StateState state, CustomResourceOptions options)
resources:  _:    type: commercetools:State    get:      id: ${id}
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
resource_name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
The following state arguments are supported:
Description Dictionary<string, string>
Description of the State as localized string.
Initial bool
A state can be declared as an initial state for any state machine. When a workflow starts, this first state must be an initial state
Key string
Name Dictionary<string, string>
Name of the State as localized string.
Roles List<string>
State Role
Type string
StateType
Version double
Description map[string]string
Description of the State as localized string.
Initial bool
A state can be declared as an initial state for any state machine. When a workflow starts, this first state must be an initial state
Key string
Name map[string]string
Name of the State as localized string.
Roles []string
State Role
Type string
StateType
Version float64
description Map<String,String>
Description of the State as localized string.
initial Boolean
A state can be declared as an initial state for any state machine. When a workflow starts, this first state must be an initial state
key String
name Map<String,String>
Name of the State as localized string.
roles List<String>
State Role
type String
StateType
version Double
description {[key: string]: string}
Description of the State as localized string.
initial boolean
A state can be declared as an initial state for any state machine. When a workflow starts, this first state must be an initial state
key string
name {[key: string]: string}
Name of the State as localized string.
roles string[]
State Role
type string
StateType
version number
description Mapping[str, str]
Description of the State as localized string.
initial bool
A state can be declared as an initial state for any state machine. When a workflow starts, this first state must be an initial state
key str
name Mapping[str, str]
Name of the State as localized string.
roles Sequence[str]
State Role
type str
StateType
version float
description Map<String>
Description of the State as localized string.
initial Boolean
A state can be declared as an initial state for any state machine. When a workflow starts, this first state must be an initial state
key String
name Map<String>
Name of the State as localized string.
roles List<String>
State Role
type String
StateType
version Number

Package Details

Repository
commercetools labd/terraform-provider-commercetools
License
Notes
This Pulumi package is based on the commercetools Terraform Provider.