mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-07-24 02:26:00 +00:00
Add support for using source_disk to google_compute_image (#9614)
This commit is contained in:
parent
81d40f0a69
commit
6eeea9e4c7
|
@ -16,6 +16,8 @@ func resourceComputeImage() *schema.Resource {
|
||||||
Delete: resourceComputeImageDelete,
|
Delete: resourceComputeImageDelete,
|
||||||
|
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
|
// TODO(cblecker): one of source_disk or raw_disk is required
|
||||||
|
|
||||||
"name": &schema.Schema{
|
"name": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
|
@ -39,9 +41,15 @@ func resourceComputeImage() *schema.Resource {
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"source_disk": &schema.Schema{
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Optional: true,
|
||||||
|
ForceNew: true,
|
||||||
|
},
|
||||||
|
|
||||||
"raw_disk": &schema.Schema{
|
"raw_disk": &schema.Schema{
|
||||||
Type: schema.TypeList,
|
Type: schema.TypeList,
|
||||||
Required: true,
|
Optional: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
MaxItems: 1,
|
MaxItems: 1,
|
||||||
Elem: &schema.Resource{
|
Elem: &schema.Resource{
|
||||||
|
@ -95,15 +103,24 @@ func resourceComputeImageCreate(d *schema.ResourceData, meta interface{}) error
|
||||||
image.Family = v.(string)
|
image.Family = v.(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
rawDiskEle := d.Get("raw_disk").([]interface{})[0].(map[string]interface{})
|
// Load up the source_disk for this image if specified
|
||||||
imageRawDisk := &compute.ImageRawDisk{
|
if v, ok := d.GetOk("source_disk"); ok {
|
||||||
Source: rawDiskEle["source"].(string),
|
image.SourceDisk = v.(string)
|
||||||
ContainerType: rawDiskEle["container_type"].(string),
|
|
||||||
}
|
}
|
||||||
if val, ok := rawDiskEle["sha1"]; ok {
|
|
||||||
imageRawDisk.Sha1Checksum = val.(string)
|
// Load up the raw_disk for this image if specified
|
||||||
|
if v, ok := d.GetOk("raw_disk"); ok {
|
||||||
|
rawDiskEle := v.([]interface{})[0].(map[string]interface{})
|
||||||
|
imageRawDisk := &compute.ImageRawDisk{
|
||||||
|
Source: rawDiskEle["source"].(string),
|
||||||
|
ContainerType: rawDiskEle["container_type"].(string),
|
||||||
|
}
|
||||||
|
if val, ok := rawDiskEle["sha1"]; ok {
|
||||||
|
imageRawDisk.Sha1Checksum = val.(string)
|
||||||
|
}
|
||||||
|
|
||||||
|
image.RawDisk = imageRawDisk
|
||||||
}
|
}
|
||||||
image.RawDisk = imageRawDisk
|
|
||||||
|
|
||||||
// Insert the image
|
// Insert the image
|
||||||
op, err := config.clientCompute.Images.Insert(
|
op, err := config.clientCompute.Images.Insert(
|
||||||
|
|
|
@ -29,6 +29,25 @@ func TestAccComputeImage_basic(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccComputeImage_basedondisk(t *testing.T) {
|
||||||
|
var image compute.Image
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testAccCheckComputeImageDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccComputeImage_basedondisk,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testAccCheckComputeImageExists(
|
||||||
|
"google_compute_image.foobar", &image),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func testAccCheckComputeImageDestroy(s *terraform.State) error {
|
func testAccCheckComputeImageDestroy(s *terraform.State) error {
|
||||||
config := testAccProvider.Meta().(*Config)
|
config := testAccProvider.Meta().(*Config)
|
||||||
|
|
||||||
|
@ -83,3 +102,14 @@ resource "google_compute_image" "foobar" {
|
||||||
source = "https://storage.googleapis.com/bosh-cpi-artifacts/bosh-stemcell-3262.4-google-kvm-ubuntu-trusty-go_agent-raw.tar.gz"
|
source = "https://storage.googleapis.com/bosh-cpi-artifacts/bosh-stemcell-3262.4-google-kvm-ubuntu-trusty-go_agent-raw.tar.gz"
|
||||||
}
|
}
|
||||||
}`, acctest.RandString(10))
|
}`, acctest.RandString(10))
|
||||||
|
|
||||||
|
var testAccComputeImage_basedondisk = fmt.Sprintf(`
|
||||||
|
resource "google_compute_disk" "foobar" {
|
||||||
|
name = "disk-test-%s"
|
||||||
|
zone = "us-central1-a"
|
||||||
|
image = "debian-8-jessie-v20160803"
|
||||||
|
}
|
||||||
|
resource "google_compute_image" "foobar" {
|
||||||
|
name = "image-test-%s"
|
||||||
|
source_disk = "${google_compute_disk.foobar.self_link}"
|
||||||
|
}`, acctest.RandString(10), acctest.RandString(10))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user