Skip to content

Commit

Permalink
Merge pull request #4783 from phires/private-dns-srv
Browse files Browse the repository at this point in the history
new resource 'azurerm_private_dns_srv_record'
  • Loading branch information
tombuildsstuff authored Nov 17, 2019
2 parents 45590f2 + 4bb7e7d commit 93dffcf
Show file tree
Hide file tree
Showing 10 changed files with 819 additions and 8 deletions.
22 changes: 22 additions & 0 deletions azurerm/helpers/validate/strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,28 @@ import (
"strings"
)

// LowerCasedString validates that the string is lower-cased
func LowerCasedString(i interface{}, k string) ([]string, []error) {
v, ok := i.(string)
if !ok {
return nil, []error{fmt.Errorf("expected type of %q to be string", k)}
}

if strings.TrimSpace(v) == "" {
return nil, []error{fmt.Errorf("%q must not be empty", k)}
}

if strings.ToLower(v) != v {
return nil, []error{fmt.Errorf("%q must be a lower-cased string", k)}
}

if strings.ContainsAny(v, " ") {
return nil, []error{fmt.Errorf("%q cannot contain whitespace", k)}
}

return nil, nil
}

// NoEmptyStrings validates that the string is not just whitespace characters (equal to [\r\n\t\f\v ])
func NoEmptyStrings(i interface{}, k string) ([]string, []error) {
v, ok := i.(string)
Expand Down
69 changes: 69 additions & 0 deletions azurerm/helpers/validate/strings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,75 @@ import (
"testing"
)

func TestLowerCasedStrings(t *testing.T) {
cases := []struct {
Value string
TestName string
ErrCount int
}{
{
Value: "",
TestName: "Empty",
ErrCount: 1,
},
{
Value: " ",
TestName: "Whitespace",
ErrCount: 1,
},
{
Value: "Hello",
TestName: "TitleCaseSingleWord",
ErrCount: 1,
},
{
Value: "HELLO",
TestName: "TitleCaseSingleWord",
ErrCount: 1,
},
{
Value: "hello",
TestName: "LowerCaseSingleWord",
ErrCount: 0,
},
{
Value: "hello-there.com",
TestName: "LowerCaseMultipleWords",
ErrCount: 0,
},
{
Value: "hello there.com",
TestName: "LowerCaseMultipleWordsWhitespace",
ErrCount: 1,
},
{
Value: "Hello There.com",
TestName: "TitleCaseMultipleWordsWhitespace",
ErrCount: 1,
},
{
Value: "Hello-There.com",
TestName: "TitleCaseMultipleWordsDash",
ErrCount: 1,
},
{
Value: "HELLO-THERE.COM",
TestName: "UpperCaseMultipleWordsDash",
ErrCount: 1,
},
}

for _, tc := range cases {
t.Run(tc.TestName, func(t *testing.T) {
_, errors := LowerCasedString(tc.Value, tc.TestName)

if len(errors) != tc.ErrCount {
t.Fatalf("Expected NoEmptyStrings to have %d not %d errors for %q", tc.ErrCount, len(errors), tc.TestName)
}
})
}
}

func TestNoEmptyStrings(t *testing.T) {
cases := []struct {
Value string
Expand Down
1 change: 1 addition & 0 deletions azurerm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ func Provider() terraform.ResourceProvider {
"azurerm_private_dns_aaaa_record": resourceArmPrivateDnsAaaaRecord(),
"azurerm_private_dns_cname_record": resourceArmPrivateDnsCNameRecord(),
"azurerm_private_dns_ptr_record": resourceArmPrivateDnsPtrRecord(),
"azurerm_private_dns_srv_record": resourceArmPrivateDnsSrvRecord(),
"azurerm_private_dns_zone_virtual_network_link": resourceArmPrivateDnsZoneVirtualNetworkLink(),
"azurerm_proximity_placement_group": resourceArmProximityPlacementGroup(),
"azurerm_public_ip": resourceArmPublicIp(),
Expand Down
3 changes: 3 additions & 0 deletions azurerm/resource_arm_private_dns_a_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts"
Expand Down Expand Up @@ -37,6 +38,8 @@ func resourceArmPrivateDnsARecord() *schema.Resource {
Type: schema.TypeString,
Required: true,
ForceNew: true,
// lower-cased due to the broken API https://github.com/Azure/azure-rest-api-specs/issues/6641
ValidateFunc: validate.LowerCasedString,
},

// TODO: make this case sensitive once the API's fixed https://github.com/Azure/azure-rest-api-specs/issues/6641
Expand Down
9 changes: 5 additions & 4 deletions azurerm/resource_arm_private_dns_cname_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ func resourceArmPrivateDnsCNameRecord() *schema.Resource {

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validate.NoEmptyStrings,
Type: schema.TypeString,
Required: true,
ForceNew: true,
// lower-cased due to the broken API https://github.com/Azure/azure-rest-api-specs/issues/6641
ValidateFunc: validate.LowerCasedString,
},

// TODO: make this case sensitive once the API's fixed https://github.com/Azure/azure-rest-api-specs/issues/6641
Expand Down
9 changes: 5 additions & 4 deletions azurerm/resource_arm_private_dns_ptr_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ func resourceArmPrivateDnsPtrRecord() *schema.Resource {

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validate.NoEmptyStrings,
Type: schema.TypeString,
Required: true,
ForceNew: true,
// lower-cased due to the broken API https://github.com/Azure/azure-rest-api-specs/issues/6641
ValidateFunc: validate.LowerCasedString,
},

// TODO: make this case sensitive once the API's fixed https://github.com/Azure/azure-rest-api-specs/issues/6641
Expand Down
Loading

0 comments on commit 93dffcf

Please sign in to comment.