Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add host and organization resources #23

Merged
merged 9 commits into from
Aug 28, 2020
19 changes: 11 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,33 @@ module github.com/hashicorp/terraform-provider-boundary
go 1.13

require (
cloud.google.com/go v0.63.0 // indirect
cloud.google.com/go v0.64.0 // indirect
github.com/agext/levenshtein v1.2.3 // indirect
github.com/alecthomas/assert v0.0.0-20170929043011-405dbfeb8e38 // indirect
github.com/alecthomas/colour v0.1.0 // indirect
github.com/alecthomas/repr v0.0.0-20200325044227-4184120f674c // indirect
github.com/apparentlymart/go-cidr v1.1.0 // indirect
github.com/aws/aws-sdk-go v1.34.4 // indirect
github.com/hashicorp/boundary v0.0.0-20200813213948-bb6b18951378
github.com/aws/aws-sdk-go v1.34.9 // indirect
github.com/hashicorp/boundary v0.0.0-20200821205347-a1490228b8ef
github.com/hashicorp/go-getter v1.4.1 // indirect
github.com/hashicorp/go-plugin v1.3.0 // indirect
github.com/hashicorp/go-retryablehttp v0.6.7 // indirect
github.com/hashicorp/go-version v1.2.1 // indirect
github.com/hashicorp/hcl/v2 v2.6.0 // indirect
github.com/hashicorp/terraform-plugin-sdk v1.15.0
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 // indirect
github.com/hashicorp/vault/api v1.0.5-0.20200717191844-f687267c8086 // indirect
github.com/hashicorp/yamux v0.0.0-20200609203250-aecfd211c9ce // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/sergi/go-diff v1.1.0 // indirect
github.com/spf13/afero v1.3.4 // indirect
github.com/stretchr/testify v1.6.1
github.com/ulikunitz/xz v0.5.7 // indirect
github.com/ulikunitz/xz v0.5.8 // indirect
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
github.com/zclconf/go-cty v1.5.1 // indirect
github.com/zclconf/go-cty-yaml v1.0.2 // indirect
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a // indirect
golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc // indirect
golang.org/x/sys v0.0.0-20200812155832-6a926be9bd1d // indirect
golang.org/x/tools v0.0.0-20200813203630-136574234359 // indirect
google.golang.org/genproto v0.0.0-20200813001606-1ccf2a5ae4fd // indirect
golang.org/x/sys v0.0.0-20200821140526-fda516888d29 // indirect
golang.org/x/tools v0.0.0-20200821200730-1e23e48ab93b // indirect
)
53 changes: 53 additions & 0 deletions go.sum

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ func New() terraform.ResourceProvider {
},
ResourcesMap: map[string]*schema.Resource{
"boundary_group": resourceGroup(),
"boundary_host": resourceHost(),
"boundary_host_catalog": resourceHostCatalog(),
"boundary_organization": resourceOrganization(),
"boundary_project": resourceProject(),
"boundary_role": resourceRole(),
"boundary_user": resourceUser(),
Expand Down
8 changes: 1 addition & 7 deletions internal/provider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,12 @@ import (
var testProvider *schema.Provider
var testProviders map[string]terraform.ResourceProvider

var fooProject = `
resource "boundary_project" "foo" {
name = "test"
}`

var (
tcUsername = "user"
tcPassword = "passpass"
tcPAUM = "paum_0000000000"
tcOrg = "o_0000000000"
tcOrg = "global"
tcConfig = []controller.Option{
controller.WithDefaultOrgId(tcOrg),
controller.WithDefaultAuthMethodId(tcPAUM),
controller.WithDefaultLoginName(tcUsername),
controller.WithDefaultPassword(tcPassword),
Expand Down
32 changes: 19 additions & 13 deletions internal/provider/resource_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,45 @@ const (
var (
orgGroup = fmt.Sprintf(`
resource "boundary_group" "foo" {
name = "test"
name = "test"
description = "%s"
scope_id = boundary_organization.foo.id
}`, fooGroupDescription)

orgGroupUpdate = fmt.Sprintf(`
resource "boundary_group" "foo" {
name = "test"
name = "test"
description = "%s"
scope_id = boundary_organization.foo.id
}`, fooGroupDescriptionUpdate)

orgGroupWithMembers = `
resource "boundary_user" "foo" {
description = "foo"
scope_id = boundary_organization.foo.id
}

resource "boundary_group" "with_members" {
description = "with members"
member_ids = [boundary_user.foo.id]
scope_id = boundary_organization.foo.id
}`

orgGroupWithMembersUpdate = `
resource "boundary_user" "foo" {
description = "foo"
scope_id = boundary_organization.foo.id
}

resource "boundary_user" "bar" {
description = "bar"
scope_id = boundary_organization.foo.id
}

resource "boundary_group" "with_members" {
description = "with members"
member_ids = [boundary_user.foo.id, boundary_user.bar.id]
scope_id = boundary_organization.foo.id
}`

orgToProjectGroupUpdate = fmt.Sprintf(`
Expand Down Expand Up @@ -97,26 +104,24 @@ func TestAccGroup(t *testing.T) {
Steps: []resource.TestStep{
{
// test create
Config: testConfig(url, orgGroup),
Config: testConfig(url, fooOrg, orgGroup),
Check: resource.ComposeTestCheckFunc(
testAccCheckGroupResourceExists("boundary_group.foo"),
resource.TestCheckResourceAttr("boundary_group.foo", groupDescriptionKey, fooGroupDescription),
resource.TestCheckResourceAttr("boundary_group.foo", groupNameKey, "test"),
resource.TestCheckResourceAttr("boundary_group.foo", groupScopeIDKey, tcOrg),
),
},
{
// test update
Config: testConfig(url, orgGroupUpdate),
Config: testConfig(url, fooOrg, orgGroupUpdate),
Check: resource.ComposeTestCheckFunc(
testAccCheckGroupResourceExists("boundary_group.foo"),
resource.TestCheckResourceAttr("boundary_group.foo", groupDescriptionKey, fooGroupDescriptionUpdate),
resource.TestCheckResourceAttr("boundary_group.foo", groupScopeIDKey, tcOrg),
),
},
{
// test update to project scope
Config: testConfig(url, fooProject, orgToProjectGroupUpdate),
Config: testConfig(url, fooOrg, fooProject, orgToProjectGroupUpdate),
Check: resource.ComposeTestCheckFunc(
testAccCheckGroupResourceExists("boundary_group.foo"),
resource.TestCheckResourceAttr("boundary_group.foo", groupDescriptionKey, fooGroupDescriptionUpdate),
Expand All @@ -125,7 +130,7 @@ func TestAccGroup(t *testing.T) {
},
{
// test create
Config: testConfig(url, fooProject, projGroup),
Config: testConfig(url, fooOrg, fooProject, projGroup),
Check: resource.ComposeTestCheckFunc(
testAccCheckGroupResourceExists("boundary_group.foo"),
resource.TestCheckResourceAttr("boundary_group.foo", groupDescriptionKey, fooGroupDescription),
Expand All @@ -135,7 +140,7 @@ func TestAccGroup(t *testing.T) {
},
{
// test update
Config: testConfig(url, fooProject, projGroupUpdate),
Config: testConfig(url, fooOrg, fooProject, projGroupUpdate),
Check: resource.ComposeTestCheckFunc(
testAccCheckGroupResourceExists("boundary_group.foo"),
resource.TestCheckResourceAttr("boundary_group.foo", groupDescriptionKey, fooGroupDescriptionUpdate),
Expand All @@ -144,7 +149,7 @@ func TestAccGroup(t *testing.T) {
},
{
// test update to org scope
Config: testConfig(url, fooProject, projToOrgGroupUpdate),
Config: testConfig(url, fooOrg, fooProject, projToOrgGroupUpdate),
Check: resource.ComposeTestCheckFunc(
testAccCheckGroupResourceExists("boundary_group.foo"),
resource.TestCheckResourceAttr("boundary_group.foo", groupDescriptionKey, fooGroupDescriptionUpdate),
Expand All @@ -167,7 +172,7 @@ func TestAccGroupWithMembers(t *testing.T) {
Steps: []resource.TestStep{
{
// test create
Config: testConfig(url, orgGroupWithMembers),
Config: testConfig(url, fooOrg, orgGroupWithMembers),
Check: resource.ComposeTestCheckFunc(
testAccCheckGroupResourceExists("boundary_group.with_members"),
testAccCheckGroupResourceExists("boundary_user.foo"),
Expand All @@ -177,7 +182,7 @@ func TestAccGroupWithMembers(t *testing.T) {
},
{
// test update
Config: testConfig(url, orgGroupWithMembersUpdate),
Config: testConfig(url, fooOrg, orgGroupWithMembersUpdate),
Check: resource.ComposeTestCheckFunc(
testAccCheckGroupResourceExists("boundary_group.with_members"),
testAccCheckGroupResourceExists("boundary_user.foo"),
Expand Down Expand Up @@ -318,7 +323,6 @@ func testAccCheckGroupResourceExists(name string) resource.TestCheckFunc {

func testAccCheckGroupResourceDestroy(t *testing.T) resource.TestCheckFunc {
return func(s *terraform.State) error {
fmt.Printf("test check group resource destroyed\n")
if testProvider.Meta() == nil {
t.Fatal("got nil provider metadata")
}
Expand All @@ -327,6 +331,8 @@ func testAccCheckGroupResourceDestroy(t *testing.T) resource.TestCheckFunc {

for _, rs := range s.RootModule().Resources {
switch rs.Type {
case "boundary_organization":
continue
case "boundary_project":
continue
case "boundary_user":
Expand Down