diff --git a/command/agent/config.go b/command/agent/config.go index d40a181b0..5f0bfdf78 100644 --- a/command/agent/config.go +++ b/command/agent/config.go @@ -358,6 +358,14 @@ func (a *Config) Merge(b *Config) *Config { result.AdvertiseAddrs = result.AdvertiseAddrs.Merge(b.AdvertiseAddrs) } + // Apply the Atlas configuration + if result.Atlas == nil && b.Atlas != nil { + atlasConfig := *b.Atlas + result.Atlas = &atlasConfig + } else if b.Atlas != nil { + result.Atlas = result.Atlas.Merge(b.Atlas) + } + return &result } @@ -499,6 +507,25 @@ func (a *AdvertiseAddrs) Merge(b *AdvertiseAddrs) *AdvertiseAddrs { return &result } +// Merge merges two Atlas configurations together. +func (a *AtlasConfig) Merge(b *AtlasConfig) *AtlasConfig { + var result AtlasConfig = *a + + if b.Infrastructure != "" { + result.Infrastructure = b.Infrastructure + } + if b.Token != "" { + result.Token = b.Token + } + if b.Join { + result.Join = true + } + if b.Endpoint != "" { + result.Endpoint = b.Endpoint + } + return &result +} + // LoadConfig loads the configuration at the given path, regardless if // its a file or directory. func LoadConfig(path string) (*Config, error) { diff --git a/command/agent/config_test.go b/command/agent/config_test.go index c3402274c..c13ff91f3 100644 --- a/command/agent/config_test.go +++ b/command/agent/config_test.go @@ -63,6 +63,12 @@ func TestConfig_Merge(t *testing.T) { RPC: "127.0.0.1", Serf: "127.0.0.1", }, + Atlas: &AtlasConfig{ + Infrastructure: "hashicorp/test1", + Token: "abc", + Join: false, + Endpoint: "foo", + }, } c2 := &Config{ @@ -123,6 +129,12 @@ func TestConfig_Merge(t *testing.T) { RPC: "127.0.0.2", Serf: "127.0.0.2", }, + Atlas: &AtlasConfig{ + Infrastructure: "hashicorp/test2", + Token: "xyz", + Join: true, + Endpoint: "bar", + }, } result := c1.Merge(c2)