diff --git a/command/agent/command.go b/command/agent/command.go index 05caa7a3f7..149fa80847 100644 --- a/command/agent/command.go +++ b/command/agent/command.go @@ -80,6 +80,7 @@ func (c *Command) readConfig() *Config { cmdFlags.StringVar(&cmdConfig.ClientAddr, "client", "", "address to bind client listeners to (DNS, HTTP, HTTPS, RPC)") cmdFlags.StringVar(&cmdConfig.BindAddr, "bind", "", "address to bind server listeners to") cmdFlags.StringVar(&cmdConfig.AdvertiseAddr, "advertise", "", "address to advertise instead of bind addr") + cmdFlags.StringVar(&cmdConfig.AdvertiseAddrWan, "advertise-wan", "", "address to advertise on wan instead of bind or advertise addr") cmdFlags.StringVar(&cmdConfig.AtlasInfrastructure, "atlas", "", "infrastructure name in Atlas") cmdFlags.StringVar(&cmdConfig.AtlasToken, "atlas-token", "", "authentication token for Atlas") diff --git a/command/agent/command_test.go b/command/agent/command_test.go index 58129bba92..b54bd45c5b 100644 --- a/command/agent/command_test.go +++ b/command/agent/command_test.go @@ -106,6 +106,32 @@ func TestRetryJoin(t *testing.T) { }) } +func TestReadCliConfig(t *testing.T) { + + shutdownCh := make(chan struct{}) + defer close(shutdownCh) + + tmpDir, err := ioutil.TempDir("", "consul") + if err != nil { + t.Fatalf("err: %s", err) + } + + cmd := &Command{ + args: []string{ + "-data-dir", tmpDir, + "-node", `"a"`, + "-advertise-wan", "1.2.3.4", + }, + ShutdownCh: shutdownCh, + Ui: new(cli.MockUi), + } + + config := cmd.readConfig() + if config.AdvertiseAddrWan != "1.2.3.4" { + t.Fatalf("expected -advertise-addr-wan 1.2.3.4 got %s", config.AdvertiseAddrWan) + } +} + func TestRetryJoinFail(t *testing.T) { conf := nextConfig() tmpDir, err := ioutil.TempDir("", "consul")