Tweaking a few minor things according to the feedback on GH
This commit is contained in:
parent
a8dacede24
commit
11314a3d71
|
@ -74,6 +74,7 @@ type Provisioner struct {
|
||||||
installChefClient func(terraform.UIOutput, communicator.Communicator) error
|
installChefClient func(terraform.UIOutput, communicator.Communicator) error
|
||||||
createConfigFiles func(terraform.UIOutput, communicator.Communicator) error
|
createConfigFiles func(terraform.UIOutput, communicator.Communicator) error
|
||||||
runChefClient func(terraform.UIOutput, communicator.Communicator) error
|
runChefClient func(terraform.UIOutput, communicator.Communicator) error
|
||||||
|
useSudo bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResourceProvisioner represents a generic chef provisioner
|
// ResourceProvisioner represents a generic chef provisioner
|
||||||
|
@ -93,15 +94,15 @@ func (r *ResourceProvisioner) Apply(
|
||||||
// Set some values based on the targeted OS
|
// Set some values based on the targeted OS
|
||||||
switch s.Ephemeral.ConnInfo["type"] {
|
switch s.Ephemeral.ConnInfo["type"] {
|
||||||
case "ssh", "": // The default connection type is ssh, so if the type is empty use ssh
|
case "ssh", "": // The default connection type is ssh, so if the type is empty use ssh
|
||||||
p.PreventSudo = p.PreventSudo || s.Ephemeral.ConnInfo["user"] == "root"
|
|
||||||
p.installChefClient = p.sshInstallChefClient
|
p.installChefClient = p.sshInstallChefClient
|
||||||
p.createConfigFiles = p.sshCreateConfigFiles
|
p.createConfigFiles = p.sshCreateConfigFiles
|
||||||
p.runChefClient = p.runChefClientFunc(linuxConfDir)
|
p.runChefClient = p.runChefClientFunc(linuxConfDir)
|
||||||
|
p.useSudo = !p.PreventSudo && s.Ephemeral.ConnInfo["user"] != "root"
|
||||||
case "winrm":
|
case "winrm":
|
||||||
p.PreventSudo = true
|
|
||||||
p.installChefClient = p.winrmInstallChefClient
|
p.installChefClient = p.winrmInstallChefClient
|
||||||
p.createConfigFiles = p.winrmCreateConfigFiles
|
p.createConfigFiles = p.winrmCreateConfigFiles
|
||||||
p.runChefClient = p.runChefClientFunc(windowsConfDir)
|
p.runChefClient = p.runChefClientFunc(windowsConfDir)
|
||||||
|
p.useSudo = false
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("Unsupported connection type: %s", s.Ephemeral.ConnInfo["type"])
|
return fmt.Errorf("Unsupported connection type: %s", s.Ephemeral.ConnInfo["type"])
|
||||||
}
|
}
|
||||||
|
@ -363,7 +364,7 @@ func (p *Provisioner) runCommand(
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
// Unless prevented, prefix the command with sudo
|
// Unless prevented, prefix the command with sudo
|
||||||
if !p.PreventSudo {
|
if p.useSudo {
|
||||||
command = "sudo " + command
|
command = "sudo " + command
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -126,6 +126,7 @@ func TestResourceProvider_runChefClient(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
p.runChefClient = p.runChefClientFunc(tc.ConfDir)
|
p.runChefClient = p.runChefClientFunc(tc.ConfDir)
|
||||||
|
p.useSudo = !p.PreventSudo
|
||||||
|
|
||||||
err = p.runChefClient(o, c)
|
err = p.runChefClient(o, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -50,7 +50,7 @@ func (p *Provisioner) sshCreateConfigFiles(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure we have enough rights to upload the files if using sudo
|
// Make sure we have enough rights to upload the files if using sudo
|
||||||
if !p.PreventSudo {
|
if p.useSudo {
|
||||||
if err := p.runCommand(o, comm, "chmod 777 "+linuxConfDir); err != nil {
|
if err := p.runCommand(o, comm, "chmod 777 "+linuxConfDir); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ func (p *Provisioner) sshCreateConfigFiles(
|
||||||
}
|
}
|
||||||
|
|
||||||
// When done copying the files restore the rights and make sure root is owner
|
// When done copying the files restore the rights and make sure root is owner
|
||||||
if !p.PreventSudo {
|
if p.useSudo {
|
||||||
if err := p.runCommand(o, comm, "chmod 755 "+linuxConfDir); err != nil {
|
if err := p.runCommand(o, comm, "chmod 755 "+linuxConfDir); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,6 +116,8 @@ func TestResourceProvider_sshInstallChefClient(t *testing.T) {
|
||||||
t.Fatalf("Error: %v", err)
|
t.Fatalf("Error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p.useSudo = !p.PreventSudo
|
||||||
|
|
||||||
err = p.sshInstallChefClient(o, c)
|
err = p.sshInstallChefClient(o, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Test %q failed: %v", k, err)
|
t.Fatalf("Test %q failed: %v", k, err)
|
||||||
|
@ -254,6 +256,8 @@ func TestResourceProvider_sshCreateConfigFiles(t *testing.T) {
|
||||||
t.Fatalf("Error: %v", err)
|
t.Fatalf("Error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p.useSudo = !p.PreventSudo
|
||||||
|
|
||||||
err = p.sshCreateConfigFiles(o, c)
|
err = p.sshCreateConfigFiles(o, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Test %q failed: %v", k, err)
|
t.Fatalf("Test %q failed: %v", k, err)
|
||||||
|
|
|
@ -17,7 +17,6 @@ func TestResourceProvider_winrmInstallChefClient(t *testing.T) {
|
||||||
"Default": {
|
"Default": {
|
||||||
Config: testConfig(t, map[string]interface{}{
|
Config: testConfig(t, map[string]interface{}{
|
||||||
"node_name": "nodename1",
|
"node_name": "nodename1",
|
||||||
"prevent_sudo": true, // Needs to be set for ALL WinRM tests!
|
|
||||||
"run_list": []interface{}{"cookbook::recipe"},
|
"run_list": []interface{}{"cookbook::recipe"},
|
||||||
"server_url": "https://chef.local",
|
"server_url": "https://chef.local",
|
||||||
"validation_client_name": "validator",
|
"validation_client_name": "validator",
|
||||||
|
@ -38,7 +37,6 @@ func TestResourceProvider_winrmInstallChefClient(t *testing.T) {
|
||||||
"http_proxy": "http://proxy.local",
|
"http_proxy": "http://proxy.local",
|
||||||
"no_proxy": []interface{}{"http://local.local", "http://local.org"},
|
"no_proxy": []interface{}{"http://local.local", "http://local.org"},
|
||||||
"node_name": "nodename1",
|
"node_name": "nodename1",
|
||||||
"prevent_sudo": true, // Needs to be set for ALL WinRM tests!
|
|
||||||
"run_list": []interface{}{"cookbook::recipe"},
|
"run_list": []interface{}{"cookbook::recipe"},
|
||||||
"server_url": "https://chef.local",
|
"server_url": "https://chef.local",
|
||||||
"validation_client_name": "validator",
|
"validation_client_name": "validator",
|
||||||
|
@ -57,7 +55,6 @@ func TestResourceProvider_winrmInstallChefClient(t *testing.T) {
|
||||||
"Version": {
|
"Version": {
|
||||||
Config: testConfig(t, map[string]interface{}{
|
Config: testConfig(t, map[string]interface{}{
|
||||||
"node_name": "nodename1",
|
"node_name": "nodename1",
|
||||||
"prevent_sudo": true, // Needs to be set for ALL WinRM tests!
|
|
||||||
"run_list": []interface{}{"cookbook::recipe"},
|
"run_list": []interface{}{"cookbook::recipe"},
|
||||||
"server_url": "https://chef.local",
|
"server_url": "https://chef.local",
|
||||||
"validation_client_name": "validator",
|
"validation_client_name": "validator",
|
||||||
|
@ -88,6 +85,8 @@ func TestResourceProvider_winrmInstallChefClient(t *testing.T) {
|
||||||
t.Fatalf("Error: %v", err)
|
t.Fatalf("Error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p.useSudo = false
|
||||||
|
|
||||||
err = p.winrmInstallChefClient(o, c)
|
err = p.winrmInstallChefClient(o, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Test %q failed: %v", k, err)
|
t.Fatalf("Test %q failed: %v", k, err)
|
||||||
|
@ -104,7 +103,6 @@ func TestResourceProvider_winrmCreateConfigFiles(t *testing.T) {
|
||||||
"Default": {
|
"Default": {
|
||||||
Config: testConfig(t, map[string]interface{}{
|
Config: testConfig(t, map[string]interface{}{
|
||||||
"node_name": "nodename1",
|
"node_name": "nodename1",
|
||||||
"prevent_sudo": true, // Needs to be set for ALL WinRM tests!
|
|
||||||
"run_list": []interface{}{"cookbook::recipe"},
|
"run_list": []interface{}{"cookbook::recipe"},
|
||||||
"server_url": "https://chef.local",
|
"server_url": "https://chef.local",
|
||||||
"validation_client_name": "validator",
|
"validation_client_name": "validator",
|
||||||
|
@ -128,7 +126,6 @@ func TestResourceProvider_winrmCreateConfigFiles(t *testing.T) {
|
||||||
"https_proxy": "https://proxy.local",
|
"https_proxy": "https://proxy.local",
|
||||||
"no_proxy": []interface{}{"http://local.local", "https://local.local"},
|
"no_proxy": []interface{}{"http://local.local", "https://local.local"},
|
||||||
"node_name": "nodename1",
|
"node_name": "nodename1",
|
||||||
"prevent_sudo": true, // Needs to be set for ALL WinRM tests!
|
|
||||||
"run_list": []interface{}{"cookbook::recipe"},
|
"run_list": []interface{}{"cookbook::recipe"},
|
||||||
"server_url": "https://chef.local",
|
"server_url": "https://chef.local",
|
||||||
"validation_client_name": "validator",
|
"validation_client_name": "validator",
|
||||||
|
@ -170,7 +167,6 @@ func TestResourceProvider_winrmCreateConfigFiles(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"node_name": "nodename1",
|
"node_name": "nodename1",
|
||||||
"prevent_sudo": true, // Needs to be set for ALL WinRM tests!
|
|
||||||
"run_list": []interface{}{"cookbook::recipe"},
|
"run_list": []interface{}{"cookbook::recipe"},
|
||||||
"server_url": "https://chef.local",
|
"server_url": "https://chef.local",
|
||||||
"validation_client_name": "validator",
|
"validation_client_name": "validator",
|
||||||
|
@ -203,6 +199,8 @@ func TestResourceProvider_winrmCreateConfigFiles(t *testing.T) {
|
||||||
t.Fatalf("Error: %v", err)
|
t.Fatalf("Error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p.useSudo = false
|
||||||
|
|
||||||
err = p.winrmCreateConfigFiles(o, c)
|
err = p.winrmCreateConfigFiles(o, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Test %q failed: %v", k, err)
|
t.Fatalf("Test %q failed: %v", k, err)
|
||||||
|
|
|
@ -48,7 +48,7 @@ resource "aws_instance" "web" {
|
||||||
|
|
||||||
The following arguments are supported:
|
The following arguments are supported:
|
||||||
|
|
||||||
* `attributes (hash)` - (Optional) A hash with initial node attributes for the new node.
|
* `attributes (map)` - (Optional) A map with initial node attributes for the new node.
|
||||||
See example.
|
See example.
|
||||||
|
|
||||||
* `environment (string)` - (Optional) The Chef environment the new node will be joining
|
* `environment (string)` - (Optional) The Chef environment the new node will be joining
|
||||||
|
|
Loading…
Reference in New Issue