consul/website/content/commands/namespace/write.mdx

87 lines
2.1 KiB
Plaintext
Raw Normal View History

---
layout: commands
2020-04-07 18:55:19 +00:00
page_title: 'Commands: Namespace Write'
---
# Consul Namespace Write
Command: `consul namespace write`
Corresponding HTTP API Endpoint: [\[PUT\] /v1/namespace/:name](/consul/api-docs/namespaces#update-a-namespace)
<EnterpriseAlert />
This `namespace write` command creates or updates a namespace's configuration from its full definition. This was added in Consul Enterprise 1.7.0.
The table below shows this command's [required ACLs](/consul/api-docs/api-structure#authentication). Configuration of
[blocking queries](/consul/api-docs/features/blocking) and [agent caching](/consul/api-docs/features/caching)
are not supported from commands, but may be from the corresponding HTTP endpoint.
| ACL Required |
| ---------------- |
| `operator:write` |
## Usage
Usage: `consul namespace write <namespace definition>`
The `<namespace definition>` must either be a file path or `-` to indicate that
the definition should be read from stdin. The definition can be in either JSON
or HCL format. See [here](/consul/docs/enterprise/namespaces#namespace-definition) for a description of the namespace definition.
#### Command Options
2020-04-07 18:55:19 +00:00
- `-format=<string>` - How to output the results. The choices are: pretty or json
2020-04-07 18:55:19 +00:00
- `-meta` - Indicates that namespace metadata such as the raft indices should be
shown for the namespace
2020-04-07 18:55:19 +00:00
#### API Options
@include 'http_api_partition_options.mdx'
@include 'http_api_options_client.mdx'
@include 'http_api_options_server.mdx'
## Examples
Create a new Namespace:
2020-05-19 18:32:38 +00:00
```shell-session
$ consul namespace write - <<< 'Name = "team-1"'
Name: team-1
Description:
```
Showing Raft Metadata:
2020-05-19 18:32:38 +00:00
```shell-session
$ consul namespace write -meta - <<< 'Name = "team-1"'
Name: team-1
Description:
Create Index: 339
Modify Index: 344
```
JSON Format:
2020-05-19 18:32:38 +00:00
```shell-session
$ cat ns.hcl
Name = "foo"
Description = "Example Namespace"
Meta {
team-id = "574407f3-8b26-4c84-8e51-028bb8cbdd37"
}
$ consul namespace write -format=json ns.hcl
{
"Name": "foo",
"Description": "Example Namespace",
"Meta": {
"team-id": "574407f3-8b26-4c84-8e51-028bb8cbdd37"
},
"CreateIndex": 352,
"ModifyIndex": 352
}
```