Skip to content

Commit

Permalink
🐛 fix conflicting id for aws ec2 instances
Browse files Browse the repository at this point in the history
  • Loading branch information
vjeffrey committed Mar 5, 2024
1 parent cead7e2 commit 72d9e75
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
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

0 comments on commit 72d9e75

Please sign in to comment.