-
Notifications
You must be signed in to change notification settings - Fork 564
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
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
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:
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.