Skip to content

Commit fec11ce

Browse files
committed
Allow the GCP VM type to optionally be configured
1 parent 3fd857e commit fec11ce

File tree

5 files changed

+19
-4
lines changed

5 files changed

+19
-4
lines changed

lib/packer/config/gcp.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def initialize(
1616
root_disk_size: 32,
1717
omit_external_ip: false,
1818
vm_tags: ['winrm'],
19+
vm_type:,
1920
network: nil,
2021
network_project_id: nil,
2122
subnetwork: nil)
@@ -31,6 +32,7 @@ def initialize(
3132
@root_disk_size = root_disk_size
3233
@omit_external_ip = omit_external_ip
3334
@vm_tags = vm_tags
35+
@vm_type = vm_type
3436
@network = network
3537
@network_project_id = network_project_id
3638
@subnetwork = subnetwork
@@ -48,7 +50,7 @@ def builders
4850
'zone' => 'us-west1-c',
4951
'disk_size' => @root_disk_size,
5052
'image_name' => "packer-#{Time.now.to_i}",
51-
'machine_type' => 'n1-standard-4',
53+
'machine_type' => @vm_type,
5254
'network' => @network,
5355
'network_project_id' => @network_project_id,
5456
'subnetwork' => @subnetwork,

lib/stemcell/builder/gcp.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ def initialize(account_json:,
77
source_image:,
88
image_family:,
99
vm_prefix:,
10+
vm_type:,
1011
network:,
1112
network_project_id:,
1213
subnetwork:,
@@ -16,6 +17,7 @@ def initialize(account_json:,
1617
@source_image = source_image
1718
@image_family = image_family
1819
@vm_prefix = vm_prefix
20+
@vm_type = vm_type
1921
@network = network
2022
@network_project_id = network_project_id
2123
@subnetwork = subnetwork
@@ -49,6 +51,7 @@ def packer_config
4951
os: @os,
5052
version: @version,
5153
vm_prefix: @vm_prefix,
54+
vm_type: @vm_type,
5255
mount_ephemeral_disk: @mount_ephemeral_disk
5356
).dump
5457
end

lib/tasks/build/gcp.rake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ namespace :build do
3636
image_family: image_family,
3737
version: version,
3838
vm_prefix: ENV.fetch('VM_PREFIX', ''),
39+
vm_type: ENV.fetch('GCP_VM_TYPE', 'n1-standard-4'),
3940
mount_ephemeral_disk: ENV.fetch('MOUNT_EPHEMERAL_DISK', 'false')
4041
)
4142

spec/packer/config/gcp_spec.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
os: os,
2020
version: '',
2121
vm_prefix: 'some-vm-prefix',
22+
vm_type: 'some-vm-type',
2223
).builders }
2324

2425
let (:baseline_builders) { {
@@ -30,7 +31,7 @@
3031
'image_family' => 'some-image-family',
3132
'zone' => 'us-west1-c',
3233
'disk_size' => 32,
33-
'machine_type' => 'n1-standard-4',
34+
'machine_type' => 'some-vm-type',
3435
'omit_external_ip' => false,
3536
'communicator' => 'winrm',
3637
'winrm_username' => 'winrmuser',
@@ -64,6 +65,7 @@
6465
os: '',
6566
version: '',
6667
vm_prefix: '',
68+
vm_type: '',
6769
).builders
6870
expect(builders[0]['metadata']).to include(
6971
'name' => "packer-#{Time.now.to_i}"
@@ -95,7 +97,8 @@
9597
image_family: '',
9698
os: 'windows2019',
9799
version: version,
98-
vm_prefix: ''
100+
vm_prefix: '',
101+
vm_type: '',
99102
).provisioners
100103
expected_provisioners_base = [
101104
{"type" => "file", "source" => "build/bosh-psmodules.zip", "destination" => "C:\\provision\\bosh-psmodules.zip", "pause_before"=>"60s"},

spec/stemcell/builder/gcp_spec.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
source_image = "some-source-image"
2828
image_family= "some-family"
2929
vm_prefix = "some-vm-prefix"
30+
vm_type = "some-vm-type"
3031
network = 'default'
3132
network_project_id = 'project-id'
3233
subnetwork = 'subnet'
@@ -42,6 +43,7 @@
4243
os: os,
4344
version: version,
4445
vm_prefix: vm_prefix,
46+
vm_type: vm_type,
4547
mount_ephemeral_disk: false,
4648
network: network,
4749
network_project_id: network_project_id,
@@ -77,6 +79,7 @@
7779
source_image: source_image,
7880
image_family: image_family,
7981
vm_prefix: vm_prefix,
82+
vm_type: vm_type,
8083
mount_ephemeral_disk: "false",
8184
network: network,
8285
network_project_id: network_project_id,
@@ -94,6 +97,7 @@
9497
packer_vars = 'some-packer-vars'
9598
os = 'windows2019'
9699
vm_prefix = 'some-vm-prefix'
100+
vm_type = 'some-vm-type'
97101
network = 'default'
98102
network_project_id = 'project-id'
99103
subnetwork = 'subnet'
@@ -109,6 +113,7 @@
109113
os: os,
110114
version: '',
111115
vm_prefix: vm_prefix,
116+
vm_type: vm_type,
112117
mount_ephemeral_disk: false,
113118
network: network,
114119
network_project_id: network_project_id,
@@ -131,7 +136,8 @@
131136
account_json: account_json,
132137
source_image: source_image,
133138
image_family: image_family,
134-
vm_prefix: vm_prefix
139+
vm_prefix: vm_prefix,
140+
vm_type: vm_type,
135141
).build
136142
}.to raise_error(Stemcell::Builder::PackerFailure)
137143
end

0 commit comments

Comments
 (0)