Skip to content

Commit

Permalink
🐛 ensure ec2 instances get a name when scanned (#3589)
Browse files Browse the repository at this point in the history
  • Loading branch information
vjeffrey authored Mar 19, 2024
1 parent 099a3e9 commit 751dab2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion providers/os/id/awsec2/metadata_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (m *CommandInstanceMetadata) Identify() (Identity, error) {
return Identity{}, errors.Wrap(err, "failed to decode EC2 instance identity document")
}

name := ""
name := doc.InstanceID
// Note that the tags metadata service has to be enabled for this to work. If not, we fallback to trying to get the name
// via the aws API (if there's a config provided).
taggedName, err := m.instanceNameTag()
Expand Down
4 changes: 2 additions & 2 deletions providers/os/id/awsec2/metadata_cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestEC2RoleProviderInstanceIdentityUnixNoName(t *testing.T) {
ident, err := metadata.Identify()

assert.Nil(t, err)
assert.Equal(t, "", ident.InstanceName)
assert.Equal(t, "i-1234567890abcdef0", ident.InstanceName)
assert.Equal(t, "//platformid.api.mondoo.app/runtime/aws/ec2/v1/accounts/123456789012/regions/us-west-2/instances/i-1234567890abcdef0", ident.InstanceID)
assert.Equal(t, "//platformid.api.mondoo.app/runtime/aws/accounts/123456789012", ident.AccountID)
}
Expand Down Expand Up @@ -68,7 +68,7 @@ func TestEC2RoleProviderInstanceIdentityWindowsNoName(t *testing.T) {
ident, err := metadata.Identify()

assert.Nil(t, err)
assert.Equal(t, "", ident.InstanceName)
assert.Equal(t, "i-1234567890abcdef0", ident.InstanceName)
assert.Equal(t, "//platformid.api.mondoo.app/runtime/aws/ec2/v1/accounts/123456789012/regions/us-east-1/instances/i-1234567890abcdef0", ident.InstanceID)
assert.Equal(t, "//platformid.api.mondoo.app/runtime/aws/accounts/123456789012", ident.AccountID)
}

0 comments on commit 751dab2

Please sign in to comment.