diff --git a/datasource/metadata/ec2/metadata.go b/datasource/metadata/ec2/metadata.go index 039c994..85e973e 100644 --- a/datasource/metadata/ec2/metadata.go +++ b/datasource/metadata/ec2/metadata.go @@ -69,7 +69,7 @@ func (ms metadataService) FetchMetadata() ([]byte, error) { } if hostname, err := ms.fetchAttribute(fmt.Sprintf("%s/hostname", ms.MetadataUrl())); err == nil { - attrs["hostname"] = hostname + attrs["hostname"] = strings.Split(hostname, " ")[0] } else if _, ok := err.(pkg.ErrNotFound); !ok { return nil, err } diff --git a/datasource/metadata/ec2/metadata_test.go b/datasource/metadata/ec2/metadata_test.go index a2a30c3..5f4a538 100644 --- a/datasource/metadata/ec2/metadata_test.go +++ b/datasource/metadata/ec2/metadata_test.go @@ -173,6 +173,20 @@ func TestFetchMetadata(t *testing.T) { }, expect: []byte(`{"hostname":"host","local-ipv4":"1.2.3.4","network_config":{"content_path":"path"},"public-ipv4":"5.6.7.8","public_keys":{"test1":"key"}}`), }, + { + root: "/", + metadataPath: "2009-04-04/meta-data", + resources: map[string]string{ + "/2009-04-04/meta-data/hostname": "host domain another_domain", + "/2009-04-04/meta-data/local-ipv4": "1.2.3.4", + "/2009-04-04/meta-data/public-ipv4": "5.6.7.8", + "/2009-04-04/meta-data/public-keys": "0=test1\n", + "/2009-04-04/meta-data/public-keys/0": "openssh-key", + "/2009-04-04/meta-data/public-keys/0/openssh-key": "key", + "/2009-04-04/meta-data/network_config/content_path": "path", + }, + expect: []byte(`{"hostname":"host","local-ipv4":"1.2.3.4","network_config":{"content_path":"path"},"public-ipv4":"5.6.7.8","public_keys":{"test1":"key"}}`), + }, { clientErr: pkg.ErrTimeout{Err: fmt.Errorf("test error")}, expectErr: pkg.ErrTimeout{Err: fmt.Errorf("test error")},