Skip to content

Commit

Permalink
Error instead of panicking if self link isn't long enough
Browse files Browse the repository at this point in the history
  • Loading branch information
rileykarson committed Nov 13, 2019
1 parent 50769bc commit 93923e0
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions third_party/terraform/utils/self_link_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ func GetLocationalResourcePropertiesFromSelfLinkString(selfLink string) (string,
}

s := strings.Split(parsed.Path, "/")

// This is a pretty bad way to tell if this is a self link, but stops us
// from accessing an index out of bounds and causing a panic. generally, we
// expect bad values to be partial URIs and names, so this will catch them
if len(s) < 9 {
return "", "", "", fmt.Errorf("value %s was not a self link", selfLink)
}

return s[4], s[6], s[8], nil
}

Expand Down

0 comments on commit 93923e0

Please sign in to comment.