diff --git a/ghost/config.go b/ghost/config.go index 768a47a..9d6f448 100644 --- a/ghost/config.go +++ b/ghost/config.go @@ -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 @@ -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 } diff --git a/ghost/provider.go b/ghost/provider.go index 85c7cf0..f60bc96 100644 --- a/ghost/provider.go +++ b/ghost/provider.go @@ -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() } diff --git a/ghost/resource_ghost_app.go b/ghost/resource_ghost_app.go index ed088eb..5b8ebae 100644 --- a/ghost/resource_ghost_app.go +++ b/ghost/resource_ghost_app.go @@ -3,6 +3,7 @@ package ghost import ( "log" + "bitbucket.org/morea/go-st" "github.com/hashicorp/terraform/helper/schema" ) @@ -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 }