Consul IO is a CLI tool used to import and export configuration files from a specified directory to/from the Consul KV store.
You can install the latest version using the go install
command:
go install github.com/turknet/consul-io@latest
consul-io version
You can run the CLI tool using the following command:
consul-io help
import [directory]
: Upload config files to Consul KV storeexport [directory]
: Download config files from Consul KV storevault-search [search-term]
: Search for a term in Vault KV storeversion
: Print the version number of Consul IOhelp
: Display help for consul-io
--consul-addr
: Specifies the address of the Consul server. The default value ishttp://localhost:8500
.--ignore
: Specifies one or more paths to ignore during the import process. This option is useful if you want to skip certain directories or files.--token
: Optional ACL token for Consul authentication. If provided, all operations will be authenticated using this token.--vault-addr
: Vault server address (e.g. http://vault:8200)--auth-type
: Authentication type for Vault (ldap)--username
: Username for Vault authentication--password
: Password for Vault authentication--path
: Optional specific path to search in Vault[directory]
: The directory containing the configuration files you want to upload or the directory to which you want to export files.
consul-io --consul-addr=http://localhost:8500 --token=my-secret-token import test --ignore="test/team1/apps/project2"
This command finds the files with the .production
extension in the test
directory and uploads them to the Consul KV store.
# Search in all KV paths
consul-io vault-search "search-term" \
--vault-addr="http://vault:8200" \
--auth-type="ldap" \
--username="your-username" \
--password="your-password"
# Search in a specific path
consul-io vault-search "search-term" \
--vault-addr="http://vault:8200" \
--auth-type="ldap" \
--username="your-username" \
--password="your-password" \
--path="secret/specific/path"
This command searches for the specified term in Vault KV store and displays matching values with colored output:
- Path is shown in green
- Keys are shown in yellow
- Values are shown in red
consul-io --consul-addr=http://localhost:8500 --token=my-secret-token export test
This command downloads the configuration files from the Consul KV store and saves them in the test
directory, maintaining the same structure.
Consul IO provides colorful console output to improve readability:
Errors
are displayed inred
.Warnings
are displayed inyellow
.Success messages
are displayed ingreen
.Informational messages
are displayed incyan
.
consul-io/
├── cmd/
│ └── root.go
├── test/
│ ├── team1/apps/
│ │ ├── project1/
│ │ │ └── .env.production
│ │ ├── project2/
│ │ │ └── appsettings.json.production
│ ├── team2/apps/
│ │ ├── project1/
│ │ │ └── .env.production
│ │ │ └── appsettings.json.production
├── go.mod
├── go.sum
└── main.go
-
cmd/
: Contains the CLI command files. -
go.mod
: Contains Go module information. -
go.sum
: Contains the verification information for the Go modules. -
main.go
: The entry point of the program. -
test/
: Example directory containing the configuration files you want to upload or the directory where you want to export files.
-
github.com/hashicorp/consul/api : Library used to interact with the Consul API.
-
github.com/spf13/cobra : Library used to create the command line interface.
-
github.com/fatih/color : Library used for adding color to the terminal output.