mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-10-06 10:41:07 +00:00
Merge pull request #1717 from Mierdin/master
Implement 'licenses' field in compute_image resource
This commit is contained in:
commit
3d2e72208e
@ -106,6 +106,13 @@ func resourceComputeImage() *schema.Resource {
|
|||||||
Set: schema.HashString,
|
Set: schema.HashString,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"licenses": &schema.Schema{
|
||||||
|
Type: schema.TypeList,
|
||||||
|
Optional: true,
|
||||||
|
ForceNew: true,
|
||||||
|
Elem: &schema.Schema{Type: schema.TypeString},
|
||||||
|
},
|
||||||
|
|
||||||
"label_fingerprint": &schema.Schema{
|
"label_fingerprint": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Computed: true,
|
Computed: true,
|
||||||
@ -158,6 +165,11 @@ func resourceComputeImageCreate(d *schema.ResourceData, meta interface{}) error
|
|||||||
image.Labels = expandLabels(d)
|
image.Labels = expandLabels(d)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load up the licenses for this image if specified
|
||||||
|
if _, ok := d.GetOk("licenses"); ok {
|
||||||
|
image.Licenses = licenses(d)
|
||||||
|
}
|
||||||
|
|
||||||
// Read create timeout
|
// Read create timeout
|
||||||
var createTimeout int
|
var createTimeout int
|
||||||
if v, ok := d.GetOk("create_timeout"); ok {
|
if v, ok := d.GetOk("create_timeout"); ok {
|
||||||
@ -213,6 +225,7 @@ func resourceComputeImageRead(d *schema.ResourceData, meta interface{}) error {
|
|||||||
d.Set("family", image.Family)
|
d.Set("family", image.Family)
|
||||||
d.Set("self_link", image.SelfLink)
|
d.Set("self_link", image.SelfLink)
|
||||||
d.Set("labels", image.Labels)
|
d.Set("labels", image.Labels)
|
||||||
|
d.Set("licenses", image.Licenses)
|
||||||
d.Set("label_fingerprint", image.LabelFingerprint)
|
d.Set("label_fingerprint", image.LabelFingerprint)
|
||||||
d.Set("project", project)
|
d.Set("project", project)
|
||||||
|
|
||||||
@ -287,3 +300,12 @@ func resourceComputeImageDelete(d *schema.ResourceData, meta interface{}) error
|
|||||||
d.SetId("")
|
d.SetId("")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func licenses(d *schema.ResourceData) []string {
|
||||||
|
licensesCount := d.Get("licenses.#").(int)
|
||||||
|
data := make([]string, licensesCount)
|
||||||
|
for i := 0; i < licensesCount; i++ {
|
||||||
|
data[i] = d.Get(fmt.Sprintf("licenses.%d", i)).(string)
|
||||||
|
}
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
@ -36,6 +36,33 @@ func TestAccComputeImage_basic(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccComputeImage_withLicense(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
var image compute.Image
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testAccCheckComputeImageDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccComputeImage_license("image-test-" + acctest.RandString(10)),
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testAccCheckComputeImageExists(
|
||||||
|
"google_compute_image.foobar", &image),
|
||||||
|
testAccCheckComputeImageDescription(&image, "description-test"),
|
||||||
|
testAccCheckComputeImageFamily(&image, "family-test"),
|
||||||
|
testAccCheckComputeImageContainsLabel(&image, "my-label", "my-label-value"),
|
||||||
|
testAccCheckComputeImageContainsLabel(&image, "empty-label", ""),
|
||||||
|
testAccCheckComputeImageContainsLicense(&image, "https://www.googleapis.com/compute/v1/projects/vm-options/global/licenses/enable-vmx"),
|
||||||
|
testAccCheckComputeImageHasComputedFingerprint(&image, "google_compute_image.foobar"),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestAccComputeImage_update(t *testing.T) {
|
func TestAccComputeImage_update(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
@ -184,6 +211,19 @@ func testAccCheckComputeImageContainsLabel(image *compute.Image, key string, val
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testAccCheckComputeImageContainsLicense(image *compute.Image, expectedLicense string) resource.TestCheckFunc {
|
||||||
|
return func(s *terraform.State) error {
|
||||||
|
|
||||||
|
for _, thisLicense := range image.Licenses {
|
||||||
|
if thisLicense == expectedLicense {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Errorf("Expected license '%s' was not found", expectedLicense)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func testAccCheckComputeImageDoesNotContainLabel(image *compute.Image, key string) resource.TestCheckFunc {
|
func testAccCheckComputeImageDoesNotContainLabel(image *compute.Image, key string) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
if v, ok := image.Labels[key]; ok {
|
if v, ok := image.Labels[key]; ok {
|
||||||
@ -242,6 +282,26 @@ resource "google_compute_image" "foobar" {
|
|||||||
}`, name)
|
}`, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testAccComputeImage_license(name string) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
resource "google_compute_image" "foobar" {
|
||||||
|
name = "%s"
|
||||||
|
description = "description-test"
|
||||||
|
family = "family-test"
|
||||||
|
raw_disk {
|
||||||
|
source = "https://storage.googleapis.com/bosh-cpi-artifacts/bosh-stemcell-3262.4-google-kvm-ubuntu-trusty-go_agent-raw.tar.gz"
|
||||||
|
}
|
||||||
|
create_timeout = 5
|
||||||
|
labels = {
|
||||||
|
my-label = "my-label-value"
|
||||||
|
empty-label = ""
|
||||||
|
}
|
||||||
|
licenses = [
|
||||||
|
"https://www.googleapis.com/compute/v1/projects/vm-options/global/licenses/enable-vmx",
|
||||||
|
]
|
||||||
|
}`, name)
|
||||||
|
}
|
||||||
|
|
||||||
func testAccComputeImage_update(name string) string {
|
func testAccComputeImage_update(name string) string {
|
||||||
return fmt.Sprintf(`
|
return fmt.Sprintf(`
|
||||||
resource "google_compute_image" "foobar" {
|
resource "google_compute_image" "foobar" {
|
||||||
|
@ -22,6 +22,10 @@ resource "google_compute_image" "bootable-image" {
|
|||||||
raw_disk {
|
raw_disk {
|
||||||
source = "https://storage.googleapis.com/my-bucket/my-disk-image-tarball.tar.gz"
|
source = "https://storage.googleapis.com/my-bucket/my-disk-image-tarball.tar.gz"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
licenses = [
|
||||||
|
"https://www.googleapis.com/compute/v1/projects/vm-options/global/licenses/enable-vmx",
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "google_compute_instance" "vm" {
|
resource "google_compute_instance" "vm" {
|
||||||
@ -67,6 +71,9 @@ The following arguments are supported: (Note that one of either source_disk or
|
|||||||
Changing this forces a new resource to be created. Structure is documented
|
Changing this forces a new resource to be created. Structure is documented
|
||||||
below.
|
below.
|
||||||
|
|
||||||
|
* `licenses` - (Optional) A list of license URIs to apply to this image. Changing this
|
||||||
|
forces a new resource to be created.
|
||||||
|
|
||||||
* `create_timeout` - (Deprecated) Configurable timeout in minutes for creating images. Default is 4 minutes.
|
* `create_timeout` - (Deprecated) Configurable timeout in minutes for creating images. Default is 4 minutes.
|
||||||
|
|
||||||
The `raw_disk` block supports:
|
The `raw_disk` block supports:
|
||||||
|
Loading…
Reference in New Issue
Block a user