|
|
|
|
@ -24,16 +24,18 @@ import (
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
clienrb = "client.rb"
|
|
|
|
|
defaultEnv = "_default"
|
|
|
|
|
firstBoot = "first-boot.json"
|
|
|
|
|
logfileDir = "logfiles"
|
|
|
|
|
linuxChefCmd = "chef-client"
|
|
|
|
|
linuxConfDir = "/etc/chef"
|
|
|
|
|
secretKey = "encrypted_data_bag_secret"
|
|
|
|
|
validationKey = "validation.pem"
|
|
|
|
|
windowsChefCmd = "cmd /c chef-client"
|
|
|
|
|
windowsConfDir = "C:/chef"
|
|
|
|
|
clienrb = "client.rb"
|
|
|
|
|
defaultEnv = "_default"
|
|
|
|
|
firstBoot = "first-boot.json"
|
|
|
|
|
logfileDir = "logfiles"
|
|
|
|
|
linuxChefCmd = "chef-client"
|
|
|
|
|
linuxKnifeCmd = "knife"
|
|
|
|
|
linuxConfDir = "/etc/chef"
|
|
|
|
|
secretKey = "encrypted_data_bag_secret"
|
|
|
|
|
validationKey = "validation.pem"
|
|
|
|
|
windowsChefCmd = "cmd /c chef-client"
|
|
|
|
|
windowsKnifeCmd = "cmd /c knife"
|
|
|
|
|
windowsConfDir = "C:/chef"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const clientConf = `
|
|
|
|
|
@ -74,34 +76,36 @@ ENV['no_proxy'] = "{{ join .NOProxy "," }}"
|
|
|
|
|
|
|
|
|
|
// Provisioner represents a specificly configured chef provisioner
|
|
|
|
|
type Provisioner struct {
|
|
|
|
|
Attributes interface{} `mapstructure:"attributes"`
|
|
|
|
|
ClientOptions []string `mapstructure:"client_options"`
|
|
|
|
|
DisableReporting bool `mapstructure:"disable_reporting"`
|
|
|
|
|
Environment string `mapstructure:"environment"`
|
|
|
|
|
LogToFile bool `mapstructure:"log_to_file"`
|
|
|
|
|
UsePolicyfile bool `mapstructure:"use_policyfile"`
|
|
|
|
|
PolicyGroup string `mapstructure:"policy_group"`
|
|
|
|
|
PolicyName string `mapstructure:"policy_name"`
|
|
|
|
|
HTTPProxy string `mapstructure:"http_proxy"`
|
|
|
|
|
HTTPSProxy string `mapstructure:"https_proxy"`
|
|
|
|
|
NOProxy []string `mapstructure:"no_proxy"`
|
|
|
|
|
NodeName string `mapstructure:"node_name"`
|
|
|
|
|
OhaiHints []string `mapstructure:"ohai_hints"`
|
|
|
|
|
OSType string `mapstructure:"os_type"`
|
|
|
|
|
PreventSudo bool `mapstructure:"prevent_sudo"`
|
|
|
|
|
RunList []string `mapstructure:"run_list"`
|
|
|
|
|
SecretKey string `mapstructure:"secret_key"`
|
|
|
|
|
ServerURL string `mapstructure:"server_url"`
|
|
|
|
|
SkipInstall bool `mapstructure:"skip_install"`
|
|
|
|
|
SSLVerifyMode string `mapstructure:"ssl_verify_mode"`
|
|
|
|
|
ValidationClientName string `mapstructure:"validation_client_name"`
|
|
|
|
|
ValidationKey string `mapstructure:"validation_key"`
|
|
|
|
|
Version string `mapstructure:"version"`
|
|
|
|
|
|
|
|
|
|
installChefClient func(terraform.UIOutput, communicator.Communicator) error
|
|
|
|
|
createConfigFiles func(terraform.UIOutput, communicator.Communicator) error
|
|
|
|
|
runChefClient func(terraform.UIOutput, communicator.Communicator) error
|
|
|
|
|
useSudo bool
|
|
|
|
|
Attributes interface{} `mapstructure:"attributes"`
|
|
|
|
|
ClientOptions []string `mapstructure:"client_options"`
|
|
|
|
|
DisableReporting bool `mapstructure:"disable_reporting"`
|
|
|
|
|
Environment string `mapstructure:"environment"`
|
|
|
|
|
FetchChefCertificates bool `mapstructure:"fetch_chef_certificates"`
|
|
|
|
|
LogToFile bool `mapstructure:"log_to_file"`
|
|
|
|
|
UsePolicyfile bool `mapstructure:"use_policyfile"`
|
|
|
|
|
PolicyGroup string `mapstructure:"policy_group"`
|
|
|
|
|
PolicyName string `mapstructure:"policy_name"`
|
|
|
|
|
HTTPProxy string `mapstructure:"http_proxy"`
|
|
|
|
|
HTTPSProxy string `mapstructure:"https_proxy"`
|
|
|
|
|
NOProxy []string `mapstructure:"no_proxy"`
|
|
|
|
|
NodeName string `mapstructure:"node_name"`
|
|
|
|
|
OhaiHints []string `mapstructure:"ohai_hints"`
|
|
|
|
|
OSType string `mapstructure:"os_type"`
|
|
|
|
|
PreventSudo bool `mapstructure:"prevent_sudo"`
|
|
|
|
|
RunList []string `mapstructure:"run_list"`
|
|
|
|
|
SecretKey string `mapstructure:"secret_key"`
|
|
|
|
|
ServerURL string `mapstructure:"server_url"`
|
|
|
|
|
SkipInstall bool `mapstructure:"skip_install"`
|
|
|
|
|
SSLVerifyMode string `mapstructure:"ssl_verify_mode"`
|
|
|
|
|
ValidationClientName string `mapstructure:"validation_client_name"`
|
|
|
|
|
ValidationKey string `mapstructure:"validation_key"`
|
|
|
|
|
Version string `mapstructure:"version"`
|
|
|
|
|
|
|
|
|
|
installChefClient func(terraform.UIOutput, communicator.Communicator) error
|
|
|
|
|
createConfigFiles func(terraform.UIOutput, communicator.Communicator) error
|
|
|
|
|
fetchChefCertificates func(terraform.UIOutput, communicator.Communicator) error
|
|
|
|
|
runChefClient func(terraform.UIOutput, communicator.Communicator) error
|
|
|
|
|
useSudo bool
|
|
|
|
|
|
|
|
|
|
// Deprecated Fields
|
|
|
|
|
SecretKeyPath string `mapstructure:"secret_key_path"`
|
|
|
|
|
@ -138,11 +142,13 @@ func (r *ResourceProvisioner) Apply(
|
|
|
|
|
case "linux":
|
|
|
|
|
p.installChefClient = p.linuxInstallChefClient
|
|
|
|
|
p.createConfigFiles = p.linuxCreateConfigFiles
|
|
|
|
|
p.fetchChefCertificates = p.fetchChefCertificatesFunc(linuxChefCmd, linuxConfDir)
|
|
|
|
|
p.runChefClient = p.runChefClientFunc(linuxChefCmd, linuxConfDir)
|
|
|
|
|
p.useSudo = !p.PreventSudo && s.Ephemeral.ConnInfo["user"] != "root"
|
|
|
|
|
case "windows":
|
|
|
|
|
p.installChefClient = p.windowsInstallChefClient
|
|
|
|
|
p.createConfigFiles = p.windowsCreateConfigFiles
|
|
|
|
|
p.fetchChefCertificates = p.fetchChefCertificatesFunc(windowsChefCmd, windowsConfDir)
|
|
|
|
|
p.runChefClient = p.runChefClientFunc(windowsChefCmd, windowsConfDir)
|
|
|
|
|
p.useSudo = false
|
|
|
|
|
default:
|
|
|
|
|
@ -176,6 +182,13 @@ func (r *ResourceProvisioner) Apply(
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if p.FetchChefCertificates {
|
|
|
|
|
o.Output("Fetch Chef certificates...")
|
|
|
|
|
if err := p.fetchChefCertificates(o, comm); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
o.Output("Starting initial Chef-Client run...")
|
|
|
|
|
if err := p.runChefClient(o, comm); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
@ -343,6 +356,17 @@ func retryFunc(timeout time.Duration, f func() error) error {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Provisioner) fetchChefCertificatesFunc(
|
|
|
|
|
knifeCmd string,
|
|
|
|
|
confDir string) func(terraform.UIOutput, communicator.Communicator) error {
|
|
|
|
|
return func(o terraform.UIOutput, comm communicator.Communicator) error {
|
|
|
|
|
clientrb := path.Join(confDir, clienrb)
|
|
|
|
|
cmd := fmt.Sprintf("%s ssl fetch -c %s", knifeCmd, clientrb)
|
|
|
|
|
|
|
|
|
|
return p.runCommand(o, comm, cmd)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Provisioner) runChefClientFunc(
|
|
|
|
|
chefCmd string,
|
|
|
|
|
confDir string) func(terraform.UIOutput, communicator.Communicator) error {
|
|
|
|
|
|