Skip to content

Commit

Permalink
Set error condition if both image and image_family are set.
Browse files Browse the repository at this point in the history
  • Loading branch information
jim-raney-physiq committed Sep 23, 2017
1 parent b6bbc3f commit f01db0a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
19 changes: 17 additions & 2 deletions lib/vagrant-google/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,17 @@ def finalize! # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedC
@google_project_id = ENV['GOOGLE_PROJECT_ID'] if @google_project_id == UNSET_VALUE

# Image must be nil, since we can't default that
@image = "debian-8-jessie-v20160511" if @image == UNSET_VALUE
if (@image == UNSET_VALUE) && (@image_family == UNSET_VALUE)
@image = "debian-8-jessie-v20160511"
end

if @image == UNSET_VALUE
if @image_family == UNSET_VALUE
@image = "debian-8-jessie-v20160511"
else
@image = nil
end
end

# Default image family is nil
@image_family = nil if @image_family == UNSET_VALUE
Expand Down Expand Up @@ -382,9 +392,14 @@ def validate(machine)
errors << I18n.t("vagrant_google.config.on_host_maintenance_invalid_on_preemptible") unless \
config.on_host_maintenance == "TERMINATE"
end

if config.image_family
errors << I18n.t("vagrant_google.config.image_and_image_family_set") if \
config.image
end
end

errors << I18n.t("vagrant_google.config.image_required") if config.image.nil?
errors << I18n.t("vagrant_google.config.image_required") if config.image.nil? && config.image_family.nil?
errors << I18n.t("vagrant_google.config.name_required") if @name.nil?

{ "Google Provider" => errors }
Expand Down
2 changes: 2 additions & 0 deletions locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ en:
on_host_maintenance_invalid_on_preemptible: |-
"on_host_maintenance" option must be set to "TERMINATE" for preemptible
instances.
image_and_image_family_set: |-
"image" must be unset when setting "image_family"
#-------------------------------------------------------------------------------
# Translations for exception classes
#-------------------------------------------------------------------------------
Expand Down

0 comments on commit f01db0a

Please sign in to comment.