From 5fe2593c16d06f94d27880296df81b006b3899c8 Mon Sep 17 00:00:00 2001 From: Clint Shryock Date: Sun, 12 Oct 2014 11:49:57 -0500 Subject: [PATCH] Add to Organization schema ref. Also gofmt the file --- .../providers/heroku/resource_heroku_app.go | 97 ++++++++++--------- 1 file changed, 49 insertions(+), 48 deletions(-) diff --git a/builtin/providers/heroku/resource_heroku_app.go b/builtin/providers/heroku/resource_heroku_app.go index 05cae572f..fd59bd7d1 100644 --- a/builtin/providers/heroku/resource_heroku_app.go +++ b/builtin/providers/heroku/resource_heroku_app.go @@ -42,7 +42,7 @@ func (a *application) Update() error { func resourceHerokuApp() *schema.Resource { return &schema.Resource{ - Create: switchHerokuAppCreate, + Create: switchHerokuAppCreate, Read: resourceHerokuAppRead, Update: resourceHerokuAppUpdate, Delete: resourceHerokuAppDelete, @@ -94,21 +94,22 @@ func resourceHerokuApp() *schema.Resource { Computed: true, }, - "organization": &schema.Schema{ - Type: schema.TypeString, - Optional: true, - }, + "organization": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, }, } } func switchHerokuAppCreate(d *schema.ResourceData, meta interface{}) error { - isOrg := d.Get("organization") - if len(isOrg.(string)) != 0 { - return resourceHerokuOrgAppCreate(d, meta) - } else { - return resourceHerokuAppCreate(d, meta) - } + isOrg := d.Get("organization") + if len(isOrg.(string)) != 0 { + return resourceHerokuOrgAppCreate(d, meta) + } else { + return resourceHerokuAppCreate(d, meta) + } } func resourceHerokuAppCreate(d *schema.ResourceData, meta interface{}) error { @@ -153,47 +154,47 @@ func resourceHerokuAppCreate(d *schema.ResourceData, meta interface{}) error { } func resourceHerokuOrgAppCreate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*heroku.Service) - // Build up our creation options - opts := heroku.OrganizationAppCreateOpts{} - if v := d.Get("organization"); v != nil { - vs := v.(string) - log.Printf("[DEBUG] App name: %s", vs) - opts.Organization = &vs - } - if v := d.Get("name"); v != nil { - vs := v.(string) - log.Printf("[DEBUG] App name: %s", vs) - opts.Name = &vs - } - if v := d.Get("region"); v != nil { - vs := v.(string) - log.Printf("[DEBUG] App region: %s", vs) - opts.Region = &vs - } - if v := d.Get("stack"); v != nil { - vs := v.(string) - log.Printf("[DEBUG] App stack: %s", vs) - opts.Stack = &vs - } + client := meta.(*heroku.Service) + // Build up our creation options + opts := heroku.OrganizationAppCreateOpts{} + if v := d.Get("organization"); v != nil { + vs := v.(string) + log.Printf("[DEBUG] App name: %s", vs) + opts.Organization = &vs + } + if v := d.Get("name"); v != nil { + vs := v.(string) + log.Printf("[DEBUG] App name: %s", vs) + opts.Name = &vs + } + if v := d.Get("region"); v != nil { + vs := v.(string) + log.Printf("[DEBUG] App region: %s", vs) + opts.Region = &vs + } + if v := d.Get("stack"); v != nil { + vs := v.(string) + log.Printf("[DEBUG] App stack: %s", vs) + opts.Stack = &vs + } - log.Printf("[DEBUG] Creating Heroku app...") - a, err := client.OrganizationAppCreate(opts) - if err != nil { - return err - } + log.Printf("[DEBUG] Creating Heroku app...") + a, err := client.OrganizationAppCreate(opts) + if err != nil { + return err + } - d.SetId(a.Name) - log.Printf("[INFO] App ID: %s", d.Id()) + d.SetId(a.Name) + log.Printf("[INFO] App ID: %s", d.Id()) - if v := d.Get("config_vars"); v != nil { - err = update_config_vars(d.Id(), client, nil, v.([]interface{})) - if err != nil { - return err - } - } + if v := d.Get("config_vars"); v != nil { + err = update_config_vars(d.Id(), client, nil, v.([]interface{})) + if err != nil { + return err + } + } - return resourceHerokuAppRead(d, meta) + return resourceHerokuAppRead(d, meta) } func resourceHerokuAppRead(d *schema.ResourceData, meta interface{}) error {