ZeTopHat / suse-vagrant-labs

Vagrant labs for SUSE-based environments
MIT License
4 stars 3 forks source link

Labs should fail early in `vagrant up` and with useful error if any required regcode is missing #22

Closed Thr3d closed 11 months ago

ZeTopHat commented 11 months ago

Perhaps the easiest thing to do here would be to require an if-statement on the relevant registration codes for each lab, in their respective provisioning scripts. e.g. in the provisioners/common/bootstrap.sh:

 if [[ -z "$SLEREGCODE" ]]; then
    >&2 echo "Required SLEREGCODE variable has not been filled out in the config/secret.yaml file."
    exit 1
  fi

Alternatively we could try to handle it in the Vagrantfile template. However, it would need to know what registration codes are required for the specific lab it is processing. So in that case we'd have to have a new required parameter for every lab. One that lists required registration codes.

So in the case of the basic lab we'd add something like, requiredcodes: ["sleregcode"] and then in the Vagrantfile right after the various vars are loaded:

  lab_vars["requiredcodes"].each do |code|
    if (secret_vars[code.downcase].empty?)
      abort("Required sleregcode variable has not been filled out in the config/secret.yaml file.")
    end
  end

Personally I like the latter option a bit more even though it's a bit more involved. It also exits the script nearly immediately, rather than having to wait for it to reach the point of executing the provisioning scripts.

What do y'all think @Thr3d and @slsnow ?

slsnow commented 11 months ago

Let's do requiredsecrets, and good idea!