Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new resource 'azurerm_private_dns_srv_record' #4783

Merged
merged 20 commits into from
Nov 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
3feae25
Merge remote-tracking branch 'upstream/master' into private-dns-srv
Oct 28, 2019
630a414
Merge remote-tracking branch 'upstream/master' into private-dns-srv
Oct 31, 2019
de4a98a
added resource_arm_private_dns_srv_record
phires Oct 31, 2019
620bbe2
Merge remote-tracking branch 'upstream/master' into private-dns-srv
phires Oct 31, 2019
278eae8
Added documentation for private_dns_srv_record
phires Oct 31, 2019
90a7b0f
Update website/docs/r/private_dns_srv_record.html.markdown
phires Nov 2, 2019
42dcc39
Update website/docs/r/private_dns_srv_record.html.markdown
phires Nov 2, 2019
aa06f1e
Update website/docs/r/private_dns_srv_record.html.markdown
phires Nov 2, 2019
cec6a11
Update website/docs/r/private_dns_srv_record.html.markdown
phires Nov 2, 2019
7dd02f8
Update website/docs/r/private_dns_srv_record.html.markdown
phires Nov 2, 2019
be1faf3
Inline variables
phires Nov 8, 2019
39912fc
Validation of "record.target" to not be empty
phires Nov 8, 2019
1fe8fd5
Removed custom hashing of record
phires Nov 8, 2019
1570f1b
minor changes to acceptance test
phires Nov 8, 2019
ac29c41
Added subcategory
phires Nov 8, 2019
d7ec631
Added dereference nil checks
phires Nov 8, 2019
987c26e
Update website/docs/r/private_dns_srv_record.html.markdown
phires Nov 11, 2019
d8377ca
Update website/docs/r/private_dns_srv_record.html.markdown
phires Nov 11, 2019
206108d
r/private_dns: validating that the name field is lower-cased
tombuildsstuff Nov 17, 2019
4bb7e7d
r/privtae_dns_srv_record: updating the test name to be lower-cased
tombuildsstuff Nov 17, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -380,6 +380,7 @@ func Provider() terraform.ResourceProvider {
"azurerm_private_dns_a_record": resourceArmPrivateDnsARecord(),
"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