Skip to content

Commit 95a815d

Browse files
committed
Starting point for adding Organization app support for Heroku Provider
1 parent b43ca0a commit 95a815d

1 file changed

Lines changed: 59 additions & 1 deletion

File tree

builtin/providers/heroku/resource_heroku_app.go

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func (a *application) Update() error {
4242

4343
func resourceHerokuApp() *schema.Resource {
4444
return &schema.Resource{
45-
Create: resourceHerokuAppCreate,
45+
Create: switchHerokuAppCreate,
4646
Read: resourceHerokuAppRead,
4747
Update: resourceHerokuAppUpdate,
4848
Delete: resourceHerokuAppDelete,
@@ -93,10 +93,24 @@ func resourceHerokuApp() *schema.Resource {
9393
Type: schema.TypeString,
9494
Computed: true,
9595
},
96+
97+
"organization": &schema.Schema{
98+
Type: schema.TypeString,
99+
Optional: true,
100+
},
96101
},
97102
}
98103
}
99104

105+
func switchHerokuAppCreate(d *schema.ResourceData, meta interface{}) error {
106+
isOrg := d.Get("organization")
107+
if len(isOrg.(string)) != 0 {
108+
return resourceHerokuOrgAppCreate(d, meta)
109+
} else {
110+
return resourceHerokuAppCreate(d, meta)
111+
}
112+
}
113+
100114
func resourceHerokuAppCreate(d *schema.ResourceData, meta interface{}) error {
101115
client := meta.(*heroku.Service)
102116

@@ -138,6 +152,50 @@ func resourceHerokuAppCreate(d *schema.ResourceData, meta interface{}) error {
138152
return resourceHerokuAppRead(d, meta)
139153
}
140154

155+
func resourceHerokuOrgAppCreate(d *schema.ResourceData, meta interface{}) error {
156+
client := meta.(*heroku.Service)
157+
// Build up our creation options
158+
opts := heroku.OrganizationAppCreateOpts{}
159+
if v := d.Get("organization"); v != nil {
160+
vs := v.(string)
161+
log.Printf("[DEBUG] App name: %s", vs)
162+
opts.Organization = &vs
163+
}
164+
if v := d.Get("name"); v != nil {
165+
vs := v.(string)
166+
log.Printf("[DEBUG] App name: %s", vs)
167+
opts.Name = &vs
168+
}
169+
if v := d.Get("region"); v != nil {
170+
vs := v.(string)
171+
log.Printf("[DEBUG] App region: %s", vs)
172+
opts.Region = &vs
173+
}
174+
if v := d.Get("stack"); v != nil {
175+
vs := v.(string)
176+
log.Printf("[DEBUG] App stack: %s", vs)
177+
opts.Stack = &vs
178+
}
179+
180+
log.Printf("[DEBUG] Creating Heroku app...")
181+
a, err := client.OrganizationAppCreate(opts)
182+
if err != nil {
183+
return err
184+
}
185+
186+
d.SetId(a.Name)
187+
log.Printf("[INFO] App ID: %s", d.Id())
188+
189+
if v := d.Get("config_vars"); v != nil {
190+
err = update_config_vars(d.Id(), client, nil, v.([]interface{}))
191+
if err != nil {
192+
return err
193+
}
194+
}
195+
196+
return resourceHerokuAppRead(d, meta)
197+
}
198+
141199
func resourceHerokuAppRead(d *schema.ResourceData, meta interface{}) error {
142200
client := meta.(*heroku.Service)
143201
app, err := resource_heroku_app_retrieve(d.Id(), client)

0 commit comments

Comments
 (0)