Skip to content

Commit d5596b4

Browse files
modular-magicianmelinathrileykarson
authored
Support vNic type and Reservation affitinity (#4981) (#3554)
Co-authored-by: Stephen Lewis (Burrows) <[email protected]> Co-authored-by: Riley Karson <[email protected]> Signed-off-by: Modular Magician <[email protected]> Co-authored-by: Stephen Lewis (Burrows) <[email protected]> Co-authored-by: Riley Karson <[email protected]>
1 parent a058be0 commit d5596b4

File tree

5 files changed

+181
-1
lines changed

5 files changed

+181
-1
lines changed

.changelog/4981.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
`notebooks`: added support for `nic_type`, `reservation_affinity` to `google_notebooks_instance`
3+
```

google-beta/resource_gke_hub_feature_membership_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"fmt"
66
"testing"
77

8-
dcl "github.com/GoogleCloudPlatform/declarative-resource-client-library/dcl"
8+
"github.com/GoogleCloudPlatform/declarative-resource-client-library/dcl"
99
gkehub "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/gkehub/beta"
1010
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1111
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"

google-beta/resource_notebooks_instance.go

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,13 @@ An object containing a list of "key": value pairs. Example: { "name": "wrench",
233233
Description: `The name of the VPC that this instance is in.
234234
Format: projects/{project_id}/global/networks/{network_id}`,
235235
},
236+
"nic_type": {
237+
Type: schema.TypeString,
238+
Optional: true,
239+
ForceNew: true,
240+
ValidateFunc: validation.StringInSlice([]string{"UNSPECIFIED_NIC_TYPE", "VIRTIO_NET", "GVNIC", ""}, false),
241+
Description: `The type of vNIC driver. Possible values: ["UNSPECIFIED_NIC_TYPE", "VIRTIO_NET", "GVNIC"]`,
242+
},
236243
"no_proxy_access": {
237244
Type: schema.TypeBool,
238245
Optional: true,
@@ -259,6 +266,39 @@ Format: projects/{project_id}/global/networks/{network_id}`,
259266
notebook instance fully boots up. The path must be a URL
260267
or Cloud Storage path (gs://path-to-file/file-name).`,
261268
},
269+
"reservation_affinity": {
270+
Type: schema.TypeList,
271+
Optional: true,
272+
ForceNew: true,
273+
Description: `Reservation Affinity for consuming Zonal reservation.`,
274+
MaxItems: 1,
275+
Elem: &schema.Resource{
276+
Schema: map[string]*schema.Schema{
277+
"consume_reservation_type": {
278+
Type: schema.TypeString,
279+
Required: true,
280+
ForceNew: true,
281+
ValidateFunc: validation.StringInSlice([]string{"NO_RESERVATION", "ANY_RESERVATION", "SPECIFIC_RESERVATION"}, false),
282+
Description: `The type of Compute Reservation. Possible values: ["NO_RESERVATION", "ANY_RESERVATION", "SPECIFIC_RESERVATION"]`,
283+
},
284+
"key": {
285+
Type: schema.TypeString,
286+
Optional: true,
287+
ForceNew: true,
288+
Description: `Corresponds to the label key of reservation resource.`,
289+
},
290+
"values": {
291+
Type: schema.TypeList,
292+
Optional: true,
293+
ForceNew: true,
294+
Description: `Corresponds to the label values of reservation resource.`,
295+
Elem: &schema.Schema{
296+
Type: schema.TypeString,
297+
},
298+
},
299+
},
300+
},
301+
},
262302
"service_account": {
263303
Type: schema.TypeString,
264304
Computed: true,
@@ -454,6 +494,18 @@ func resourceNotebooksInstanceCreate(d *schema.ResourceData, meta interface{}) e
454494
} else if v, ok := d.GetOkExists("shielded_instance_config"); !isEmptyValue(reflect.ValueOf(shieldedInstanceConfigProp)) && (ok || !reflect.DeepEqual(v, shieldedInstanceConfigProp)) {
455495
obj["shieldedInstanceConfig"] = shieldedInstanceConfigProp
456496
}
497+
nicTypeProp, err := expandNotebooksInstanceNicType(d.Get("nic_type"), d, config)
498+
if err != nil {
499+
return err
500+
} else if v, ok := d.GetOkExists("nic_type"); !isEmptyValue(reflect.ValueOf(nicTypeProp)) && (ok || !reflect.DeepEqual(v, nicTypeProp)) {
501+
obj["nicType"] = nicTypeProp
502+
}
503+
reservationAffinityProp, err := expandNotebooksInstanceReservationAffinity(d.Get("reservation_affinity"), d, config)
504+
if err != nil {
505+
return err
506+
} else if v, ok := d.GetOkExists("reservation_affinity"); !isEmptyValue(reflect.ValueOf(reservationAffinityProp)) && (ok || !reflect.DeepEqual(v, reservationAffinityProp)) {
507+
obj["reservationAffinity"] = reservationAffinityProp
508+
}
457509
installGpuDriverProp, err := expandNotebooksInstanceInstallGpuDriver(d.Get("install_gpu_driver"), d, config)
458510
if err != nil {
459511
return err
@@ -673,6 +725,12 @@ func resourceNotebooksInstanceRead(d *schema.ResourceData, meta interface{}) err
673725
if err := d.Set("shielded_instance_config", flattenNotebooksInstanceShieldedInstanceConfig(res["shieldedInstanceConfig"], d, config)); err != nil {
674726
return fmt.Errorf("Error reading Instance: %s", err)
675727
}
728+
if err := d.Set("nic_type", flattenNotebooksInstanceNicType(res["nicType"], d, config)); err != nil {
729+
return fmt.Errorf("Error reading Instance: %s", err)
730+
}
731+
if err := d.Set("reservation_affinity", flattenNotebooksInstanceReservationAffinity(res["reservationAffinity"], d, config)); err != nil {
732+
return fmt.Errorf("Error reading Instance: %s", err)
733+
}
676734
if err := d.Set("state", flattenNotebooksInstanceState(res["state"], d, config)); err != nil {
677735
return fmt.Errorf("Error reading Instance: %s", err)
678736
}
@@ -929,6 +987,39 @@ func flattenNotebooksInstanceShieldedInstanceConfigEnableVtpm(v interface{}, d *
929987
return v
930988
}
931989

990+
func flattenNotebooksInstanceNicType(v interface{}, d *schema.ResourceData, config *Config) interface{} {
991+
return v
992+
}
993+
994+
func flattenNotebooksInstanceReservationAffinity(v interface{}, d *schema.ResourceData, config *Config) interface{} {
995+
if v == nil {
996+
return nil
997+
}
998+
original := v.(map[string]interface{})
999+
if len(original) == 0 {
1000+
return nil
1001+
}
1002+
transformed := make(map[string]interface{})
1003+
transformed["consume_reservation_type"] =
1004+
flattenNotebooksInstanceReservationAffinityConsumeReservationType(original["consumeReservationType"], d, config)
1005+
transformed["key"] =
1006+
flattenNotebooksInstanceReservationAffinityKey(original["key"], d, config)
1007+
transformed["values"] =
1008+
flattenNotebooksInstanceReservationAffinityValues(original["values"], d, config)
1009+
return []interface{}{transformed}
1010+
}
1011+
func flattenNotebooksInstanceReservationAffinityConsumeReservationType(v interface{}, d *schema.ResourceData, config *Config) interface{} {
1012+
return v
1013+
}
1014+
1015+
func flattenNotebooksInstanceReservationAffinityKey(v interface{}, d *schema.ResourceData, config *Config) interface{} {
1016+
return v
1017+
}
1018+
1019+
func flattenNotebooksInstanceReservationAffinityValues(v interface{}, d *schema.ResourceData, config *Config) interface{} {
1020+
return v
1021+
}
1022+
9321023
func flattenNotebooksInstanceState(v interface{}, d *schema.ResourceData, config *Config) interface{} {
9331024
return v
9341025
}
@@ -1084,6 +1175,55 @@ func expandNotebooksInstanceShieldedInstanceConfigEnableVtpm(v interface{}, d Te
10841175
return v, nil
10851176
}
10861177

1178+
func expandNotebooksInstanceNicType(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
1179+
return v, nil
1180+
}
1181+
1182+
func expandNotebooksInstanceReservationAffinity(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
1183+
l := v.([]interface{})
1184+
if len(l) == 0 || l[0] == nil {
1185+
return nil, nil
1186+
}
1187+
raw := l[0]
1188+
original := raw.(map[string]interface{})
1189+
transformed := make(map[string]interface{})
1190+
1191+
transformedConsumeReservationType, err := expandNotebooksInstanceReservationAffinityConsumeReservationType(original["consume_reservation_type"], d, config)
1192+
if err != nil {
1193+
return nil, err
1194+
} else if val := reflect.ValueOf(transformedConsumeReservationType); val.IsValid() && !isEmptyValue(val) {
1195+
transformed["consumeReservationType"] = transformedConsumeReservationType
1196+
}
1197+
1198+
transformedKey, err := expandNotebooksInstanceReservationAffinityKey(original["key"], d, config)
1199+
if err != nil {
1200+
return nil, err
1201+
} else if val := reflect.ValueOf(transformedKey); val.IsValid() && !isEmptyValue(val) {
1202+
transformed["key"] = transformedKey
1203+
}
1204+
1205+
transformedValues, err := expandNotebooksInstanceReservationAffinityValues(original["values"], d, config)
1206+
if err != nil {
1207+
return nil, err
1208+
} else if val := reflect.ValueOf(transformedValues); val.IsValid() && !isEmptyValue(val) {
1209+
transformed["values"] = transformedValues
1210+
}
1211+
1212+
return transformed, nil
1213+
}
1214+
1215+
func expandNotebooksInstanceReservationAffinityConsumeReservationType(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
1216+
return v, nil
1217+
}
1218+
1219+
func expandNotebooksInstanceReservationAffinityKey(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
1220+
return v, nil
1221+
}
1222+
1223+
func expandNotebooksInstanceReservationAffinityValues(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
1224+
return v, nil
1225+
}
1226+
10871227
func expandNotebooksInstanceInstallGpuDriver(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
10881228
return v, nil
10891229
}

google-beta/resource_notebooks_instance_generated_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,12 @@ resource "google_notebooks_instance" "instance" {
208208
metadata = {
209209
terraform = "true"
210210
}
211+
212+
nic_type = "VIRTIO_NET"
213+
214+
reservation_affinity {
215+
consume_reservation_type = "NO_RESERVATION"
216+
}
211217
}
212218
213219
data "google_compute_network" "my_network" {

website/docs/r/notebooks_instance.html.markdown

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ resource "google_notebooks_instance" "instance" {
137137
metadata = {
138138
terraform = "true"
139139
}
140+
141+
nic_type = "VIRTIO_NET"
142+
143+
reservation_affinity {
144+
consume_reservation_type = "NO_RESERVATION"
145+
}
140146
}
141147
142148
data "google_compute_network" "my_network" {
@@ -212,6 +218,16 @@ The following arguments are supported:
212218
Not all combinations are valid
213219
Structure is documented below.
214220

221+
* `nic_type` -
222+
(Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html))
223+
The type of vNIC driver.
224+
Possible values are `UNSPECIFIED_NIC_TYPE`, `VIRTIO_NET`, and `GVNIC`.
225+
226+
* `reservation_affinity` -
227+
(Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html))
228+
Reservation Affinity for consuming Zonal reservation.
229+
Structure is documented below.
230+
215231
* `install_gpu_driver` -
216232
(Optional)
217233
Whether the end user authorizes Google Cloud to install GPU driver
@@ -338,6 +354,21 @@ The `shielded_instance_config` block supports:
338354
Defines whether the instance has the vTPM enabled.
339355
Enabled by default.
340356

357+
The `reservation_affinity` block supports:
358+
359+
* `consume_reservation_type` -
360+
(Required)
361+
The type of Compute Reservation.
362+
Possible values are `NO_RESERVATION`, `ANY_RESERVATION`, and `SPECIFIC_RESERVATION`.
363+
364+
* `key` -
365+
(Optional)
366+
Corresponds to the label key of reservation resource.
367+
368+
* `values` -
369+
(Optional)
370+
Corresponds to the label values of reservation resource.
371+
341372
The `vm_image` block supports:
342373

343374
* `project` -

0 commit comments

Comments
 (0)