diff --git a/README.md b/README.md index 7743edcd..7e61ba97 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ function. * SoftLayer [Config options](https://github.com/hashicorp/go-discover/blob/master/provider/softlayer/softlayer_discover.go#L16-L25) * Triton [Config options](https://github.com/hashicorp/go-discover/blob/master/provider/triton/triton_discover.go#L17-L27) * vSphere [Config options](https://github.com/hashicorp/go-discover/blob/master/provider/vsphere/vsphere_discover.go#L148-L155) + * Packet [Config options](https://github.com/hashicorp/go-discover/blob/master/provider/packet/packet_discover.go#L25-L35) HashiCorp maintains acceptance tests that regularly allocate and run tests with real resources to verify the behavior of several of these providers. Those @@ -68,6 +69,9 @@ provider=triton account=testaccount url=https://us-sw-1.api.joyentcloud.com key_ # vSphere provider=vsphere category_name=consul-role tag_name=consul-server host=... user=... password=... insecure_ssl=[true|false] + +# Packet +provider=packet auth_token=token project=uuid url=... address_type=... ``` ## Command Line Tool Usage diff --git a/provider/packet/packet_discover.go b/provider/packet/packet_discover.go index 510e977a..5ad1eead 100644 --- a/provider/packet/packet_discover.go +++ b/provider/packet/packet_discover.go @@ -23,19 +23,24 @@ func (p *Provider) SetUserAgent(s string) { // Help function func (p *Provider) Help() string { return `Packet: - provider: "packet" - packet_project: UUID of packet project - packet_url: Packet REST URL - packet_auth_token: Packet authentication token - address_type: "private_v4", "public_v4" or "public_v6". Defaults to "private_v4". - ` + provider: "packet" + project: UUID of packet project. Required + auth_token: Packet authentication token. Required + url: Packet REST URL. Optional + address_type: "private_v4", "public_v4" or "public_v6". Defaults to "private_v4". Optional + + Variables can also be provided by environmental variables: + export PACKET_PROJECT for project + export PACKET_URL for url + export PACKET_AUTH_TOKEN for auth_token +` } // Addrs function func (p *Provider) Addrs(args map[string]string, l *log.Logger) ([]string, error) { - authToken := argsOrEnv(args, "packet_auth_token", "PACKET_AUTH_TOKEN") - projectID := argsOrEnv(args, "packet_project", "PACKET_PROJECT") - packetURL := argsOrEnv(args, "packet_url", "PACKET_URL") + authToken := argsOrEnv(args, "auth_token", "PACKET_AUTH_TOKEN") + projectID := argsOrEnv(args, "project", "PACKET_PROJECT") + packetURL := argsOrEnv(args, "url", "PACKET_URL") addressType := args["address_type"] if addressType != "private_v4" && addressType != "public_v4" && addressType != "public_v6" { @@ -51,7 +56,7 @@ func (p *Provider) Addrs(args map[string]string, l *log.Logger) ([]string, error var devices []packngo.Device if projectID == "" { - return nil, fmt.Errorf("discover-packet: 'packet_project' parameter must be provider") + return nil, fmt.Errorf("discover-packet: 'project' parameter must be provider") } devices, _, err = c.Devices.List(projectID, nil) diff --git a/provider/packet/packet_discover_test.go b/provider/packet/packet_discover_test.go index f9dfc726..2c98bafa 100644 --- a/provider/packet/packet_discover_test.go +++ b/provider/packet/packet_discover_test.go @@ -14,16 +14,16 @@ var _ discover.ProviderWithUserAgent = (*packet.Provider)(nil) func TestAddrsDefault(t *testing.T) { args := discover.Config{ - "provider": "packet", - "packet_auth_token": os.Getenv("PACKET_TOKEN"), - "packet_project": os.Getenv("PACKET_PROJECT"), + "provider": "packet", + "auth_token": os.Getenv("PACKET_TOKEN"), + "project": os.Getenv("PACKET_PROJECT"), } - if args["packet_auth_token"] == "" { + if args["auth_token"] == "" { t.Skip("Packet credentials missing") } - if args["packet_project"] == "" { + if args["project"] == "" { t.Skip("Packet project UUID missing") } @@ -43,17 +43,17 @@ func TestAddrsDefault(t *testing.T) { func TestAddrsPublicV6(t *testing.T) { args := discover.Config{ - "provider": "packet", - "packet_auth_token": os.Getenv("PACKET_TOKEN"), - "packet_project": os.Getenv("PACKET_PROJECT"), - "address_type": "public_v6", + "provider": "packet", + "auth_token": os.Getenv("PACKET_TOKEN"), + "project": os.Getenv("PACKET_PROJECT"), + "address_type": "public_v6", } - if args["packet_auth_token"] == "" { + if args["auth_token"] == "" { t.Skip("Packet credentials missing") } - if args["packet_project"] == "" { + if args["project"] == "" { t.Skip("Packet project UUID missing") } @@ -73,17 +73,17 @@ func TestAddrsPublicV6(t *testing.T) { func TestAddrsPublicV4(t *testing.T) { args := discover.Config{ - "provider": "packet", - "packet_auth_token": os.Getenv("PACKET_TOKEN"), - "packet_project": os.Getenv("PACKET_PROJECT"), - "address_type": "public_v4", + "provider": "packet", + "auth_token": os.Getenv("PACKET_TOKEN"), + "project": os.Getenv("PACKET_PROJECT"), + "address_type": "public_v4", } - if args["packet_auth_token"] == "" { + if args["auth_token"] == "" { t.Skip("Packet credentials missing") } - if args["packet_project"] == "" { + if args["project"] == "" { t.Skip("Packet project UUID missing") }