This repository has been archived by the owner on Jul 17, 2020. It is now read-only.
forked from heroku/terraform-provider-heroku
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhelper.go
77 lines (64 loc) · 1.71 KB
/
helper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package heroku
import (
"context"
"fmt"
"log"
"strings"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
heroku "github.com/heroku/heroku-go/v5"
"github.com/terraform-providers/terraform-provider-heroku/version"
)
// getAppName extracts the app attribute generically from a Heroku resource.
func getAppName(d *schema.ResourceData) string {
var appName string
if v, ok := d.GetOk("app"); ok {
vs := v.(string)
log.Printf("[DEBUG] App name: %s", vs)
appName = vs
}
return appName
}
// getAppId extracts the app attribute generically from a Heroku resource.
func getAppId(d *schema.ResourceData) string {
var appName string
if v, ok := d.GetOk("app_id"); ok {
vs := v.(string)
log.Printf("[DEBUG] App id name: %s", vs)
appName = vs
}
return appName
}
// getEmail extracts the email attribute generically from a Heroku resource.
func getEmail(d *schema.ResourceData) string {
var email string
if v, ok := d.GetOk("email"); ok {
vs := v.(string)
log.Printf("[DEBUG] Email: %s", vs)
email = vs
}
return email
}
func doesHerokuAppExist(appName string, client *heroku.Service) (*heroku.App, error) {
app, err := client.AppInfo(context.TODO(), appName)
if err != nil {
log.Println(err)
return nil, fmt.Errorf("[ERROR] Your app does not exist")
}
return app, nil
}
func buildCompositeID(a, b string) string {
return fmt.Sprintf("%s:%s", a, b)
}
func parseCompositeID(id string) (p1 string, p2 string, err error) {
parts := strings.SplitN(id, ":", 2)
if len(parts) == 2 {
p1 = parts[0]
p2 = parts[1]
} else {
err = fmt.Errorf("error: Import composite ID requires two parts separated by colon, eg x:y")
}
return
}
func providerVersion() string {
return version.ProviderVersion
}