Skip to content

Commit

Permalink
PLT-1462: Added validation for domain name (#532)
Browse files Browse the repository at this point in the history
* PLT-1462: added validation for domain name

* example fix
  • Loading branch information
SivaanandM authored Oct 29, 2024
1 parent 3e1ee0c commit d706018
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ data "spectrocloud_private_cloud_gateway" "gateway" {
}

data "spectrocloud_privatecloudgateway_dns_map" "gateway_dns_map" {
search_domain_name = "spectrocloud2.dev"

search_domain_name = "spectrocloud.dev"
# Option to filter with network, if more than one dns map in same search_domain_name.
# network = "VM-NETWORK"
private_cloud_gateway_id = data.spectrocloud_private_cloud_gateway.gateway.id
}

Expand Down
5 changes: 4 additions & 1 deletion spectrocloud/data_source_pcg_dns_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ func dataSourceDNSMapRead(_ context.Context, d *schema.ResourceData, m interface
matchDNSMap.Items = append(matchDNSMap.Items, dnsMap)
}
}
if len(matchDNSMap.Items) == 1 {
if len(matchDNSMap.Items) == 0 {
err := fmt.Errorf("error: No DNS Map identified for name `%s`. Kindly re-try with up valid `name`", name)
return diag.FromErr(err)
} else if len(matchDNSMap.Items) == 1 {
err := setBackDNSMap(matchDNSMap.Items[0], d)
if err != nil {
return diag.FromErr(err)
Expand Down
6 changes: 6 additions & 0 deletions spectrocloud/resource_pcg_dns_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/spectrocloud/gomi/pkg/ptr"
"github.com/spectrocloud/palette-sdk-go/api/models"
"regexp"
"time"
)

Expand Down Expand Up @@ -34,6 +36,10 @@ func resourcePrivateCloudGatewayDNSMap() *schema.Resource {
Type: schema.TypeString,
Required: true,
Description: "The domain name used for DNS search queries within the private cloud.",
ValidateFunc: validation.StringMatch(
regexp.MustCompile(`^([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}$`),
"must be a valid domain name",
),
},
"data_center": {
Type: schema.TypeString,
Expand Down

0 comments on commit d706018

Please sign in to comment.