github.com/adamar/terraform@v0.2.2-0.20141016210445-2e703afdad0e/builtin/providers/google/image.go (about) 1 package google 2 3 import ( 4 "strings" 5 6 "code.google.com/p/google-api-go-client/compute/v1" 7 ) 8 9 // readImage finds the image with the given name. 10 func readImage(c *Config, name string) (*compute.Image, error) { 11 // First, always try ourselves first. 12 image, err := c.clientCompute.Images.Get(c.Project, name).Do() 13 if err == nil && image != nil && image.SelfLink != "" { 14 return image, nil 15 } 16 17 // This is a map of names to the project name where a public image is 18 // hosted. GCE doesn't have an API to simply look up an image without 19 // a project so we do this jank thing. 20 imageMap := map[string]string{ 21 "centos": "centos-cloud", 22 "coreos": "coreos-cloud", 23 "debian": "debian-cloud", 24 "opensuse": "opensuse-cloud", 25 "rhel": "rhel-cloud", 26 "sles": "suse-cloud", 27 } 28 29 // If we match a lookup for an alternate project, then try that next. 30 // If not, we return the error. 31 var project string 32 for k, v := range imageMap { 33 if strings.Contains(name, k) { 34 project = v 35 break 36 } 37 } 38 if project == "" { 39 return nil, err 40 } 41 42 return c.clientCompute.Images.Get(project, name).Do() 43 }