# create

Use `greymatter create` to **create a specific object** in the Grey Matter mesh. Objects can be `zone`, `proxy`, `domain`, `route`, `shared_rules`, `cluster`, `catalog-mesh`, and `catalog-service`.

## Usage

```bash
greymatter create <object type> [flags]
```

### Sample Usage

#### Create from JSON File

Resources can be created directly from files on disk through shell redirects like shown below. Using the file `domain-catalog.json` with the following content:

```
{
  "domain_key": "domain-catalog",
  "force_https": true,
  "gzip_enabled": false,
  "name": "*",
  "port": 10808,
  "zone_key": "zone-default-zone"
}
```

`greymatter create domain < domain-catalog.json` will create the domain object from the given spec.

```
$ ./greymatter create domain < domain-catalog.json
{
  "aliases": null,
  "checksum": "27f6729b9e28ca28a903fa669a5764f7c0655d6995a69dc17973032fe1372cec",
  "cors_config": null,
  "custom_headers": null,
  "domain_key": "domain-catalog",
  "force_https": true,
  "gzip_enabled": false,
  "name": "*",
  "port": 10808,
  "redirects": null,
  "zone_key": "zone-default-zone"
}
```

#### Interactive Editor

By setting the `EDITOR` environment variable, the `greymatter` tool will open the editor of choice and let the user create the object directly.

```bash
export EDITOR=vim
greymatter create listener
```

If a default object (in this case a listener) is not set, the editor of choice will contain an empty json object `{}`; otherwise it will contain a skeleton listener object that looks something like the following indicating the fields that can be set:

```bash
{
  "access_loggers": {
    "http_connection_loggers": {
      "disabled": false,
      "file_loggers": null,
      "http_grpc_access_loggers": null
    },
    "http_upstream_loggers": {
      "disabled": false,
      "file_loggers": null,
      "http_grpc_access_loggers": null
    }
  },
  "active_http_filters": null,
  "active_network_filters": null,
  "checksum": "",
  "delayed_close_timeout": "",
  "domain_keys": null,
  "drain_timeout": "",
  "http2_protocol_options": null,
  "http_filters": null,
  "http_protocol_options": null,
  "ip": "",
  "listener_key": "default",
  "name": "default",
  "network_filters": null,
  "port": 0,
  "protocol": "",
  "request_timeout": "",
  "secret": {
    "secret_key": "",
    "secret_name": "",
    "secret_validation_name": "",
    "subject_names": null,
    "ecdh_curves": null,
    "set_current_client_cert_details": {
      "uri": false
    },
    "checksum": ""
  },
  "stream_idle_timeout": "",
  "tracing_config": null,
  "use_remote_address": false,
  "zone_key": "default"
}
```

There are a few option to set default objects. Take a listener, for instance, you can set a listener template with one of the two flags below:

```bash
  --default-listener-key string  the key that points to the listener object that should act as a template.
  --default-object-key string    the default key that points to the object that should act as a template. Precedence is given to specific object type defaults. (default "default")
```

Typically, the mesh will have a listener called `default` which will be used as a template by default without any flags. You can confirm this by running `greymatter get listener default`. If you get an 400 error message when running the command, it will need to be set up by creating a `default` listener just like any other listeners.

Another way to do this is by copying from an existing listener. Say there is an existing listener whose key is `listener-slo` - you can create a new listener by duplicating this listener and changing fields necessary by running:

```bash
greymatter create listener --default-listener-key listener-slo
```

Key is a unique field, so trying to save without changing a key after duplicating will result in a duplicate key error.

#### Help

To list available commands run with the global help flag:

```bash
greymatter create --help
```

## Questions

{% hint style="success" %}
**Need help with the CLI?**

Create an account at [Grey Matter Support](https://support.greymatter.io/support/home) to reach our team.
{% endhint %}
