Files
terraform-provider-threshold/internal/provider/data_source_scope_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

103 lines
3.2 KiB
Go

// Copyright IBM Corp. 2020, 2026
// SPDX-License-Identifier: MPL-2.0
package provider
import (
"fmt"
"testing"
"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 (
scopeDesc = "created to test the scope datasource"
)
func scopeCreateAndRead(suffix string) string {
orgName := "test org scope " + suffix
projectName := "test project scope " + suffix
return fmt.Sprintf(`
resource "boundary_scope" "global" {
global_scope = true
name = "global"
description = "Global Scope"
scope_id = "global"
}
resource "boundary_scope" "org" {
scope_id = boundary_scope.global.id
name = "%s"
description = "%s"
}
resource "boundary_scope" "project" {
depends_on = [boundary_role.org_admin]
scope_id = boundary_scope.org.id
name = "%s"
description = "%s"
}
resource "boundary_role" "org_admin" {
scope_id = "global"
grant_scope_ids = [boundary_scope.org.id]
grant_strings = ["ids=*;type=*;actions=*"]
principal_ids = ["u_auth"]
}
data "boundary_scope" "org" {
depends_on = [boundary_scope.org]
scope_id = "global"
name = "%s"
}
data "boundary_scope" "project" {
depends_on = [boundary_scope.project]
scope_id = data.boundary_scope.org.id
name = "%s"
}`, orgName, scopeDesc, projectName, scopeDesc, orgName, projectName)
}
func TestAccScopeRead(t *testing.T) {
cfg, err := loadTestConfig()
require.NoError(t, err)
url := cfg.BoundaryAddr
suffix := id.UniqueId()
orgName := "test org scope " + suffix
projectName := "test project scope " + suffix
var provider *schema.Provider
resource.Test(t, resource.TestCase{
ProviderFactories: providerFactories(&provider),
CheckDestroy: testAccCheckScopeResourceDestroy(t, provider),
Steps: []resource.TestStep{
{
// create and read
Config: testConfig(url, scopeCreateAndRead(suffix)),
Check: resource.ComposeTestCheckFunc(
testAccCheckScopeResourceExists(provider, "boundary_scope.org"),
resource.TestCheckResourceAttr("boundary_scope.org", "description", scopeDesc),
resource.TestCheckResourceAttr("boundary_scope.org", "name", orgName),
testAccCheckScopeResourceExists(provider, "boundary_scope.project"),
resource.TestCheckResourceAttr("boundary_scope.project", "description", scopeDesc),
resource.TestCheckResourceAttr("boundary_scope.project", "name", projectName),
// Check attributes on the org datasource
resource.TestCheckResourceAttrSet("data.boundary_scope.org", "scope_id"),
resource.TestCheckResourceAttrSet("data.boundary_scope.org", "id"),
resource.TestCheckResourceAttr("data.boundary_scope.org", "name", orgName),
resource.TestCheckResourceAttr("data.boundary_scope.org", "description", scopeDesc),
// Check attributes on the project datasource
resource.TestCheckResourceAttrSet("data.boundary_scope.project", "scope_id"),
resource.TestCheckResourceAttrSet("data.boundary_scope.project", "id"),
resource.TestCheckResourceAttr("data.boundary_scope.project", "name", projectName),
resource.TestCheckResourceAttr("data.boundary_scope.project", "description", scopeDesc),
),
},
},
})
}