Skip to content

Commit

Permalink
pause until scope resource is done
Browse files Browse the repository at this point in the history
  • Loading branch information
malnick committed Aug 26, 2020
1 parent 2935efa commit 54431ef
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 63 deletions.
2 changes: 1 addition & 1 deletion internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func New() terraform.ResourceProvider {
},
ResourcesMap: map[string]*schema.Resource{
"boundary_group": resourceGroup(),
"boundar_host": resourceHost(),
"boundary_host": resourceHost(),
"boundary_host_catalog": resourceHostCatalog(),
"boundary_project": resourceProject(),
"boundary_role": resourceRole(),
Expand Down
4 changes: 2 additions & 2 deletions internal/provider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ var (
tcUsername = "user"
tcPassword = "passpass"
tcPAUM = "paum_0000000000"
tcOrg = "o_0000000000"
tcOrg = "global" //"o_0000000000"
tcConfig = []controller.Option{
controller.WithDefaultOrgId(tcOrg),
// controller.WithDefaultOrgId(tcOrg),
controller.WithDefaultAuthMethodId(tcPAUM),
controller.WithDefaultLoginName(tcUsername),
controller.WithDefaultPassword(tcPassword),
Expand Down
68 changes: 8 additions & 60 deletions internal/provider/resource_host_catalog_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package provider

import (
"errors"
"fmt"
"net/http"
"strings"
"testing"

"github.com/hashicorp/boundary/api/hosts"
Expand All @@ -22,16 +20,18 @@ const (
var (
orgHostCatalog = fmt.Sprintf(`
resource "boundary_host_catalog" "foo" {
name = "foo"
description = "%s"
scope_id = boundary_project.project1.id
type = "Static"
scope_id = boundary_project.project1.id
type = "Static"
}`, fooHostCatalogDescription)

orgHostCatalogUpdate = fmt.Sprintf(`
resource "boundary_host_catalog" "foo" {
name = "foo"
description = "%s"
scope_id = boundary_project.project1.id
type = "Static"
scope_id = boundary_project.project1.id
type = "Static"
}`, fooHostCatalogDescriptionUpdate)
)

Expand Down Expand Up @@ -61,62 +61,10 @@ func TestAccHostCatalogCreate(t *testing.T) {
resource.TestCheckResourceAttr("boundary_host_catalog.foo", hostCatalogDescriptionKey, fooHostCatalogDescriptionUpdate),
),
},
{
// test destroy
Config: testConfig(url, firstProjectBar),
Check: resource.ComposeTestCheckFunc(
testAccCheckProjectResourceExists("boundary_project.project1"),
testAccCheckHostCatalogDestroyed("boundary_host_catalog.foo"),
),
},
},
})
}

// testAccCheckHostCatalogDestroyed checks the terraform state for the host
// catalog and returns an error if found.
//
// TODO(malnick) This method falls short of checking the Boundary API for
// the resource if the resource is not found in state. This is due to us not
// having the host catalog ID, but it doesn't guarantee that the resource was
// successfully removed.
//
// It does check Boundary if the resource is found in state to point out any
// misalignment between what is in state and the actual configuration.
func testAccCheckHostCatalogDestroyed(name string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[name]
if !ok {
// If it's not in state, it's destroyed in TF but not guaranteed to be destroyed
// in Boundary. Need to find a way to get the host catalog ID here so we can
// form a lookup to the WT API to check this.
return nil
}
errs := []string{}
errs = append(errs, fmt.Sprintf("Found host catalog resource in state: %s", name))

id := rs.Primary.ID
if id == "" {
return fmt.Errorf("No ID is set")
}

md := testProvider.Meta().(*metaData)
projID, ok := rs.Primary.Attributes["scope_id"]
if !ok {
return fmt.Errorf("scope_id is not set")
}
projClient := md.client.Clone()
projClient.SetScopeId(projID)
hcClient := hosts.NewHostCatalogsClient(projClient)

if _, apiErr, _ := hcClient.Read(md.ctx, id); apiErr == nil || apiErr.Status != http.StatusNotFound {
errs = append(errs, fmt.Sprintf("Host catalog not destroyed %q: %v", id, apiErr))
}

return errors.New(strings.Join(errs, ","))
}
}

func testAccCheckHostCatalogResourceExists(name string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[name]
Expand Down Expand Up @@ -166,8 +114,8 @@ func testAccCheckHostCatalogResourceDestroy(t *testing.T) resource.TestCheckFunc
hcClient := hosts.NewHostCatalogsClient(projClient)

_, apiErr, _ := hcClient.Read(md.ctx, id)
if apiErr == nil || apiErr.Status != http.StatusNotFound {
return fmt.Errorf("Didn't get a 404 when reading destroyed host catalog %q: %v", id, apiErr)
if apiErr == nil || apiErr.Status != http.StatusNotFound && apiErr.Status != http.StatusForbidden {
return fmt.Errorf("Didn't get a 404 or 403 when reading destroyed host catalog %q: %v", id, apiErr)
}

default:
Expand Down
3 changes: 3 additions & 0 deletions internal/provider/resource_host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var (
resource "boundary_host_catalog" "foo" {
name = "test"
description = "test catalog"
scope_id = boundary_project.foo.id
}
resource "boundary_host" "foo" {
Expand All @@ -36,6 +37,7 @@ resource "boundary_host" "foo" {
resource "boundary_host_catalog" "foo" {
name = "test"
description = "test catalog"
scope_id = boundary_project.foo.id
}
resource "boundary_host" "foo" {
Expand All @@ -50,6 +52,7 @@ resource "boundary_host" "foo" {
func TestAccHost(t *testing.T) {
tc := controller.NewTestController(t, tcConfig...)
defer tc.Shutdown()
// org := iam.TestOrg(t, tc.IamRepo())
url := tc.ApiAddrs()[0]

resource.Test(t, resource.TestCase{
Expand Down

0 comments on commit 54431ef

Please sign in to comment.