Files
terraform-provider-threshold/internal/provider/data_source_group_test.go
T
Michael Li 2d920805d4 test: Update tests to run against boundary-enterprise (#834)
* chore: Update make testacc to use boundary dev

Use boundary dev instead of test controller in order to get an enterprise cluster

* test: Update tests to use boundary dev cluster

- Set up environment variables via loadTestConfig
- Update testConfigWithRecovery to use recovery key from config
- Update testCOnfigWithoutAMPWCredentials to use boundary dev's auth method

* test: Update tests to use their own orgs

This is to address some test failures due to conflicts when creating resources within the same org.

* test: Enable tests that require boundary-enterprise

* chore: Update workflow to use boundary enterprise
2026-09-10 15:00:05 -04:00

120 lines
3.8 KiB
Go

// Copyright IBM Corp. 2020, 2026
// SPDX-License-Identifier: MPL-2.0
package provider
import (
"fmt"
"testing"
"github.com/YakDriver/regexache"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/id"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/stretchr/testify/require"
)
const (
testGroupName = "test_group"
)
func groupReadGlobal(suffix string) string {
name := testGroupName + "-" + suffix
return fmt.Sprintf(`
resource "boundary_user" "user" {
description = "user"
scope_id = "global"
depends_on = [boundary_role.org1_admin]
}
resource "boundary_group" "group" {
name = "%s"
description = "test"
scope_id = "global"
member_ids = [boundary_user.user.id]
depends_on = [boundary_user.user]
}
data "boundary_group" "group" {
depends_on = [ boundary_group.group ]
name = "%s"
}`, name, name)
}
var groupReadOrg = fmt.Sprintf(`
resource "boundary_user" "user" {
description = "user"
scope_id = boundary_scope.org1.id
depends_on = [boundary_role.org1_admin]
}
resource "boundary_group" "group" {
name = "%s"
description = "test"
scope_id = boundary_scope.org1.id
member_ids = [boundary_user.user.id]
depends_on = [boundary_user.user]
}
data "boundary_group" "group" {
depends_on = [ boundary_group.group ]
name = "%s"
scope_id = boundary_scope.org1.id
}`, testGroupName, testGroupName)
func TestAccGroupReadGlobal(t *testing.T) {
cfg, err := loadTestConfig()
require.NoError(t, err)
url := cfg.BoundaryAddr
suffix := id.UniqueId()
var provider *schema.Provider
resource.Test(t, resource.TestCase{
ProviderFactories: providerFactories(&provider),
Steps: []resource.TestStep{
{
Config: testConfig(url, fooOrg(suffix), groupReadGlobal(suffix)),
Check: resource.ComposeTestCheckFunc(
testAccCheckGroupResourceExists(provider, "boundary_group.group"),
resource.TestCheckResourceAttrSet("data.boundary_group.group", IDKey),
resource.TestCheckResourceAttrSet("data.boundary_group.group", ScopeIdKey),
resource.TestMatchResourceAttr("data.boundary_group.group", NameKey, regexache.MustCompile(`^`+testGroupName)),
resource.TestCheckResourceAttrSet("data.boundary_group.group", DescriptionKey),
resource.TestCheckResourceAttrSet("data.boundary_group.group", fmt.Sprintf("%s.#", GroupMemberIdsKey)),
resource.TestCheckResourceAttrSet("data.boundary_group.group", "scope.0.id"),
resource.TestCheckResourceAttr("data.boundary_group.group", "scope.0.name", "global"),
resource.TestCheckResourceAttr("data.boundary_group.group", "scope.0.type", "global"),
),
},
},
})
}
func TestAccGroupReadOrg(t *testing.T) {
cfg, err := loadTestConfig()
require.NoError(t, err)
url := cfg.BoundaryAddr
suffix := id.UniqueId()
var provider *schema.Provider
resource.Test(t, resource.TestCase{
ProviderFactories: providerFactories(&provider),
Steps: []resource.TestStep{
{
Config: testConfig(url, fooOrg(suffix), groupReadOrg),
Check: resource.ComposeTestCheckFunc(
testAccCheckGroupResourceExists(provider, "boundary_group.group"),
resource.TestCheckResourceAttrSet("data.boundary_group.group", IDKey),
resource.TestCheckResourceAttrSet("data.boundary_group.group", ScopeIdKey),
resource.TestCheckResourceAttr("data.boundary_group.group", NameKey, testGroupName),
resource.TestCheckResourceAttrSet("data.boundary_group.group", DescriptionKey),
resource.TestCheckResourceAttrSet("data.boundary_group.group", fmt.Sprintf("%s.#", GroupMemberIdsKey)),
resource.TestCheckResourceAttrSet("data.boundary_group.group", "scope.0.id"),
resource.TestMatchResourceAttr("data.boundary_group.group", "scope.0.name", regexache.MustCompile(`^org1-`)),
resource.TestCheckResourceAttr("data.boundary_group.group", "scope.0.type", "org"),
),
},
},
})
}