googleapis / googleapis/google-cloud-ruby

Compute: `disks` is a required param even when creating an instance from an instance template

Open
#23,642 2 comments 0 reactions 0 assignees View on GitHub
api: compute priority: p2 type: question
Dominant language
Ruby
Stars
1.4k
Forks
578
Avg merge
1d 11h
Merged PRs (30d)
166

Description

Not sure if this is an actual bug or if this is the intended behaviour and it's more of a feature request.

When using gcloud cli we are perfectly able to create machines using an instance template, and we do not need to specify disks. Because of this, we would expect the same behaviour.
However, the code examples for this use case in the documentation do not include Ruby (https://cloud.google.com/compute/docs/instances/create-vm-from-instance-template#create_a_vm_instance_from_an_instance_template), which indicates that maybe this is indeed a missing feature.

#### Environment details

- OS: Debian Bullseye
- Ruby version: 3.2.2
- Gem name and version: google-cloud-compute (1.2.0), google-cloud-compute-v1 (2.5.0)

#### Steps to reproduce

- Run the code below to create an instance using an instance template
- Get an error saying disks are a required field

#### Code example

```ruby
Google::Cloud::Compute.configure do |config|
config.credentials = '/path/to/credentials.json'
end
instances_client = Google::Cloud::Compute.instances
instance_templates_client = Google::Cloud::Compute.instance_templates

zone = 'europe-west4-c'
machine_type = 'e2-medium'
project = 'my_project'
source_instance_template = 'my_instance_template'

instance_template = instance_templates_client.get(project: project, instance_template: source_instance_template)

instance = Google::Cloud::Compute::V1::Instance.new(
name: 'my_test_machine',
machine_type: "zones/#{zone}/machineTypes/#{machine_type}",
disks: [ ], # also tried not including it
network_interfaces: [
{
name: "projects/my-project/global/networks/mynet",
subnetwork: "projects/my-project/regions/europe-west4/subnetworks/mysubnet",
}
],
)

request = { project: project, zone: zone, instance_resource: instance, source_instance_template: instance_template.self_link }

puts "Creating the instance..."
begin
# Send the insert request.
operation = instances_client.insert(request)
```

#### Full backtrace

```sh
Creating the instance...
Exception during creation:
An error has occurred when making a REST request: Invalid value for field 'resource.disks': ''. No disks are specified.
```

Also tried setting `disks: instance_template.properties.disks.to_a` to see if I could work around this, but in that case the request also failed with the following error:

```sh
An error has occurred when making a REST request: Invalid value for field 'resource.disks[0].initializeParams.diskType': 'pd-standard'. The URL is malformed.
```

This suggests that the disks need to be defined all over again, which defeats the purpose of having instance templates.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.