Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for min_cpu_platform in google_compute_instance. #349

Merged
merged 3 commits into from
Aug 30, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions google/resource_compute_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ var InstanceVersionedFeatures = []Feature{
Version: v0beta,
Item: "guest_accelerator",
},
{
Version: v0beta,
Item: "min_cpu_platform",
},
}

func stringScopeHashcode(v interface{}) int {
Expand Down Expand Up @@ -465,6 +469,12 @@ func resourceComputeInstance() *schema.Resource {
},
},

"min_cpu_platform": &schema.Schema{
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},

"tags": &schema.Schema{
Type: schema.TypeSet,
Optional: true,
Expand Down Expand Up @@ -858,6 +868,7 @@ func resourceComputeInstanceCreate(d *schema.ResourceData, meta interface{}) err
Labels: expandLabels(d),
ServiceAccounts: serviceAccounts,
GuestAccelerators: expandGuestAccelerators(zone.Name, d.Get("guest_accelerator").([]interface{})),
MinCpuPlatform: d.Get("min_cpu_platform").(string),
Scheduling: scheduling,
}

Expand Down Expand Up @@ -1122,6 +1133,7 @@ func resourceComputeInstanceRead(d *schema.ResourceData, meta interface{}) error
d.Set("scratch_disk", scratchDisks)
d.Set("scheduling", flattenBetaScheduling(instance.Scheduling))
d.Set("guest_accelerator", flattenGuestAccelerators(instance.Zone, instance.GuestAccelerators))
d.Set("min_cpu_platform", instance.MinCpuPlatform)
d.Set("self_link", ConvertSelfLinkToV1(instance.SelfLink))
d.SetId(instance.Name)

Expand Down
52 changes: 52 additions & 0 deletions google/resource_compute_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,27 @@ func TestAccComputeInstance_guestAccelerator(t *testing.T) {

}

func TestAccComputeInstance_minCpuPlatform(t *testing.T) {
var instance computeBeta.Instance
instanceName := fmt.Sprintf("terraform-test-%s", acctest.RandString(10))

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeInstanceDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeInstance_minCpuPlatform(instanceName),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeBetaInstanceExists("google_compute_instance.foobar", &instance),
testAccCheckComputeInstanceHasMinCpuPlatform(&instance, "Intel Haswell"),
),
},
},
})

}

func testAccCheckComputeInstanceUpdateMachineType(n string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down Expand Up @@ -1099,6 +1120,16 @@ func testAccCheckComputeInstanceHasGuestAccelerator(instance *computeBeta.Instan
}
}

func testAccCheckComputeInstanceHasMinCpuPlatform(instance *computeBeta.Instance, minCpuPlatform string) resource.TestCheckFunc {
return func(s *terraform.State) error {
if instance.MinCpuPlatform != minCpuPlatform {
return fmt.Errorf("Wrong minimum CPU platform: expected %s, got %s", minCpuPlatform, instance.MinCpuPlatform)
}

return nil
}
}

func testAccComputeInstance_basic_deprecated_network(instance string) string {
return fmt.Sprintf(`
resource "google_compute_instance" "foobar" {
Expand Down Expand Up @@ -1950,3 +1981,24 @@ resource "google_compute_instance" "foobar" {
}
}`, instance)
}

func testAccComputeInstance_minCpuPlatform(instance string) string {
return fmt.Sprintf(`
resource "google_compute_instance" "foobar" {
name = "%s"
machine_type = "n1-standard-1"
zone = "us-east1-d"

boot_disk {
initialize_params {
image = "debian-8-jessie-v20160803"
}
}

network_interface {
network = "default"
}

min_cpu_platform = "Intel Haswell"
}`, instance)
}
3 changes: 3 additions & 0 deletions website/docs/r/compute_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,9 @@ The `scheduling` block supports:

* `guest_accelerator` - (Optional, [Beta](/docs/providers/google/index.html#beta-features)) List of the type and count of accelerator cards attached to the instance. Structure documented below.

* `min_cpu_platform` - (Optional, [Beta](/docs/providers/google/index.html#beta-features)) Specifies a minimum CPU platform for the VM instance. Applicable values are the friendly names of CPU platforms, such as
`Intel Haswell` or `Intel Skylake`. See the complete list [here](https://cloud.google.com/compute/docs/instances/specify-min-cpu-platform).

The `guest_accelerator` block supports:

* `type` (Required) - The accelerator type resource to expose to this instance. E.g. `nvidia-tesla-k80`.
Expand Down