mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-07-09 03:28:29 +00:00
Search configured project image families (#9243)
* Search configured project image families * Clarify documentation around google_compute_instance image families * Acceptance test for private instance family creation
This commit is contained in:
parent
784b9f5247
commit
99b165ab54
8
image.go
8
image.go
|
@ -21,12 +21,18 @@ func resolveImage(c *Config, name string) (string, error) {
|
||||||
|
|
||||||
// Must infer the project name:
|
// Must infer the project name:
|
||||||
|
|
||||||
// First, try the configured project.
|
// First, try the configured project for a specific image:
|
||||||
image, err := c.clientCompute.Images.Get(c.Project, name).Do()
|
image, err := c.clientCompute.Images.Get(c.Project, name).Do()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return image.SelfLink, nil
|
return image.SelfLink, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If it doesn't exist, try to see if it works as an image family:
|
||||||
|
image, err = c.clientCompute.Images.GetFromFamily(c.Project, name).Do()
|
||||||
|
if err == nil {
|
||||||
|
return image.SelfLink, nil
|
||||||
|
}
|
||||||
|
|
||||||
// If we match a lookup for an alternate project, then try that next.
|
// If we match a lookup for an alternate project, then try that next.
|
||||||
// If not, we return the original error.
|
// If not, we return the original error.
|
||||||
|
|
||||||
|
|
|
@ -458,6 +458,30 @@ func TestAccComputeInstance_address_custom(t *testing.T) {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccComputeInstance_private_image_family(t *testing.T) {
|
||||||
|
var instance compute.Instance
|
||||||
|
var instanceName = fmt.Sprintf("instance-test-%s", acctest.RandString(10))
|
||||||
|
var diskName = fmt.Sprintf("instance-testd-%s", acctest.RandString(10))
|
||||||
|
var imageName = fmt.Sprintf("instance-testi-%s", acctest.RandString(10))
|
||||||
|
var familyName = fmt.Sprintf("instance-testf-%s", acctest.RandString(10))
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testAccCheckComputeInstanceDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccComputeInstance_private_image_family(diskName, imageName, familyName, instanceName),
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testAccCheckComputeInstanceExists(
|
||||||
|
"google_compute_instance.foobar", &instance),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func testAccCheckComputeInstanceDestroy(s *terraform.State) error {
|
func testAccCheckComputeInstanceDestroy(s *terraform.State) error {
|
||||||
config := testAccProvider.Meta().(*Config)
|
config := testAccProvider.Meta().(*Config)
|
||||||
|
|
||||||
|
@ -1095,3 +1119,36 @@ func testAccComputeInstance_address_custom(instance, address string) string {
|
||||||
|
|
||||||
}`, acctest.RandString(10), acctest.RandString(10), instance, address)
|
}`, acctest.RandString(10), acctest.RandString(10), instance, address)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testAccComputeInstance_private_image_family(disk, image, family, instance string) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
resource "google_compute_disk" "foobar" {
|
||||||
|
name = "%s"
|
||||||
|
zone = "us-central1-a"
|
||||||
|
image = "debian-8-jessie-v20160803"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "google_compute_image" "foobar" {
|
||||||
|
name = "%s"
|
||||||
|
source_disk = "${google_compute_disk.foobar.self_link}"
|
||||||
|
family = "%s"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "google_compute_instance" "foobar" {
|
||||||
|
name = "%s"
|
||||||
|
machine_type = "n1-standard-1"
|
||||||
|
zone = "us-central1-a"
|
||||||
|
|
||||||
|
disk {
|
||||||
|
image = "${google_compute_image.foobar.family}"
|
||||||
|
}
|
||||||
|
|
||||||
|
network_interface {
|
||||||
|
network = "default"
|
||||||
|
}
|
||||||
|
|
||||||
|
metadata {
|
||||||
|
foo = "bar"
|
||||||
|
}
|
||||||
|
}`, disk, image, family, instance)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user