Skip to content
This repository has been archived by the owner on Apr 9, 2021. It is now read-only.

Commit

Permalink
TER-233: Update provider so it properly configures ghost client
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Caussat authored and Jordan Caussat committed Mar 19, 2018
1 parent 66e5eca commit a3e44df
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
7 changes: 4 additions & 3 deletions ghost/config.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package ghost

import (
"bitbucket.org/morea/go-st"
"log"

"bitbucket.org/morea/go-st"
)

// Config defines the configuration options for the Ghost client
Expand All @@ -14,9 +15,9 @@ type Config struct {

// Client returns a new Ghost client
func (c *Config) Client() (*ghost.Client, error) {
client := ghost.NewClient(c.User, c.Password, c.URL)
client := ghost.NewClient(c.URL, c.User, c.Password)

log.Printf("[INFO] Ghost client configured")
log.Printf("[INFO] Ghost client configured: %s %s %s", c.User, c.Password, c.URL)

return client, nil
}
7 changes: 4 additions & 3 deletions ghost/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ func Provider() terraform.ResourceProvider {

func providerConfigure(data *schema.ResourceData) (interface{}, error) {
config := Config{
User: data.Get("user").(string),
Password: data.Get("password").(string),
URL: data.Get("endpoint").(string),
User: data.Get("user").(string),
Password: data.Get("password").(string),
URL: data.Get("endpoint").(string),
}
log.Println("[INFO] Initializing Ghost client")

return config.Client()
}
24 changes: 20 additions & 4 deletions ghost/resource_ghost_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ghost
import (
"log"

"bitbucket.org/morea/go-st"
"github.com/hashicorp/terraform/helper/schema"
)

Expand All @@ -12,24 +13,39 @@ func resourceGhostApp() *schema.Resource {
Read: resourceGhostAppRead,
Update: resourceGhostAppUpdate,
Delete: resourceGhostAppDelete,

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
},
"description": {
"env": {
Type: schema.TypeString,
Optional: true,
Default: "Managed by Terraform",
Required: true,
},
"role": {
Type: schema.TypeString,
Required: true,
},
},
}
}

func resourceGhostAppCreate(d *schema.ResourceData, meta interface{}) error {
//client := meta.(*ghost.Client)
client := meta.(*ghost.Client)

name := d.Get("name").(string)
d.SetId(name)
log.Printf("[INFO] Creating Ghost app %s", d.Get("name").(string))

log.Printf("[INFO ]Testing Ghost client get all apps")
apps, err := client.GetApps()
if err == nil {
log.Printf("All apps retrieved: %s", apps)
} else {
log.Printf("error: %v", err)
}

return nil
}

Expand Down

0 comments on commit a3e44df

Please sign in to comment.