Add support for using source_disk to google_compute_image (#9614)
This commit is contained in:
parent
71536155e0
commit
ca8cd4b1f0
|
@ -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))
|
||||||
|
|
|
@ -40,14 +40,18 @@ resource "google_compute_instance" "vm" {
|
||||||
|
|
||||||
## Argument Reference
|
## Argument Reference
|
||||||
|
|
||||||
The following arguments are supported:
|
The following arguments are supported: (Note that one of either source_disk or
|
||||||
|
raw_disk is required)
|
||||||
|
|
||||||
* `name` - (Required) A unique name for the resource, required by GCE.
|
* `name` - (Required) A unique name for the resource, required by GCE.
|
||||||
Changing this forces a new resource to be created.
|
Changing this forces a new resource to be created.
|
||||||
|
|
||||||
* `raw_disk` - (Required) The raw disk that will be used as the source of
|
* `source_disk` - The URL of a disk that will be used as the source of the
|
||||||
the image. Changing this forces a new resource to be created.
|
image. Changing this forces a new resource to be created.
|
||||||
Structure is documented below.
|
|
||||||
|
* `raw_disk` - The raw disk that will be used as the source of the image.
|
||||||
|
Changing this forces a new resource to be created. Structure is documented
|
||||||
|
below.
|
||||||
|
|
||||||
The `raw_disk` block supports:
|
The `raw_disk` block supports:
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue