mirror of
https://github.com/ysoftdevs/terraform-provider-bitbucketserver.git
synced 2026-03-26 19:31:07 +01:00
Merge pull request #11 from Kamahl19/data_bitbucketserver_user
Implement data source bitbucketserver_user
This commit is contained in:
35
bitbucket/data_user.go
Normal file
35
bitbucket/data_user.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package bitbucket
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
)
|
||||
|
||||
func dataSourceUser() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
Read: dataSourceUserRead,
|
||||
|
||||
Schema: map[string]*schema.Schema{
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
"email_address": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"display_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"user_id": {
|
||||
Type: schema.TypeInt,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func dataSourceUserRead(d *schema.ResourceData, m interface{}) error {
|
||||
d.SetId(d.Get("name").(string))
|
||||
return resourceUserRead(d, m)
|
||||
}
|
||||
31
bitbucket/data_user_test.go
Normal file
31
bitbucket/data_user_test.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package bitbucket
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
)
|
||||
|
||||
func TestAccBitbucketDataUser(t *testing.T) {
|
||||
config := `
|
||||
data "bitbucketserver_user" "test" {
|
||||
name = "admin"
|
||||
}
|
||||
`
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
Steps: []resource.TestStep{
|
||||
{
|
||||
Config: config,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
resource.TestCheckResourceAttr("data.bitbucketserver_user.test", "name", "admin"),
|
||||
resource.TestCheckResourceAttr("data.bitbucketserver_user.test", "email_address", "admin@example.com"),
|
||||
resource.TestCheckResourceAttr("data.bitbucketserver_user.test", "display_name", "Admin"),
|
||||
resource.TestCheckResourceAttr("data.bitbucketserver_user.test", "user_id", "1"),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -44,6 +44,7 @@ func Provider() terraform.ResourceProvider {
|
||||
"bitbucketserver_repository_hooks": dataSourceRepositoryHooks(),
|
||||
"bitbucketserver_repository_permissions_groups": dataSourceRepositoryPermissionsGroups(),
|
||||
"bitbucketserver_repository_permissions_users": dataSourceRepositoryPermissionsUsers(),
|
||||
"bitbucketserver_user": dataSourceUser(),
|
||||
},
|
||||
ResourcesMap: map[string]*schema.Resource{
|
||||
"bitbucketserver_banner": resourceBanner(),
|
||||
|
||||
@@ -4,18 +4,20 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
"github.com/hashicorp/terraform/helper/validation"
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
"github.com/hashicorp/terraform/helper/validation"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
EmailAddress string `json:"emailAddress,omitempty"`
|
||||
DisplayName string `json:"displayName,omitempty"`
|
||||
UserId int `json:"id,omitempty"`
|
||||
}
|
||||
|
||||
type UserUpdate struct {
|
||||
@@ -176,6 +178,7 @@ func resourceUserRead(d *schema.ResourceData, m interface{}) error {
|
||||
d.Set("name", user.Name)
|
||||
d.Set("email_address", user.EmailAddress)
|
||||
d.Set("display_name", user.DisplayName)
|
||||
d.Set("user_id", user.UserId)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user