-
Notifications
You must be signed in to change notification settings - Fork 385
/
util.go
36 lines (29 loc) · 839 Bytes
/
util.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
package common
import (
"context"
"log"
"regexp"
"strings"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
var (
uuidRegex = regexp.MustCompile(`^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`)
)
func StringIsUUID(s string) bool {
return uuidRegex.MatchString(s)
}
func GetTerraformVersionFromContext(ctx context.Context) string {
tfVersion := "unknown"
p, ok := ctx.Value(Provider).(*schema.Provider)
if ok {
tfVersion = p.TerraformVersion
}
return tfVersion
}
func IsExporter(ctx context.Context) bool {
return GetTerraformVersionFromContext(ctx) == "exporter"
}
func SuppressDiffWhitespaceChange(k, old, new string, d *schema.ResourceData) bool {
log.Printf("[DEBUG] Suppressing diff for %v: old=%#v new=%#v", k, old, new)
return strings.TrimSpace(old) == strings.TrimSpace(new)
}