Skip to content

Commit

Permalink
Adding support for policy_name and policy_group to a chef_node resource
Browse files Browse the repository at this point in the history
Closes hashicorp#6.
  • Loading branch information
hynd committed Mar 21, 2018
1 parent 926c693 commit 33ca9b2
Show file tree
Hide file tree
Showing 15 changed files with 191 additions and 102 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ If you wish to work on the provider, you'll first need [Go](http://www.golang.or
To compile the provider, run `make build`. This will build the provider and put the provider binary in the `$GOPATH/bin` directory.

```sh
$ make bin
$ make build
...
$ $GOPATH/bin/terraform-provider-chef
...
Expand Down
12 changes: 12 additions & 0 deletions chef/resource_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ func resourceChefNode() *schema.Resource {
StateFunc: runListEntryStateFunc,
},
},
"policy_name": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
"policy_group": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
},
}
}
Expand Down Expand Up @@ -116,6 +124,8 @@ func ReadNode(d *schema.ResourceData, meta interface{}) error {

d.Set("name", node.Name)
d.Set("environment_name", node.Environment)
d.Set("policy_name", node.PolicyName)
d.Set("policy_group", node.PolicyGroup)

automaticAttrJson, err := json.Marshal(node.AutomaticAttributes)
if err != nil {
Expand Down Expand Up @@ -170,6 +180,8 @@ func nodeFromResourceData(d *schema.ResourceData) (*chefc.Node, error) {
Environment: d.Get("environment_name").(string),
ChefType: "node",
JsonClass: "Chef::Node",
PolicyName: d.Get("policy_name").(string),
PolicyGroup: d.Get("policy_group").(string),
}

var err error
Expand Down
40 changes: 40 additions & 0 deletions chef/resource_node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,38 @@ func TestAccNode_basic(t *testing.T) {
})
}

func TestAccNode_policyfile(t *testing.T) {
var node chefc.Node

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccNodeCheckDestroy(&node),
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccNodeConfig_policyfile,
Check: resource.ComposeTestCheckFunc(
testAccNodeCheckExists("chef_node.testpolicyfile", &node),
func(s *terraform.State) error {

if expected := "terraform-acc-test-policyfile"; node.Name != expected {
return fmt.Errorf("wrong name; expected %v, got %v", expected, node.Name)
}
if expected := "test_policyname"; node.PolicyName != expected {
return fmt.Errorf("wrong policy_name; expected %v, got %v", expected, node.PolicyName)
}
if expected := "test_policygroup"; node.PolicyGroup != expected {
return fmt.Errorf("wrong policy_group; expected %v, got %v", expected, node.PolicyGroup)
}

return nil
},
),
},
},
})
}

func testAccNodeCheckExists(rn string, node *chefc.Node) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[rn]
Expand Down Expand Up @@ -137,3 +169,11 @@ EOT
run_list = ["terraform@1.0.0", "recipe[consul]", "role[foo]"]
}
`

const testAccNodeConfig_policyfile = `
resource "chef_node" "testpolicyfile" {
name = "terraform-acc-test-policyfile"
policy_name = "test_policyname"
policy_group = "test_policygroup"
}
`
82 changes: 41 additions & 41 deletions vendor/github.com/go-chef/chef/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 36 additions & 5 deletions vendor/github.com/go-chef/chef/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions vendor/github.com/go-chef/chef/cookbook.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions vendor/github.com/go-chef/chef/environment.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions vendor/github.com/go-chef/chef/http.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 33ca9b2

Please sign in to comment.