Skip to content

Commit

Permalink
feat: Generate data sources
Browse files Browse the repository at this point in the history
  • Loading branch information
moduli committed Jul 12, 2024
1 parent aa7617d commit a792a3f
Show file tree
Hide file tree
Showing 40 changed files with 6,918 additions and 5 deletions.
211 changes: 211 additions & 0 deletions internal/provider/data_source_accounts.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 67 additions & 0 deletions internal/provider/data_source_accounts_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package provider

import (
"regexp"
"testing"

"github.com/hashicorp/boundary/testing/controller"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

var (
fooAccountDataMissingAuthMethodId = `
data "boundary_accounts" "foo" {}
`

fooAccountData = `
data "boundary_accounts" "foo" {
depends_on = [boundary_account.foo]
auth_method_id = boundary_auth_method.foo.id
}
`
)

func TestAccDataSourceAccounts(t *testing.T) {
tc := controller.NewTestController(t, tcConfig...)
defer tc.Shutdown()
url := tc.ApiAddrs()[0]

var provider *schema.Provider
resource.Test(t, resource.TestCase{
ProviderFactories: providerFactories(&provider),
Steps: []resource.TestStep{
{
Config: testConfig(url, fooAccountDataMissingAuthMethodId),
ExpectError: regexp.MustCompile("Invalid formatted identifier."),
},
{
Config: testConfig(url, fooOrg, fooAccount, fooAccountData),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet("data.boundary_accounts.foo", "auth_method_id"),
resource.TestCheckResourceAttr("data.boundary_accounts.foo", "items.#", "1"),
resource.TestCheckResourceAttr("data.boundary_accounts.foo", "items.0.%", "11"),
resource.TestCheckResourceAttrSet("data.boundary_accounts.foo", "items.0.auth_method_id"),
resource.TestCheckResourceAttr("data.boundary_accounts.foo", "items.0.authorized_actions.#", "6"),
resource.TestCheckResourceAttrSet("data.boundary_accounts.foo", "items.0.created_time"),
resource.TestCheckResourceAttr("data.boundary_accounts.foo", "items.0.description", "test account"),
resource.TestCheckResourceAttrSet("data.boundary_accounts.foo", "items.0.id"),
resource.TestCheckResourceAttr("data.boundary_accounts.foo", "items.0.managed_group_ids.#", "0"),
resource.TestCheckResourceAttr("data.boundary_accounts.foo", "items.0.name", "test"),
resource.TestCheckResourceAttr("data.boundary_accounts.foo", "items.0.scope.#", "1"),
resource.TestCheckResourceAttr("data.boundary_accounts.foo", "items.0.scope.0.%", "5"),
resource.TestCheckResourceAttr("data.boundary_accounts.foo", "items.0.scope.0.description", ""),
resource.TestCheckResourceAttrSet("data.boundary_accounts.foo", "items.0.scope.0.id"),
resource.TestCheckResourceAttr("data.boundary_accounts.foo", "items.0.scope.0.name", "org1"),
resource.TestCheckResourceAttr("data.boundary_accounts.foo", "items.0.scope.0.parent_scope_id", "global"),
resource.TestCheckResourceAttr("data.boundary_accounts.foo", "items.0.scope.0.type", "org"),
resource.TestCheckResourceAttr("data.boundary_accounts.foo", "items.0.type", "password"),
resource.TestCheckResourceAttrSet("data.boundary_accounts.foo", "items.0.updated_time"),
resource.TestCheckResourceAttr("data.boundary_accounts.foo", "items.0.version", "1"),
),
},
},
})
}
Loading

0 comments on commit a792a3f

Please sign in to comment.