Skip to content

Commit 7bdc5c6

Browse files
Add missing disk related fields to instance_template resources (#13245) (#22644)
[upstream:42fa1e5ff232404bba2420edc4b46247f78d9330] Signed-off-by: Modular Magician <magic-modules@google.com>
1 parent e8124f3 commit 7bdc5c6

7 files changed

+172
-0
lines changed

.changelog/13245.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
compute: add guest_os_features and architecture to `google_compute_instance_template` and `google_compute_region_instance_template`
3+
```

google/services/compute/resource_compute_instance_template.go

+28
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,14 @@ func ResourceComputeInstanceTemplate() *schema.Resource {
142142
Description: `Name of the disk. When not provided, this defaults to the name of the instance.`,
143143
},
144144

145+
"architecture": {
146+
Type: schema.TypeString,
147+
Optional: true,
148+
ForceNew: true,
149+
Computed: true,
150+
Description: `The architecture of the image. Allowed values are ARM64 or X86_64.`,
151+
},
152+
145153
"disk_size_gb": {
146154
Type: schema.TypeInt,
147155
Optional: true,
@@ -193,6 +201,16 @@ func ResourceComputeInstanceTemplate() *schema.Resource {
193201
Description: `A map of resource manager tags. Resource manager tag keys and values have the same definition as resource manager tags. Keys must be in the format tagKeys/{tag_key_id}, and values are in the format tagValues/456. The field is ignored (both PUT & PATCH) when empty.`,
194202
},
195203

204+
"guest_os_features": {
205+
Type: schema.TypeList,
206+
Optional: true,
207+
ForceNew: true,
208+
Description: `A list of features to enable on the guest operating system. Applicable only for bootable images.`,
209+
Elem: &schema.Schema{
210+
Type: schema.TypeString,
211+
},
212+
},
213+
196214
"source_image": {
197215
Type: schema.TypeString,
198216
Optional: true,
@@ -1375,6 +1393,14 @@ func buildDisks(d *schema.ResourceData, config *transport_tpg.Config) ([]*comput
13751393
disk.Type = v.(string)
13761394
}
13771395

1396+
if v, ok := d.GetOk(prefix + ".guest_os_features"); ok {
1397+
disk.GuestOsFeatures = expandComputeInstanceGuestOsFeatures(v.([]interface{}))
1398+
}
1399+
1400+
if v, ok := d.GetOk(prefix + ".architecture"); ok {
1401+
disk.Architecture = v.(string)
1402+
}
1403+
13781404
disks = append(disks, &disk)
13791405
}
13801406

@@ -1639,6 +1665,8 @@ func flattenDisk(disk *compute.AttachedDisk, configDisk map[string]any, defaultP
16391665
diskMap["source"] = tpgresource.ConvertSelfLinkToV1(disk.Source)
16401666
diskMap["mode"] = disk.Mode
16411667
diskMap["type"] = disk.Type
1668+
diskMap["guest_os_features"] = flattenComputeInstanceGuestOsFeatures(disk.GuestOsFeatures)
1669+
diskMap["architecture"] = configDisk["architecture"]
16421670

16431671
return diskMap, nil
16441672
}

google/services/compute/resource_compute_instance_template_test.go

+57
Original file line numberDiff line numberDiff line change
@@ -1587,6 +1587,36 @@ func TestAccComputeInstanceTemplate_migration(t *testing.T) {
15871587
})
15881588
}
15891589

1590+
func TestAccComputeInstanceTemplate_GuestOsFeatures(t *testing.T) {
1591+
t.Parallel()
1592+
1593+
var instanceTemplate compute.InstanceTemplate
1594+
context := map[string]interface{}{
1595+
"template_name": fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10)),
1596+
"guest_os_features": `["UEFI_COMPATIBLE", "VIRTIO_SCSI_MULTIQUEUE", "GVNIC", "IDPF"]`,
1597+
}
1598+
1599+
acctest.VcrTest(t, resource.TestCase{
1600+
PreCheck: func() { acctest.AccTestPreCheck(t) },
1601+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
1602+
CheckDestroy: testAccCheckComputeInstanceTemplateDestroyProducer(t),
1603+
Steps: []resource.TestStep{
1604+
{
1605+
Config: testAccComputeInstanceTemplate_GuestOsFeatures(context),
1606+
Check: resource.ComposeTestCheckFunc(
1607+
testAccCheckComputeInstanceTemplateExists(
1608+
t, "google_compute_instance_template.foobar", &instanceTemplate),
1609+
resource.TestCheckResourceAttr("google_compute_instance_template.foobar", "disk.0.guest_os_features.#", "4"),
1610+
resource.TestCheckResourceAttr("google_compute_instance_template.foobar", "disk.0.guest_os_features.0", "UEFI_COMPATIBLE"),
1611+
resource.TestCheckResourceAttr("google_compute_instance_template.foobar", "disk.0.guest_os_features.1", "VIRTIO_SCSI_MULTIQUEUE"),
1612+
resource.TestCheckResourceAttr("google_compute_instance_template.foobar", "disk.0.guest_os_features.2", "GVNIC"),
1613+
resource.TestCheckResourceAttr("google_compute_instance_template.foobar", "disk.0.guest_os_features.3", "IDPF"),
1614+
),
1615+
},
1616+
},
1617+
})
1618+
}
1619+
15901620
func TestAccComputeInstanceTemplate_withLabels(t *testing.T) {
15911621
acctest.SkipIfVcr(t)
15921622
t.Parallel()
@@ -4668,3 +4698,30 @@ resource "google_compute_instance_template" "foobar" {
46684698
}
46694699
`, context)
46704700
}
4701+
4702+
func testAccComputeInstanceTemplate_GuestOsFeatures(context map[string]interface{}) string {
4703+
return acctest.Nprintf(`
4704+
data "google_compute_image" "my_image" {
4705+
family = "debian-11"
4706+
project = "debian-cloud"
4707+
}
4708+
4709+
resource "google_compute_instance_template" "foobar" {
4710+
name = "%{template_name}"
4711+
machine_type = "e2-medium"
4712+
4713+
disk {
4714+
source_image = data.google_compute_image.my_image.self_link
4715+
auto_delete = true
4716+
disk_size_gb = 10
4717+
architecture = "X86_64"
4718+
boot = true
4719+
guest_os_features = %{guest_os_features}
4720+
}
4721+
4722+
network_interface {
4723+
network = "default"
4724+
}
4725+
}
4726+
`, context)
4727+
}

google/services/compute/resource_compute_region_instance_template.go

+18
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@ func ResourceComputeRegionInstanceTemplate() *schema.Resource {
121121
Description: `Name of the disk. When not provided, this defaults to the name of the instance.`,
122122
},
123123

124+
"architecture": {
125+
Type: schema.TypeString,
126+
Optional: true,
127+
ForceNew: true,
128+
Computed: true,
129+
Description: `The architecture of the image. Allowed values are ARM64 or X86_64.`,
130+
},
131+
124132
"disk_size_gb": {
125133
Type: schema.TypeInt,
126134
Optional: true,
@@ -172,6 +180,16 @@ func ResourceComputeRegionInstanceTemplate() *schema.Resource {
172180
Description: `A map of resource manager tags. Resource manager tag keys and values have the same definition as resource manager tags. Keys must be in the format tagKeys/{tag_key_id}, and values are in the format tagValues/456. The field is ignored (both PUT & PATCH) when empty.`,
173181
},
174182

183+
"guest_os_features": {
184+
Type: schema.TypeList,
185+
Optional: true,
186+
ForceNew: true,
187+
Description: `A list of features to enable on the guest operating system. Applicable only for bootable images.`,
188+
Elem: &schema.Schema{
189+
Type: schema.TypeString,
190+
},
191+
},
192+
175193
"source_image": {
176194
Type: schema.TypeString,
177195
Optional: true,

google/services/compute/resource_compute_region_instance_template_test.go

+58
Original file line numberDiff line numberDiff line change
@@ -1481,6 +1481,36 @@ func TestAccComputeRegionInstanceTemplate_keyRevocationActionType(t *testing.T)
14811481
})
14821482
}
14831483

1484+
func TestAccComputeRegionInstanceTemplate_GuestOsFeatures(t *testing.T) {
1485+
t.Parallel()
1486+
1487+
var instanceTemplate compute.InstanceTemplate
1488+
context := map[string]interface{}{
1489+
"template_name": fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10)),
1490+
"guest_os_features": `["UEFI_COMPATIBLE", "VIRTIO_SCSI_MULTIQUEUE", "GVNIC", "IDPF"]`,
1491+
}
1492+
1493+
acctest.VcrTest(t, resource.TestCase{
1494+
PreCheck: func() { acctest.AccTestPreCheck(t) },
1495+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
1496+
CheckDestroy: testAccCheckComputeRegionInstanceTemplateDestroyProducer(t),
1497+
Steps: []resource.TestStep{
1498+
{
1499+
Config: testAccComputeRegionInstanceTemplate_GuestOsFeatures(context),
1500+
Check: resource.ComposeTestCheckFunc(
1501+
testAccCheckComputeRegionInstanceTemplateExists(
1502+
t, "google_compute_region_instance_template.foobar", &instanceTemplate),
1503+
resource.TestCheckResourceAttr("google_compute_region_instance_template.foobar", "disk.0.guest_os_features.#", "4"),
1504+
resource.TestCheckResourceAttr("google_compute_region_instance_template.foobar", "disk.0.guest_os_features.0", "UEFI_COMPATIBLE"),
1505+
resource.TestCheckResourceAttr("google_compute_region_instance_template.foobar", "disk.0.guest_os_features.1", "VIRTIO_SCSI_MULTIQUEUE"),
1506+
resource.TestCheckResourceAttr("google_compute_region_instance_template.foobar", "disk.0.guest_os_features.2", "GVNIC"),
1507+
resource.TestCheckResourceAttr("google_compute_region_instance_template.foobar", "disk.0.guest_os_features.3", "IDPF"),
1508+
),
1509+
},
1510+
},
1511+
})
1512+
}
1513+
14841514
func testAccCheckComputeRegionInstanceTemplateDestroyProducer(t *testing.T) func(s *terraform.State) error {
14851515
return func(s *terraform.State) error {
14861516
config := acctest.GoogleProviderConfig(t)
@@ -4260,3 +4290,31 @@ data "google_compute_default_service_account" "default" {
42604290
}
42614291
`, context)
42624292
}
4293+
4294+
func testAccComputeRegionInstanceTemplate_GuestOsFeatures(context map[string]interface{}) string {
4295+
return acctest.Nprintf(`
4296+
data "google_compute_image" "my_image" {
4297+
family = "debian-11"
4298+
project = "debian-cloud"
4299+
}
4300+
4301+
resource "google_compute_region_instance_template" "foobar" {
4302+
name = "%{template_name}"
4303+
machine_type = "e2-medium"
4304+
region = "us-central1"
4305+
4306+
disk {
4307+
source_image = data.google_compute_image.my_image.self_link
4308+
auto_delete = true
4309+
disk_size_gb = 10
4310+
boot = true
4311+
architecture = "X86_64"
4312+
guest_os_features = %{guest_os_features}
4313+
}
4314+
4315+
network_interface {
4316+
network = "default"
4317+
}
4318+
}
4319+
`, context)
4320+
}

website/docs/r/compute_instance_template.html.markdown

+4
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,8 @@ The following arguments are supported:
451451

452452
* `resource_manager_tags` - (Optional) A set of key/value resource manager tag pairs to bind to this disk. Keys must be in the format tagKeys/{tag_key_id}, and values are in the format tagValues/456.
453453

454+
* `guest_os_features` - (optional) A list of features to enable on the guest operating system. Applicable only for bootable images. Read [Enabling guest operating system features](https://cloud.google.com/compute/docs/images/create-delete-deprecate-private-images#guest-os-features) to see a list of available options.
455+
454456
* `source_image` - (Optional) The image from which to
455457
initialize this disk. This can be one of: the image's `self_link`,
456458
`projects/{project}/global/images/{image}`,
@@ -484,6 +486,8 @@ The following arguments are supported:
484486
or READ_ONLY. If you are attaching or creating a boot disk, this must
485487
read-write mode.
486488

489+
* `architecture` - (Optional) The architecture of the attached disk. Valid values are `ARM64` or `x86_64`.
490+
487491
* `source` - (Optional) The name (**not self_link**)
488492
of the disk (such as those managed by `google_compute_disk`) to attach.
489493
~> **Note:** Either `source`, `source_image`, or `source_snapshot` is **required** in a disk block unless the disk type is `local-ssd`. Check the API [docs](https://cloud.google.com/compute/docs/reference/rest/v1/instanceTemplates/insert) for details.

website/docs/r/compute_region_instance_template.html.markdown

+4
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,8 @@ The following arguments are supported:
416416

417417
* `resource_manager_tags` - (Optional) A set of key/value resource manager tag pairs to bind to this disk. Keys must be in the format tagKeys/{tag_key_id}, and values are in the format tagValues/456.
418418

419+
* `guest_os_features` - (optional) A list of features to enable on the guest operating system. Applicable only for bootable images. Read [Enabling guest operating system features](https://cloud.google.com/compute/docs/images/create-delete-deprecate-private-images#guest-os-features) to see a list of available options.
420+
419421
* `source_image` - (Optional) The image from which to
420422
initialize this disk. This can be one of: the image's `self_link`,
421423
`projects/{project}/global/images/{image}`,
@@ -449,6 +451,8 @@ The following arguments are supported:
449451
or READ_ONLY. If you are attaching or creating a boot disk, this must
450452
read-write mode.
451453

454+
* `architecture` - (Optional) The architecture of the attached disk. Valid values are `ARM64` or `x86_64`.
455+
452456
* `source` - (Optional) The name (**not self_link**)
453457
of the disk (such as those managed by `google_compute_disk`) to attach.
454458
~> **Note:** Either `source`, `source_image`, or `source_snapshot` is **required** in a disk block unless the disk type is `local-ssd`. Check the API [docs](https://cloud.google.com/compute/docs/reference/rest/v1/instanceTemplates/insert) for details.

0 commit comments

Comments
 (0)