Skip to content

Step 5. Create your MACH composer stack

MACH composer is undergoing a major, backwards compatible overhaul

MACH composer has been rewritten in Golang, coming from a Python version. We've done this because the Golang ecosystem is more suitable for a tool like this, as it is also the language in which Hashicorp builds Terraform itself.

Because of this, some commands might not be available yet in the Golang version; particularly the mach-composer bootstrap command is not available, which makes it a bit harder to start up. However, based on the examples in the GitHub repository, you should be able to get started without the bootstrap command.

For creating components, please instead of mach-composer bootstrap component, use mach-composer-cookiecutter.

We do currently recommend to use the latest version (2.14.x).

If you are still on the Python version, the bootstrap command will still work.

To create a new MACH composer configuration file, run

mach-composer bootstrap config

A configuration will be created and can be used as input for MACH composer.

An example:

---
mach_composer:
  version: 1.0.0
global:
  environment: test
  cloud: azure
  terraform_config:
    azure_remote_state:
      resource_group: my-shared-rg
      storage_account: mysharedsaterra
      container_name: tfstate
      state_folder: test
  azure:
    tenant_id: e180345a-b3e1-421f-b448-672ab50d8502
    subscription_id: 086bd7e7-0755-44ab-a730-7a0b8ad4883f
    region: westeurope
sites:
  - identifier: my-site
    endpoints:
      main: api.tst.mach-example.net
    commercetools:
      project_key: my-site-tst
      client_id: ...
      client_secret: ...
      scopes: manage_project:my-site-tst manage_api_clients:my-site-tst view_api_clients:my-site-tst
      languages:
        - en-GB
        - nl-NL
      currencies:
        - GBP
        - EUR
      countries:
        - GB
        - NL
    components:
      - name: payment
        variables:
          STRIPE_ACCOUNT_ID: 0123456789
        secrets:
          STRIPE_SECRET_KEY: secret-value
components:
  - name: payment
    source: git::ssh://git@github.com/your-project/components/payment-component.git//terraform
    endpoints:
      main: main
    version: e638e57

See Syntax for all configuration options.

6. Deploy

You can deploy your current configuration by running

$ mach-composer apply

If you wish to review the changes before applying them, run

$ mach-composer plan

Using Docker image

You can invoke MACH by running the Docker image:
$ docker run --rm --volume $(pwd):/code docker.pkg.github.com/mach-composer/mach-composer-cli/mach apply

You do need to provide the docker container with the necessary environment variables to be able to authenticate with the cloud provider. More info on that in the deployment section

Example files

You can find example files needed for preparing the infrastructure and a configuration file on GitHub in the /examples directory

Further reading