Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/resources/account.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,10 @@ resource "boundary_account" "jeff" {
- **name** (String, Optional) The account name. Defaults to the resource name.
- **password** (String, Optional) The account password.

## Import

Import is supported using the following syntax:

```shell
terraform import boundary_account.foo <my-id>
```
6 changes: 6 additions & 0 deletions docs/resources/auth_method.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,10 @@ resource "boundary_auth_method" "password" {
- **min_password_length** (Number, Optional) The minimum password length.
- **name** (String, Optional) The auth method name. Defaults to the resource name.

## Import

Import is supported using the following syntax:

```shell
terraform import boundary_auth_method.foo <my-id>
```
8 changes: 8 additions & 0 deletions docs/resources/group.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,11 @@ resource "boundary_group" "example" {
- **id** (String, Optional) The ID of this resource.
- **member_ids** (Set of String, Optional) Resource IDs for group members, these are most likely boundary users.
- **name** (String, Optional) The group name. Defaults to the resource name.

## Import

Import is supported using the following syntax:

```shell
terraform import boundary_group.foo <my-id>
```
6 changes: 6 additions & 0 deletions docs/resources/host.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,10 @@ resource "boundary_host" "example" {
- **id** (String, Optional) The ID of this resource.
- **name** (String, Optional) The host name. Defaults to the resource name.

## Import

Import is supported using the following syntax:

```shell
terraform import boundary_host.foo <my-id>
```
6 changes: 6 additions & 0 deletions docs/resources/host_catalog.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,10 @@ resource "boundary_host_catalog" "example" {
- **id** (String, Optional) The ID of this resource.
- **name** (String, Optional) The host catalog name. Defaults to the resource name.

## Import

Import is supported using the following syntax:

```shell
terraform import boundary_host_catalog.foo <my-id>
```
6 changes: 6 additions & 0 deletions docs/resources/host_set.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,10 @@ resource "boundary_host_set" "web" {
- **id** (String, Optional) The ID of this resource.
- **name** (String, Optional) The hostset name. Defaults to the resource name.

## Import

Import is supported using the following syntax:

```shell
terraform import boundary_host_set.foo <my-id>
```
8 changes: 8 additions & 0 deletions docs/resources/role.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,11 @@ resource "boundary_role" "readonly" {
- **id** (String, Optional) The ID of this resource.
- **name** (String, Optional) The role name. Defaults to the resource name.
- **principal_ids** (Set of String, Optional) A list of principal (user or group) IDs to add as principals on the role.

## Import

Import is supported using the following syntax:

```shell
terraform import boundary_role.foo <my-id>
```
8 changes: 8 additions & 0 deletions docs/resources/scope.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,11 @@ resource "boundary_role" "org_admin" {
- **global_scope** (Boolean, Optional) Indicates that the scope containing this value is the global scope, which triggers some specialized behavior to allow it to be imported and managed.
- **id** (String, Optional) The ID of this resource.
- **name** (String, Optional) The scope name. Defaults to the resource name.

## Import

Import is supported using the following syntax:

```shell
terraform import boundary_scope.foo <my-id>
```
6 changes: 6 additions & 0 deletions docs/resources/target.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,10 @@ resource "boundary_target" "foo" {
- **session_connection_limit** (Number, Optional)
- **session_max_seconds** (Number, Optional)

## Import

Import is supported using the following syntax:

```shell
terraform import boundary_target.foo <my-id>
```
6 changes: 6 additions & 0 deletions docs/resources/user.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,10 @@ resource "boundary_user" "jeff" {
- **id** (String, Optional) The ID of this resource.
- **name** (String, Optional) The username. Defaults to the resource name.

## Import

Import is supported using the following syntax:

```shell
terraform import boundary_user.foo <my-id>
```
1 change: 1 addition & 0 deletions examples/resources/boundary_account/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform import boundary_account.foo <my-id>
1 change: 1 addition & 0 deletions examples/resources/boundary_auth_method/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform import boundary_auth_method.foo <my-id>
1 change: 1 addition & 0 deletions examples/resources/boundary_group/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform import boundary_group.foo <my-id>
1 change: 1 addition & 0 deletions examples/resources/boundary_host/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform import boundary_host.foo <my-id>
1 change: 1 addition & 0 deletions examples/resources/boundary_host_catalog/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform import boundary_host_catalog.foo <my-id>
1 change: 1 addition & 0 deletions examples/resources/boundary_host_set/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform import boundary_host_set.foo <my-id>
1 change: 1 addition & 0 deletions examples/resources/boundary_role/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform import boundary_role.foo <my-id>
1 change: 1 addition & 0 deletions examples/resources/boundary_scope/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform import boundary_scope.foo <my-id>
1 change: 1 addition & 0 deletions examples/resources/boundary_target/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform import boundary_target.foo <my-id>
1 change: 1 addition & 0 deletions examples/resources/boundary_user/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform import boundary_user.foo <my-id>
27 changes: 23 additions & 4 deletions internal/provider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/hashicorp/boundary/testing/controller"
wrapping "github.com/hashicorp/go-kms-wrapping"
"github.com/hashicorp/go-kms-wrapping/wrappers/aead"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

Expand All @@ -25,10 +26,14 @@ var (
tcRecoveryKey = "7xtkEoS5EXPbgynwd+dDLHopaCqK8cq0Rpep4eooaTs="
)

var providerFactories = map[string]func() (*schema.Provider, error){
"boundary": func() (*schema.Provider, error) {
return New(), nil
},
func providerFactories(p **schema.Provider) map[string]func() (*schema.Provider, error) {
// TODO: eventually rework this to real factories...
*p = New()
return map[string]func() (*schema.Provider, error){
"boundary": func() (*schema.Provider, error) {
return *p, nil
},
}
}

func testWrapper(t *testing.T, key string) wrapping.Wrapper {
Expand Down Expand Up @@ -113,6 +118,20 @@ provider "boundary" {
return strings.Join(c, "\n")
}

func importStep(name string, ignore ...string) resource.TestStep {
step := resource.TestStep{
ResourceName: name,
ImportState: true,
ImportStateVerify: true,
}

if len(ignore) > 0 {
step.ImportStateVerifyIgnore = ignore
}

return step
}

func TestProvider(t *testing.T) {
if err := New().InternalValidate(); err != nil {
t.Fatalf("err: %s", err)
Expand Down
4 changes: 4 additions & 0 deletions internal/provider/resource_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ func resourceAccount() *schema.Resource {
ReadContext: resourceAccountRead,
UpdateContext: resourceAccountUpdate,
DeleteContext: resourceAccountDelete,
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},

Schema: map[string]*schema.Schema{
NameKey: {
Description: "The account name. Defaults to the resource name.",
Expand Down
17 changes: 11 additions & 6 deletions internal/provider/resource_account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/hashicorp/boundary/api/accounts"
"github.com/hashicorp/boundary/testing/controller"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)

Expand Down Expand Up @@ -61,9 +62,11 @@ func TestAccAccount(t *testing.T) {
defer tc.Shutdown()
url := tc.ApiAddrs()[0]

var provider *schema.Provider

resource.Test(t, resource.TestCase{
ProviderFactories: providerFactories,
CheckDestroy: testAccCheckAccountResourceDestroy(t),
ProviderFactories: providerFactories(&provider),
CheckDestroy: testAccCheckAccountResourceDestroy(t, provider),
Steps: []resource.TestStep{
{
//create
Expand All @@ -74,9 +77,10 @@ func TestAccAccount(t *testing.T) {
resource.TestCheckResourceAttr("boundary_account.foo", "type", "password"),
resource.TestCheckResourceAttr("boundary_account.foo", "login_name", "foo"),
resource.TestCheckResourceAttr("boundary_account.foo", "password", "foofoofoo"),
testAccCheckAccountResourceExists("boundary_account.foo"),
testAccCheckAccountResourceExists(provider, "boundary_account.foo"),
),
},
importStep("boundary_account.foo", "password"),
{
// update
Config: testConfig(url, fooOrg, fooAccountUpdate),
Expand All @@ -86,14 +90,15 @@ func TestAccAccount(t *testing.T) {
resource.TestCheckResourceAttr("boundary_account.foo", "type", "password"),
resource.TestCheckResourceAttr("boundary_account.foo", "login_name", "foo"),
resource.TestCheckResourceAttr("boundary_account.foo", "password", "foofoofoo"),
testAccCheckAccountResourceExists("boundary_account.foo"),
testAccCheckAccountResourceExists(provider, "boundary_account.foo"),
),
},
importStep("boundary_account.foo", "password"),
},
})
}

func testAccCheckAccountResourceExists(name string) resource.TestCheckFunc {
func testAccCheckAccountResourceExists(testProvider *schema.Provider, name string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[name]
if !ok {
Expand All @@ -117,7 +122,7 @@ func testAccCheckAccountResourceExists(name string) resource.TestCheckFunc {
}
}

func testAccCheckAccountResourceDestroy(t *testing.T) resource.TestCheckFunc {
func testAccCheckAccountResourceDestroy(t *testing.T, testProvider *schema.Provider) resource.TestCheckFunc {
return func(s *terraform.State) error {
if testProvider.Meta() == nil {
t.Fatal("got nil provider metadata")
Expand Down
4 changes: 4 additions & 0 deletions internal/provider/resource_auth_method.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ func resourceAuthMethod() *schema.Resource {
ReadContext: resourceAuthMethodRead,
UpdateContext: resourceAuthMethodUpdate,
DeleteContext: resourceAuthMethodDelete,
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},

Schema: map[string]*schema.Schema{
NameKey: {
Description: "The auth method name. Defaults to the resource name.",
Expand Down
16 changes: 10 additions & 6 deletions internal/provider/resource_auth_method_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/hashicorp/boundary/api/authmethods"
"github.com/hashicorp/boundary/testing/controller"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)

Expand Down Expand Up @@ -43,9 +44,10 @@ func TestAccAuthMethod(t *testing.T) {
defer tc.Shutdown()
url := tc.ApiAddrs()[0]

var provider *schema.Provider
resource.Test(t, resource.TestCase{
ProviderFactories: providerFactories,
CheckDestroy: testAccCheckAuthMethodResourceDestroy(t),
ProviderFactories: providerFactories(&provider),
CheckDestroy: testAccCheckAuthMethodResourceDestroy(t, provider),
Steps: []resource.TestStep{
{
//create
Expand All @@ -54,24 +56,26 @@ func TestAccAuthMethod(t *testing.T) {
resource.TestCheckResourceAttr("boundary_auth_method.foo", "description", fooAuthMethodDesc),
resource.TestCheckResourceAttr("boundary_auth_method.foo", "name", "test"),
resource.TestCheckResourceAttr("boundary_auth_method.foo", "type", "password"),
testAccCheckAuthMethodResourceExists("boundary_auth_method.foo"),
testAccCheckAuthMethodResourceExists(provider, "boundary_auth_method.foo"),
),
},
importStep("boundary_auth_method.foo"),
{
// update
Config: testConfig(url, fooOrg, fooAuthMethodUpdate),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("boundary_auth_method.foo", "description", fooAuthMethodDescUpdate),
resource.TestCheckResourceAttr("boundary_auth_method.foo", "name", "test"),
resource.TestCheckResourceAttr("boundary_auth_method.foo", "type", "password"),
testAccCheckAuthMethodResourceExists("boundary_auth_method.foo"),
testAccCheckAuthMethodResourceExists(provider, "boundary_auth_method.foo"),
),
},
importStep("boundary_auth_method.foo"),
},
})
}

func testAccCheckAuthMethodResourceExists(name string) resource.TestCheckFunc {
func testAccCheckAuthMethodResourceExists(testProvider *schema.Provider, name string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[name]
if !ok {
Expand All @@ -95,7 +99,7 @@ func testAccCheckAuthMethodResourceExists(name string) resource.TestCheckFunc {
}
}

func testAccCheckAuthMethodResourceDestroy(t *testing.T) resource.TestCheckFunc {
func testAccCheckAuthMethodResourceDestroy(t *testing.T, testProvider *schema.Provider) resource.TestCheckFunc {
return func(s *terraform.State) error {
if testProvider.Meta() == nil {
t.Fatal("got nil provider metadata")
Expand Down
4 changes: 4 additions & 0 deletions internal/provider/resource_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ func resourceGroup() *schema.Resource {
ReadContext: resourceGroupRead,
UpdateContext: resourceGroupUpdate,
DeleteContext: resourceGroupDelete,
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},

Schema: map[string]*schema.Schema{
NameKey: {
Description: "The group name. Defaults to the resource name.",
Expand Down
Loading