From 7d64cacc76cd7acc796166321dc3ef84c005e9ca Mon Sep 17 00:00:00 2001 From: Melissa Meyer Date: Thu, 11 Jan 2018 14:48:00 -0800 Subject: [PATCH] testing schema for creating user --- main.go | 12 +++---- okta/groups.go | 54 ++++++++++++++++++++++++++++++ okta/provider.go | 8 +++-- okta/provider_test.go | 4 +++ okta/users.go | 76 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 145 insertions(+), 9 deletions(-) create mode 100644 okta/groups.go create mode 100644 okta/users.go diff --git a/main.go b/main.go index 745130ebf..603f408ff 100644 --- a/main.go +++ b/main.go @@ -1,14 +1,12 @@ package main import ( - "github.com/articulate/terraform-provider-okta/okta" - "github.com/hashicorp/terraform/plugin" + "github.com/articulate/terraform-provider-okta/okta" + "github.com/hashicorp/terraform/plugin" ) -var Version string - func main() { - plugin.Serve(&plugin.ServeOpts{ - ProviderFunc: okta.Provider, - }) + plugin.Serve(&plugin.ServeOpts{ + ProviderFunc: okta.Provider, + }) } diff --git a/okta/groups.go b/okta/groups.go new file mode 100644 index 000000000..5a9feccd8 --- /dev/null +++ b/okta/groups.go @@ -0,0 +1,54 @@ +package okta + +import ( + "encoding/json" + "log" + "time" + + "github.com/articulate/oktasdk-go/okta" + "github.com/hashicorp/terraform/helper/schema" +) + +func Users() *schema.Resource { + return &schema.Resource{ + Create: UserCreate, + Read: UserRead, + Update: UserUpdate, + Delete: UserDelete, + + Schema: map[string]*schema.Schema{ + "name": &schema.Schema{ + Type: schema.TypeString, + Required: true, + Description: "Group name", + }, + "description": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Description: "Group description", + }, + + "group_id": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Group ID (generated)", + }, + }, + } +} + +func GroupCreate(d *schema.ResourceData, m interface{}) error { + return nil +} + +func GroupRead(d *schema.ResourceData, m interface{}) error { + return nil +} + +func GroupUpdate(d *schema.ResourceData, m interface{}) error { + return nil +} + +func GroupDelete(d *schema.ResourceData, m interface{}) error { + return nil +} diff --git a/okta/provider.go b/okta/provider.go index 63e07d259..73523a5bb 100644 --- a/okta/provider.go +++ b/okta/provider.go @@ -3,7 +3,7 @@ package okta import ( "log" - "github.com/chrismalek/oktasdk-go/okta" + "github.com/articulate/oktasdk-go/okta" "github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/terraform" ) @@ -31,7 +31,11 @@ func Provider() terraform.ResourceProvider { }, }, - ResourcesMap: map[string]*schema.Resource{}, + ResourcesMap: map[string]*schema.Resource{ + "groups": Groups(), + "users": Users(), + + }, ConfigureFunc: providerConfigure, } diff --git a/okta/provider_test.go b/okta/provider_test.go index b0c614d7b..1e4847e33 100644 --- a/okta/provider_test.go +++ b/okta/provider_test.go @@ -24,6 +24,10 @@ func TestProvider(t *testing.T) { } } +func TestProviderImpl(t *testing.T) { + var _ terraform.ResourceProvider = Provider() +} + func testAccPreCheck(t *testing.T) { if v := os.Getenv("OKTA_ORGANIZATION"); v == "" { t.Fatal("OKTA_ORGANIZATION must be set for acceptance tests") diff --git a/okta/users.go b/okta/users.go new file mode 100644 index 000000000..51523c3db --- /dev/null +++ b/okta/users.go @@ -0,0 +1,76 @@ +package okta + +import ( + "encoding/json" + "log" + "time" + + "github.com/articulate/oktasdk-go/okta" + "github.com/hashicorp/terraform/helper/schema" +) + +func Users() *schema.Resource { + return &schema.Resource{ + Create: UserCreate, + Read: UserRead, + Update: UserUpdate, + Delete: UserDelete, + + Schema: map[string]*schema.Schema{ + "firstname": &schema.Schema{ + Type: schema.TypeString, + Required: true, + Description: "User first name", + }, + "lastname": &schema.Schema{ + Type: schema.TypeString, + Required: true, + Description: "User last name", + }, + + "email": &schema.Schema{ + Type: schema.TypeString, + Required: true, + Description: "User email address", + }, + }, + } +} + +func UserCreate(d *schema.ResourceData, m interface{}) error { + log.Println("[INFO] Creating User") + client := okta.NewClient(nil, orgName, apiToken, isProductionOKTAORG) + log.Println("[INFO] Client Base URL: %v\n\n", client.BaseURL) + + newUserTemplate := client.Users.NewUser() + newUserTemplate.Profile.FirstName = d.Get("firstname").(string) + newUserTemplate.Profile.LastName = d.Get("lastname").(string) + time.Now().Format("2006-01-02") + newUserTemplate.Profile.Login = d.Get("email").(string) + newUserTemplate.Profile.Email = newUserTemplate.Profile.Login + + jsonTest, _ := json.Marshal(newUserTemplate) + + log.Println("[INFO] User Json\n\t%v\n\n", string(jsonTest)) + createNewUserAsActive := false + + newUser, _, err := client.Users.Create(newUserTemplate, createNewUserAsActive) + + if err != nil { + + log.Println("[ERROR] Error Creating User:\n \t%v", err) + return + } + printUser(*newUser) +} + +func UserRead(d *schema.ResourceData, m interface{}) error { + return nil +} + +func UserUpdate(d *schema.ResourceData, m interface{}) error { + return nil +} + +func UserDelete(d *schema.ResourceData, m interface{}) error { + return nil +}