2026-05-11 20:53:55 -07:00
|
|
|
// Copyright IBM Corp. 2020, 2026
|
2023-12-12 16:36:37 -05:00
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
|
|
|
|
|
package provider
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"testing"
|
|
|
|
|
|
2026-09-10 15:00:05 -04:00
|
|
|
"github.com/YakDriver/regexache"
|
|
|
|
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/id"
|
2023-12-12 16:36:37 -05:00
|
|
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
|
|
|
|
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
2026-09-10 15:00:05 -04:00
|
|
|
"github.com/stretchr/testify/require"
|
2023-12-12 16:36:37 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
testAuthMethodName = "test_auth_method"
|
|
|
|
|
)
|
|
|
|
|
|
2026-09-10 15:00:05 -04:00
|
|
|
func authMethodReadGlobal(suffix string) string {
|
|
|
|
|
name := testAuthMethodName + "-" + suffix
|
|
|
|
|
return fmt.Sprintf(`
|
2023-12-12 16:36:37 -05:00
|
|
|
resource "boundary_auth_method" "auth_method" {
|
|
|
|
|
name = "%s"
|
|
|
|
|
description = "test"
|
|
|
|
|
scope_id = "global"
|
|
|
|
|
type = "password"
|
|
|
|
|
depends_on = [boundary_role.org1_admin]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data "boundary_auth_method" "auth_method" {
|
|
|
|
|
depends_on = [ boundary_auth_method.auth_method ]
|
|
|
|
|
name = "%s"
|
2026-09-10 15:00:05 -04:00
|
|
|
}`, name, name)
|
|
|
|
|
}
|
2023-12-12 16:36:37 -05:00
|
|
|
|
|
|
|
|
var authMethodReadOrg = fmt.Sprintf(`
|
|
|
|
|
resource "boundary_auth_method" "auth_method" {
|
|
|
|
|
name = "%s"
|
|
|
|
|
description = "test"
|
|
|
|
|
scope_id = boundary_scope.org1.id
|
|
|
|
|
type = "password"
|
|
|
|
|
depends_on = [boundary_role.org1_admin]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data "boundary_auth_method" "auth_method" {
|
|
|
|
|
depends_on = [ boundary_auth_method.auth_method ]
|
|
|
|
|
name = "%s"
|
|
|
|
|
scope_id = boundary_scope.org1.id
|
|
|
|
|
}`, testAuthMethodName, testAuthMethodName)
|
|
|
|
|
|
|
|
|
|
func TestAccAuthMethodReadGlobal(t *testing.T) {
|
2026-09-10 15:00:05 -04:00
|
|
|
cfg, err := loadTestConfig()
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
url := cfg.BoundaryAddr
|
|
|
|
|
suffix := id.UniqueId()
|
2023-12-12 16:36:37 -05:00
|
|
|
|
|
|
|
|
var provider *schema.Provider
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
|
ProviderFactories: providerFactories(&provider),
|
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
|
{
|
2026-09-10 15:00:05 -04:00
|
|
|
Config: testConfig(url, fooOrg(suffix), authMethodReadGlobal(suffix)),
|
2023-12-12 16:36:37 -05:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
|
resource.TestCheckResourceAttrSet("data.boundary_auth_method.auth_method", IDKey),
|
|
|
|
|
resource.TestCheckResourceAttrSet("data.boundary_auth_method.auth_method", ScopeIdKey),
|
2026-09-10 15:00:05 -04:00
|
|
|
resource.TestMatchResourceAttr("data.boundary_auth_method.auth_method", NameKey, regexache.MustCompile(`^`+testAuthMethodName)),
|
2023-12-12 16:36:37 -05:00
|
|
|
resource.TestCheckResourceAttr("data.boundary_auth_method.auth_method", TypeKey, "password"),
|
|
|
|
|
resource.TestCheckResourceAttrSet("data.boundary_auth_method.auth_method", DescriptionKey),
|
|
|
|
|
resource.TestCheckResourceAttrSet("data.boundary_auth_method.auth_method", "scope.0.id"),
|
|
|
|
|
resource.TestCheckResourceAttr("data.boundary_auth_method.auth_method", "scope.0.name", "global"),
|
|
|
|
|
resource.TestCheckResourceAttr("data.boundary_auth_method.auth_method", "scope.0.type", "global"),
|
|
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestAccAuthMethodReadOrg(t *testing.T) {
|
2026-09-10 15:00:05 -04:00
|
|
|
cfg, err := loadTestConfig()
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
url := cfg.BoundaryAddr
|
|
|
|
|
suffix := id.UniqueId()
|
2023-12-12 16:36:37 -05:00
|
|
|
|
|
|
|
|
var provider *schema.Provider
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
|
ProviderFactories: providerFactories(&provider),
|
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
|
{
|
2026-09-10 15:00:05 -04:00
|
|
|
Config: testConfig(url, fooOrg(suffix), authMethodReadOrg),
|
2023-12-12 16:36:37 -05:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
|
resource.TestCheckResourceAttrSet("data.boundary_auth_method.auth_method", IDKey),
|
|
|
|
|
resource.TestCheckResourceAttrSet("data.boundary_auth_method.auth_method", ScopeIdKey),
|
|
|
|
|
resource.TestCheckResourceAttr("data.boundary_auth_method.auth_method", NameKey, testAuthMethodName),
|
|
|
|
|
resource.TestCheckResourceAttr("data.boundary_auth_method.auth_method", TypeKey, "password"),
|
|
|
|
|
resource.TestCheckResourceAttrSet("data.boundary_auth_method.auth_method", DescriptionKey),
|
|
|
|
|
resource.TestCheckResourceAttrSet("data.boundary_auth_method.auth_method", "scope.0.id"),
|
2026-09-10 15:00:05 -04:00
|
|
|
resource.TestMatchResourceAttr("data.boundary_auth_method.auth_method", "scope.0.name", regexache.MustCompile(`^org1-`)),
|
2023-12-12 16:36:37 -05:00
|
|
|
resource.TestCheckResourceAttr("data.boundary_auth_method.auth_method", "scope.0.type", "org"),
|
|
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
}
|