Rust Discover Nodes for Cloud Providers

node-discover is a Rust library and command line tool to discover ip addresses of nodes in cloud environments based on meta information like tags provided by the environment. It is a port to Rust of the excellent go-discover library.

The configuration for the providers is provided as a list of key=val key=val ... tuples.

Duplicate keys are reported as error and the provider is determined through the provider key.

Supported Providers

The following cloud providers have implementations in the node-discover/src/providers package.

Providers comming soon

Config Example

```

Aliyun (Alibaba) Cloud

provider=aliyun region=... tagkey=consul tagvalue=... accesskeyid=... accesskeysecret=...

Amazon AWS

provider=aws region=eu-west-1 tagkey=consul tagvalue=... accesskeyid=... secretaccesskey=...

DigitalOcean

provider=digitalocean region=... tagname=... apitoken=...

Google Cloud

provider=gce projectname=... zonepattern=eu-west-* tagvalue=consul credentialsfile=...

Linode

provider=linode tagname=... region=us-east addresstype=privatev4 apitoken=...

mDNS

provider=mdns service=consul domain=local

Microsoft Azure

provider=azure tagname=consul tagvalue=... tenantid=... clientid=... subscriptionid=... secretaccess_key=...

Openstack

provider=os tagkey=consul tagvalue=server username=... password=... auth_url=...

Scaleway

provider=scaleway organization=my-org tag_name=consul-server token=... region=...

SoftLayer

provider=softlayer datacenter=dal06 tagvalue=consul username=... apikey=...

TencentCloud

provider=tencentcloud region=ap-guangzhou tagkey=consul tagvalue=... accesskeyid=... accesskeysecret=...

Triton

provider=triton account=testaccount url=https://us-sw-1.api.joyentcloud.com keyid=... tagkey=consul-role tag_value=server

vSphere

provider=vsphere categoryname=consul-role tagname=consul-server host=... user=... password=... insecure_ssl=[true|false]

Packet

provider=packet authtoken=token project=uuid url=... addresstype=...

Kubernetes

provider=k8s label_selector="app = consul-server" ```

Command Line Tool Usage

Install the command line tool with:

cargo install node-discover --all-features

Then run it with:

$ node-discover help $ node-discover help aws $ node-discover addrs provider=aws region=eu-west-1 ...

Library Usage

Active providers in Cargo.toml ``` [dependencies]

Choose which providers you need in features list

node-discover = { version = "x.y.z", features = ["digitalocean", "aws"] } ```

For complete API documentation, see docs.rs. crates.io

Testing

Configuration tests can be run with:

$ cargo test

By default tests that communicate with providers do not run unless credentials are set for that provider. To run provider tests you must set the necessary environment variables.

Note: This will make real API calls to the account provided by the credentials.

$ AWS_ACCESS_KEY_ID=... AWS_ACCESS_KEY_SECRET=... AWS_REGION=... cargo test

This requires resources to exist that match those specified in tests (eg instance tags in the case of AWS). To create these resources, there are sets of Terraform configuration in the tests/tf directory for supported providers.

You must use the same account and access credentials above. The same environment variables should be applicable and read by Terraform.

$ cd tests/tf/aws $ export AWS_ACCESS_KEY_ID=... AWS_ACCESS_KEY_SECRET=... AWS_REGION=... $ terraform init ... $ terraform apply ...

After Terraform successfully runs, you should be able to successfully run the tests, assuming you have exported credentials into your environment:

$ cargo test

To destroy the resources you need to use Terraform again:

$ cd tests/tf/aws $ terraform destroy ...

Note: There should be no requirements to create and test these resources other than credentials and Terraform. This is to ensure tests can run in development and CI environments consistently across all providers.