Add to Organization schema ref. Also gofmt the file

This commit is contained in:
Clint Shryock 2014-10-12 11:49:57 -05:00
parent 95a815deda
commit 5fe2593c16
1 changed files with 49 additions and 48 deletions

View File

@ -42,7 +42,7 @@ func (a *application) Update() error {
func resourceHerokuApp() *schema.Resource { func resourceHerokuApp() *schema.Resource {
return &schema.Resource{ return &schema.Resource{
Create: switchHerokuAppCreate, Create: switchHerokuAppCreate,
Read: resourceHerokuAppRead, Read: resourceHerokuAppRead,
Update: resourceHerokuAppUpdate, Update: resourceHerokuAppUpdate,
Delete: resourceHerokuAppDelete, Delete: resourceHerokuAppDelete,
@ -94,21 +94,22 @@ func resourceHerokuApp() *schema.Resource {
Computed: true, Computed: true,
}, },
"organization": &schema.Schema{ "organization": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
}, ForceNew: true,
},
}, },
} }
} }
func switchHerokuAppCreate(d *schema.ResourceData, meta interface{}) error { func switchHerokuAppCreate(d *schema.ResourceData, meta interface{}) error {
isOrg := d.Get("organization") isOrg := d.Get("organization")
if len(isOrg.(string)) != 0 { if len(isOrg.(string)) != 0 {
return resourceHerokuOrgAppCreate(d, meta) return resourceHerokuOrgAppCreate(d, meta)
} else { } else {
return resourceHerokuAppCreate(d, meta) return resourceHerokuAppCreate(d, meta)
} }
} }
func resourceHerokuAppCreate(d *schema.ResourceData, meta interface{}) error { 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 { func resourceHerokuOrgAppCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*heroku.Service) client := meta.(*heroku.Service)
// Build up our creation options // Build up our creation options
opts := heroku.OrganizationAppCreateOpts{} opts := heroku.OrganizationAppCreateOpts{}
if v := d.Get("organization"); v != nil { if v := d.Get("organization"); v != nil {
vs := v.(string) vs := v.(string)
log.Printf("[DEBUG] App name: %s", vs) log.Printf("[DEBUG] App name: %s", vs)
opts.Organization = &vs opts.Organization = &vs
} }
if v := d.Get("name"); v != nil { if v := d.Get("name"); v != nil {
vs := v.(string) vs := v.(string)
log.Printf("[DEBUG] App name: %s", vs) log.Printf("[DEBUG] App name: %s", vs)
opts.Name = &vs opts.Name = &vs
} }
if v := d.Get("region"); v != nil { if v := d.Get("region"); v != nil {
vs := v.(string) vs := v.(string)
log.Printf("[DEBUG] App region: %s", vs) log.Printf("[DEBUG] App region: %s", vs)
opts.Region = &vs opts.Region = &vs
} }
if v := d.Get("stack"); v != nil { if v := d.Get("stack"); v != nil {
vs := v.(string) vs := v.(string)
log.Printf("[DEBUG] App stack: %s", vs) log.Printf("[DEBUG] App stack: %s", vs)
opts.Stack = &vs opts.Stack = &vs
} }
log.Printf("[DEBUG] Creating Heroku app...") log.Printf("[DEBUG] Creating Heroku app...")
a, err := client.OrganizationAppCreate(opts) a, err := client.OrganizationAppCreate(opts)
if err != nil { if err != nil {
return err return err
} }
d.SetId(a.Name) d.SetId(a.Name)
log.Printf("[INFO] App ID: %s", d.Id()) log.Printf("[INFO] App ID: %s", d.Id())
if v := d.Get("config_vars"); v != nil { if v := d.Get("config_vars"); v != nil {
err = update_config_vars(d.Id(), client, nil, v.([]interface{})) err = update_config_vars(d.Id(), client, nil, v.([]interface{}))
if err != nil { if err != nil {
return err return err
} }
} }
return resourceHerokuAppRead(d, meta) return resourceHerokuAppRead(d, meta)
} }
func resourceHerokuAppRead(d *schema.ResourceData, meta interface{}) error { func resourceHerokuAppRead(d *schema.ResourceData, meta interface{}) error {