Skip to content

Commit

Permalink
Clean up and add docs
Browse files Browse the repository at this point in the history
Signed-off-by: Brian Dwyer <[email protected]>
  • Loading branch information
bdwyertech committed Apr 30, 2020
1 parent 4701ed2 commit 2f4067c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
34 changes: 16 additions & 18 deletions builtin/provisioners/chef/resource_provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,15 @@ type provisioner struct {
PolicyName string
HTTPProxy string
HTTPSProxy string
MaxRetries int
NamedRunList string
NOProxy []string
NodeName string
OhaiHints []string
OSType string
RecreateClient bool
PreventSudo bool
RetryOnExitCode []int
RunList []string
SecretKey string
ServerURL string
Expand All @@ -115,9 +117,7 @@ type provisioner struct {
UserKey string
Vaults map[string][]string
Version string
RetryOnExitCode []int
WaitForRetry int
MaxRetries int

cleanupUserKeyCmd string
createConfigFiles provisionFn
Expand Down Expand Up @@ -201,6 +201,11 @@ func Provisioner() terraform.ResourceProvisioner {
Type: schema.TypeString,
Optional: true,
},
"max_retries": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
Default: 1,
},
"no_proxy": &schema.Schema{
Type: schema.TypeList,
Elem: &schema.Schema{Type: schema.TypeString},
Expand All @@ -219,14 +224,19 @@ func Provisioner() terraform.ResourceProvisioner {
Type: schema.TypeString,
Optional: true,
},
"recreate_client": &schema.Schema{
"prevent_sudo": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
},
"prevent_sudo": &schema.Schema{
"recreate_client": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
},
"retry_on_exit_code": &schema.Schema{
Type: schema.TypeList,
Elem: &schema.Schema{Type: schema.TypeInt},
Optional: true,
},
"run_list": &schema.Schema{
Type: schema.TypeList,
Elem: &schema.Schema{Type: schema.TypeString},
Expand Down Expand Up @@ -256,18 +266,6 @@ func Provisioner() terraform.ResourceProvisioner {
Type: schema.TypeString,
Optional: true,
},
// Same defaults as Test-Kitchen
// https://github.com/test-kitchen/test-kitchen/blob/e5998e0dd1aa42601c55659da78f9b112ff9f8ee/lib/kitchen/provisioner/base.rb#L36-38
"retry_on_exit_code": &schema.Schema{
Type: schema.TypeList,
Elem: &schema.Schema{Type: schema.TypeInt},
Optional: true,
},
"max_retries": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
Default: 1,
},
"wait_for_retry": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
Expand Down Expand Up @@ -790,12 +788,14 @@ func decodeConfig(d *schema.ResourceData) (*provisioner, error) {
HTTPProxy: d.Get("http_proxy").(string),
HTTPSProxy: d.Get("https_proxy").(string),
NOProxy: getStringList(d.Get("no_proxy")),
MaxRetries: d.Get("max_retries").(int),
NamedRunList: d.Get("named_run_list").(string),
NodeName: d.Get("node_name").(string),
OhaiHints: getStringList(d.Get("ohai_hints")),
OSType: d.Get("os_type").(string),
RecreateClient: d.Get("recreate_client").(bool),
PreventSudo: d.Get("prevent_sudo").(bool),
RetryOnExitCode: getIntList(d.Get("retry_on_exit_code")),
RunList: getStringList(d.Get("run_list")),
SecretKey: d.Get("secret_key").(string),
ServerURL: d.Get("server_url").(string),
Expand All @@ -805,9 +805,7 @@ func decodeConfig(d *schema.ResourceData) (*provisioner, error) {
UserName: d.Get("user_name").(string),
UserKey: d.Get("user_key").(string),
Version: d.Get("version").(string),
RetryOnExitCode: getIntList(d.Get("retry_on_exit_code")),
WaitForRetry: d.Get("wait_for_retry").(int),
MaxRetries: d.Get("max_retries").(int),
}

// Make sure the supplied URL has a trailing slash
Expand Down
10 changes: 9 additions & 1 deletion website/docs/provisioners/chef.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ resource "aws_instance" "web" {
recreate_client = true
user_name = "bork"
user_key = "${file("../bork.pem")}"
version = "12.4.1"
version = "15.10.13"
# If you have a self signed cert on your chef server change this to :verify_none
ssl_verify_mode = ":verify_peer"
# Gracefully handle Chef upgrades, reboots, etc.
retry_on_exit_code = [35, 213]
}
}
```
Expand Down Expand Up @@ -109,6 +111,8 @@ The following arguments are supported:

* `https_proxy (string)` - (Optional) The proxy server for Chef Client HTTPS connections.

* `max_retries (integer)` - (Optional) The number of times to retry the provisioning process after receiving an exit code in the `retry_on_error` list. Defaults to `1`

* `named_run_list (string)` - (Optional) The name of an alternate run-list to invoke during the
initial Chef Client run. The run-list must already exist in the Policyfile that defines
`policy_name`. Only applies when `use_policyfile` is `true`.
Expand All @@ -131,6 +135,8 @@ The following arguments are supported:
* `recreate_client (boolean)` - (Optional) If `true`, first delete any existing Chef Node and
Client before registering the new Chef Client.

* `retry_on_error (list of integers)` - (Optional) The error codes upon which Terraform should gracefully retry the provisioning process. Intended for use with [Chef RFC062 codes.](https://github.com/chef-boneyard/chef-rfc/blob/69a19f632cceffe965bafaad6765e3376068fd5b/rfc062-exit-status.md)

* `run_list (array)` - (Optional) A list with recipes that will be invoked during the initial
Chef Client run. The run-list will also be saved to the Chef Server after a successful
initial run. Required if `use_policyfile` is `false`; ignored when `use_policyfile` is `true`
Expand Down Expand Up @@ -169,3 +175,5 @@ The following arguments are supported:

* `version (string)` - (Optional) The Chef Client version to install on the remote machine.
If not set, the latest available version will be installed.

* `wait_for_retry (integer)` - (Optional) - Amount of time in seconds to wait before retrying the provisionining process after receiving an exit code in the `retry_on_error` list. Defaults to `30`.

0 comments on commit 2f4067c

Please sign in to comment.