Skip to content

Commit

Permalink
Add support for min_cpu_platform in google_compute_instance. (hashic…
Browse files Browse the repository at this point in the history
  • Loading branch information
rosbo authored Aug 30, 2017
1 parent e1ff044 commit f86ffc0
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
18 changes: 18 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,17 @@ func resourceComputeInstance() *schema.Resource {
},
},

"cpu_platform": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},

"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 +873,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 +1138,8 @@ 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("cpu_platform", instance.CpuPlatform)
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)
}
5 changes: 5 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 All @@ -283,6 +286,8 @@ exported:

* `label_fingerprint` - The unique fingerprint of the labels.

* `cpu_platform` - The CPU platform used by this instance.

* `network_interface.0.address` - The internal ip address of the instance, either manually or dynamically assigned.

* `network_interface.0.access_config.0.assigned_nat_ip` - If the instance has an access config, either the given external ip (in the `nat_ip` field) or the ephemeral (generated) ip (if you didn't provide one).
Expand Down

0 comments on commit f86ffc0

Please sign in to comment.