forked from hashicorp/terraform-provider-azurerm
/
resource_group.go
55 lines (45 loc) · 1.42 KB
/
resource_group.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
package azure
import (
"fmt"
"regexp"
"strings"
"github.com/hashicorp/terraform/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/suppress"
)
func SchemaResourceGroupName() *schema.Schema {
return &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validateResourceGroupName,
}
}
func SchemaResourceGroupNameDiffSuppress() *schema.Schema {
return &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
DiffSuppressFunc: suppress.CaseDifference,
ValidateFunc: validateResourceGroupName,
}
}
func SchemaResourceGroupNameForDataSource() *schema.Schema {
return &schema.Schema{
Type: schema.TypeString,
Required: true,
}
}
func validateResourceGroupName(v interface{}, k string) (ws []string, es []error) {
value := v.(string)
if len(value) > 80 {
es = append(es, fmt.Errorf("%q may not exceed 80 characters in length", k))
}
if strings.HasSuffix(value, ".") {
es = append(es, fmt.Errorf("%q may not end with a period", k))
}
// regex pulled from https://docs.microsoft.com/en-us/rest/api/resources/resourcegroups/createorupdate
if matched := regexp.MustCompile(`^[-\w\._\(\)]+$`).Match([]byte(value)); !matched {
es = append(es, fmt.Errorf("%q may only contain alphanumeric characters, dash, underscores, parentheses and periods", k))
}
return ws, es
}