generated from davidji99/terraform-provider-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathhelper.go
76 lines (63 loc) · 1.82 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
package split
import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"log"
"strings"
)
// getWorkspaceID extracts the workspace ID attribute generically from a Split resource.
func getWorkspaceID(d *schema.ResourceData) string {
var workspaceID string
if v, ok := d.GetOk("workspace_id"); ok {
vs := v.(string)
log.Printf("[DEBUG] workspace_id: %s", vs)
workspaceID = vs
}
return workspaceID
}
// getTrafficTypeID extracts the traffic type ID attribute generically from a Split resource.
func getTrafficTypeID(d *schema.ResourceData) string {
var trafficTypeID string
if v, ok := d.GetOk("traffic_type_id"); ok {
vs := v.(string)
log.Printf("[DEBUG] traffic_type_id: %s", vs)
trafficTypeID = vs
}
return trafficTypeID
}
// getEnvironmentID extracts the environment ID attribute generically from a Split resource.
func getEnvironmentID(d *schema.ResourceData) string {
var envID string
if v, ok := d.GetOk("environment_id"); ok {
vs := v.(string)
log.Printf("[DEBUG] environment_id: %s", vs)
envID = vs
}
return envID
}
// getSplitName extracts the split name attribute generically from a Split resource.
func getSplitName(d *schema.ResourceData) string {
var n string
if v, ok := d.GetOk("split_name"); ok {
vs := v.(string)
log.Printf("[DEBUG] split_name: %s", vs)
n = vs
}
return n
}
func parseCompositeID(id string, numOfSplits int) ([]string, error) {
parts := strings.SplitN(id, ":", numOfSplits)
if len(parts) != numOfSplits {
return nil, fmt.Errorf("error: import composite ID requires %d parts separated by a colon (x:y). "+
"Please check resource documentation for more information", numOfSplits)
}
return parts, nil
}
func Truncate(text string, width int) string {
if width < 0 {
return ""
}
r := []rune(text)
trunc := r[:width]
return string(trunc) + "..."
}