Skip to content

Commit

Permalink
Support GET-only HTTP servers for image sources (#472)
Browse files Browse the repository at this point in the history
Some HTTP services, notably GitHub Releases, do not support HEAD requests to their endpoints.

terraform-provider-libvirt will thus fail on something along the lines of:

resource "libvirt_volume" "centos7_volume" {
  name = "centos7"
  source = "https://github.com/moio/sumaform-images/releases/download/4.0.0/centos7.qcow2"
}

With:

libvirt_volume.centos7_volume: Error accessing remote resource: https://github.com/moio/sumaform-images/releases/download/4.0.0/centos7.qcow2 - 403 Forbidden


This removes the assumption a HEAD request will succeed. If it doesn't, it will try a Body-less GET instead.
  • Loading branch information
moio authored Nov 9, 2018
1 parent afd5c1a commit 8597016
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions libvirt/utils_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ func (i *httpImage) Size() (uint64, error) {
if err != nil {
return 0, err
}
if response.StatusCode == 403 {
// possibly only the HEAD method is forbidden, try a Body-less GET instead
response, err = http.Get(i.url.String())
if err != nil {
return 0, err
}

response.Body.Close()
}
if response.StatusCode != 200 {
return 0,
fmt.Errorf(
Expand Down

0 comments on commit 8597016

Please sign in to comment.