Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 fix conflicting id for aws ec2 instances #3500

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions providers/aws/connection/awsec2ebsconn/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,16 +322,16 @@ func NewInstanceId(account string, region string, id string) (*awsec2ebstypes.In

func ParseInstanceId(path string) (*awsec2ebstypes.InstanceId, error) {
if !IsValidInstanceId(path) {
return nil, errors.New("invalid instance id. expected account/<id>/region/<region-val>/instance/<instance-id>")
return nil, errors.New("invalid instance id. expected account/<id>/region/<region-val>/instances/<instance-id>")
}
keyValues := strings.Split(path, "/")
if len(keyValues) != 6 {
return nil, errors.New("invalid instance id. expected account/<id>/region/<region-val>/instance/<instance-id>")
return nil, errors.New("invalid instance id. expected account/<id>/region/<region-val>/instances/<instance-id>")
}
return NewInstanceId(keyValues[1], keyValues[3], keyValues[5])
}

var VALID_INSTANCE_ID = regexp.MustCompile(`^account/\d{12}/region\/(us(-gov)?|ap|ca|cn|eu|sa)-(central|(north|south)?(east|west)?)-\d\/instance\/.+$`)
var VALID_INSTANCE_ID = regexp.MustCompile(`^account/\d{12}/region\/(us(-gov)?|ap|ca|cn|eu|sa)-(central|(north|south)?(east|west)?)-\d\/instances\/.+$`)

func IsValidInstanceId(path string) bool {
return VALID_INSTANCE_ID.MatchString(path)
Expand Down
4 changes: 2 additions & 2 deletions providers/aws/connection/awsec2ebsconn/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ type VolumeInfo struct {
}

func (s *InstanceId) String() string {
// e.g. account/999000999000/region/us-east-2/instance/i-0989478343232
return path.Join("account", s.Account, "region", s.Region, "instance", s.Id)
// e.g. account/999000999000/region/us-east-2/instances/i-0989478343232
return path.Join("account", s.Account, "region", s.Region, "instances", s.Id)
}
2 changes: 1 addition & 1 deletion providers/aws/connection/awsec2ebsconn/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

func TestParseInstanceId(t *testing.T) {
path := "account/185972265011/region/us-east-1/instance/i-07f67838ada5879af"
path := "account/185972265011/region/us-east-1/instances/i-07f67838ada5879af"
id, err := ParseInstanceId(path)
require.NoError(t, err)
assert.Equal(t, id.Account, "185972265011")
Expand Down
Loading