Skip to content

Commit

Permalink
Error instead of panicking if self link isn't long enough (#2672)
Browse files Browse the repository at this point in the history
Merged PR #2672.
  • Loading branch information
rileykarson authored and modular-magician committed Nov 18, 2019
1 parent 8ef590c commit 39d92c7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build/terraform
2 changes: 1 addition & 1 deletion build/terraform-beta
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 39d92c7

Please sign in to comment.