From b850f8bc658c1569de775c1be7fbde3c8f985bca Mon Sep 17 00:00:00 2001 From: Clint Shryock Date: Sun, 12 Oct 2014 13:01:47 -0500 Subject: [PATCH] proposal for making orgs a structure with fields instead of just a name field --- .../providers/heroku/resource_heroku_app.go | 47 +++++++++++++++++-- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/builtin/providers/heroku/resource_heroku_app.go b/builtin/providers/heroku/resource_heroku_app.go index 41a42d494..eca88b345 100644 --- a/builtin/providers/heroku/resource_heroku_app.go +++ b/builtin/providers/heroku/resource_heroku_app.go @@ -95,17 +95,40 @@ func resourceHerokuApp() *schema.Resource { }, "organization": &schema.Schema{ - Type: schema.TypeString, Description: "Name of Organization to create application in. Leave blank for personal apps.", + Type: schema.TypeList, Optional: true, ForceNew: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": &schema.Schema{ + Type: schema.TypeString, + Required: true, + }, + + "locked": &schema.Schema{ + Type: schema.TypeBool, + Optional: true, + }, + + "personal": &schema.Schema{ + Type: schema.TypeBool, + Optional: true, + }, + }, + }, }, }, } } func switchHerokuAppCreate(d *schema.ResourceData, meta interface{}) error { - if _, ok := d.GetOk("organization"); ok { + orgCount := d.Get("organization.#").(int) + if orgCount > 1 { + return fmt.Errorf("Error Creating Heroku App: Only 1 Organization") + } + + if _, ok := d.GetOk("organization.0.name"); ok { return resourceHerokuOrgAppCreate(d, meta) } else { return resourceHerokuAppCreate(d, meta) @@ -157,12 +180,26 @@ func resourceHerokuOrgAppCreate(d *schema.ResourceData, meta interface{}) error client := meta.(*heroku.Service) // Build up our creation options opts := heroku.OrganizationAppCreateOpts{} - if v, ok := d.GetOk("organization"); ok { + + if v := d.Get("organization.0.name"); v != nil { vs := v.(string) - log.Printf("[DEBUG] App name: %s", vs) + log.Printf("[DEBUG] Organization name: %s", vs) opts.Organization = &vs } - if v, ok := d.GetOk("name"); ok { + + if v := d.Get("organization.0.personal"); v != nil { + vs := v.(bool) + log.Printf("[DEBUG] Organization Personal: %s", vs) + opts.Personal = &vs + } + + if v := d.Get("organization.0.locked"); v != nil { + vs := v.(bool) + log.Printf("[DEBUG] Organization locked: %s", vs) + opts.Locked = &vs + } + + if v := d.Get("name"); v != nil { vs := v.(string) log.Printf("[DEBUG] App name: %s", vs) opts.Name = &vs