Skip to content

Commit

Permalink
v12 fix IBM-Cloud#1090 Validate Schema for name input field for VPC r…
Browse files Browse the repository at this point in the history
…esources
  • Loading branch information
kavya498 committed Feb 13, 2020
1 parent 41ee2c6 commit 3bd0ff2
Show file tree
Hide file tree
Showing 19 changed files with 100 additions and 53 deletions.
8 changes: 4 additions & 4 deletions ibm/resource_ibm_is_floating_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"

"github.ibm.com/Bluemix/riaas-go-client/clients/network"
iserrors "github.ibm.com/Bluemix/riaas-go-client/errors"
)
Expand Down Expand Up @@ -47,9 +46,10 @@ func resourceIBMISFloatingIP() *schema.Resource {
},

isFloatingIPName: {
Type: schema.TypeString,
Required: true,
ForceNew: false,
Type: schema.TypeString,
Required: true,
ForceNew: false,
ValidateFunc: validateISName,
},

isFloatingIPStatus: {
Expand Down
5 changes: 3 additions & 2 deletions ibm/resource_ibm_is_ike_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ func resourceIBMISIKEPolicy() *schema.Resource {

Schema: map[string]*schema.Schema{
isIKEName: {
Type: schema.TypeString,
Required: true,
Type: schema.TypeString,
Required: true,
ValidateFunc: validateISName,
},

isIKEAuthenticationAlg: {
Expand Down
7 changes: 4 additions & 3 deletions ibm/resource_ibm_is_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ func resourceIBMISImage() *schema.Resource {
},

isImageName: {
Type: schema.TypeString,
Required: true,
ForceNew: false,
Type: schema.TypeString,
Required: true,
ForceNew: false,
ValidateFunc: validateISName,
},

isImageTags: {
Expand Down
7 changes: 4 additions & 3 deletions ibm/resource_ibm_is_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,10 @@ func resourceIBMISInstance() *schema.Resource {

Schema: map[string]*schema.Schema{
isInstanceName: {
Type: schema.TypeString,
Required: true,
ForceNew: false,
Type: schema.TypeString,
Required: true,
ForceNew: false,
ValidateFunc: validateISName,
},

isInstanceVPC: {
Expand Down
5 changes: 3 additions & 2 deletions ibm/resource_ibm_is_ipsec_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ func resourceIBMISIPSecPolicy() *schema.Resource {

Schema: map[string]*schema.Schema{
isIpSecName: {
Type: schema.TypeString,
Required: true,
Type: schema.TypeString,
Required: true,
ValidateFunc: validateISName,
},

isIpSecAuthenticationAlg: {
Expand Down
7 changes: 4 additions & 3 deletions ibm/resource_ibm_is_lb.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ func resourceIBMISLB() *schema.Resource {
Schema: map[string]*schema.Schema{

isLBName: {
Type: schema.TypeString,
Required: true,
ForceNew: false,
Type: schema.TypeString,
Required: true,
ForceNew: false,
ValidateFunc: validateISName,
},

isLBType: {
Expand Down
5 changes: 3 additions & 2 deletions ibm/resource_ibm_is_lb_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ func resourceIBMISLBPool() *schema.Resource {

Schema: map[string]*schema.Schema{
isLBPoolName: {
Type: schema.TypeString,
Required: true,
Type: schema.TypeString,
Required: true,
ValidateFunc: validateISName,
},

isLBID: {
Expand Down
7 changes: 4 additions & 3 deletions ibm/resource_ibm_is_networkacls.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ func resourceIBMISNetworkACL() *schema.Resource {

Schema: map[string]*schema.Schema{
isNetworkACLName: {
Type: schema.TypeString,
Required: true,
ForceNew: false,
Type: schema.TypeString,
Required: true,
ForceNew: false,
ValidateFunc: validateISName,
},
isNetworkACLVPC: {
Type: schema.TypeString,
Expand Down
7 changes: 4 additions & 3 deletions ibm/resource_ibm_is_public_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ func resourceIBMISPublicGateway() *schema.Resource {

Schema: map[string]*schema.Schema{
isPublicGatewayName: {
Type: schema.TypeString,
Required: true,
ForceNew: false,
Type: schema.TypeString,
Required: true,
ForceNew: false,
ValidateFunc: validateISName,
},

isPublicGatewayFloatingIP: {
Expand Down
10 changes: 5 additions & 5 deletions ibm/resource_ibm_is_security_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package ibm

import (
"github.com/go-openapi/strfmt"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
gouuid "github.com/satori/go.uuid"
"github.ibm.com/Bluemix/riaas-go-client/clients/network"
Expand Down Expand Up @@ -30,10 +29,11 @@ func resourceIBMISSecurityGroup() *schema.Resource {
Schema: map[string]*schema.Schema{

isSecurityGroupName: {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "Security group name",
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "Security group name",
ValidateFunc: validateISName,
},
isSecurityGroupVPC: {
Type: schema.TypeString,
Expand Down
7 changes: 4 additions & 3 deletions ibm/resource_ibm_is_ssh_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ func resourceIBMISSSHKey() *schema.Resource {

Schema: map[string]*schema.Schema{
isKeyName: {
Type: schema.TypeString,
Required: true,
ForceNew: false,
Type: schema.TypeString,
Required: true,
ForceNew: false,
ValidateFunc: validateISName,
},

isKeyPublicKey: {
Expand Down
7 changes: 4 additions & 3 deletions ibm/resource_ibm_is_subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ func resourceIBMISSubnet() *schema.Resource {
},

isSubnetName: {
Type: schema.TypeString,
Required: true,
ForceNew: false,
Type: schema.TypeString,
Required: true,
ForceNew: false,
ValidateFunc: validateISName,
},

isSubnetNetworkACL: {
Expand Down
5 changes: 3 additions & 2 deletions ibm/resource_ibm_is_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ func resourceIBMISVolume() *schema.Resource {
Schema: map[string]*schema.Schema{

isVolumeName: {
Type: schema.TypeString,
Required: true,
Type: schema.TypeString,
Required: true,
ValidateFunc: validateISName,
},

isVolumeProfileName: {
Expand Down
7 changes: 4 additions & 3 deletions ibm/resource_ibm_is_vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,10 @@ func resourceIBMISVPC() *schema.Resource {
},

isVPCName: {
Type: schema.TypeString,
Required: true,
ForceNew: false,
Type: schema.TypeString,
Required: true,
ForceNew: false,
ValidateFunc: validateISName,
},

isVPCResourceGroup: {
Expand Down
7 changes: 4 additions & 3 deletions ibm/resource_ibm_is_vpc_address_prefix.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ func resourceIBMISVpcAddressPrefix() *schema.Resource {

Schema: map[string]*schema.Schema{
isVPCAddressPrefixPrefixName: {
Type: schema.TypeString,
Required: true,
ForceNew: false,
Type: schema.TypeString,
Required: true,
ForceNew: false,
ValidateFunc: validateISName,
},
isVPCAddressPrefixZoneName: {
Type: schema.TypeString,
Expand Down
7 changes: 4 additions & 3 deletions ibm/resource_ibm_is_vpc_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ func resourceIBMISVpcRoute() *schema.Resource {

Schema: map[string]*schema.Schema{
isVPCRouteName: {
Type: schema.TypeString,
Required: true,
ForceNew: false,
Type: schema.TypeString,
Required: true,
ForceNew: false,
ValidateFunc: validateISName,
},
isVPCRouteLocation: {
Type: schema.TypeString,
Expand Down
7 changes: 4 additions & 3 deletions ibm/resource_ibm_is_vpn_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ func resourceIBMISVPNGateway() *schema.Resource {
Schema: map[string]*schema.Schema{

isVPNGatewayName: {
Type: schema.TypeString,
Required: true,
ForceNew: false,
Type: schema.TypeString,
Required: true,
ForceNew: false,
ValidateFunc: validateISName,
},

isVPNGatewaySubnet: {
Expand Down
5 changes: 3 additions & 2 deletions ibm/resource_ibm_is_vpn_gateway_connections.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ func resourceIBMISVPNGatewayConnection() *schema.Resource {
Schema: map[string]*schema.Schema{

isVPNGatewayConnectionName: {
Type: schema.TypeString,
Required: true,
Type: schema.TypeString,
Required: true,
ValidateFunc: validateISName,
},

isVPNGatewayConnectionVPNGateway: {
Expand Down
33 changes: 32 additions & 1 deletion ibm/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import (
"regexp"
"strings"

"github.com/IBM-Cloud/bluemix-go/helpers"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
homedir "github.com/mitchellh/go-homedir"
gouuid "github.com/satori/go.uuid"

"github.com/IBM-Cloud/bluemix-go/helpers"
)

var (
Expand Down Expand Up @@ -935,3 +936,33 @@ func validateLBListenerConnectionLimit(v interface{}, k string) (ws []string, er
}
return
}

func validateISName(v interface{}, k string) (ws []string, errors []error) {
name := v.(string)
acceptedcharacters, _ := regexp.MatchString(`^[a-z][-a-z0-9]*$`, name)
endwithalphanumeric, _ := regexp.MatchString(`.*[a-z0-9]$`, name)
length := len(name)
if acceptedcharacters == true {
if length <= 40 {
if endwithalphanumeric == true {
if strings.Contains(name, "--") != true {
return
} else {
errors = append(errors, fmt.Errorf(
"%q (%q) should not contain consecutive dash(-)", k, v))
}
} else {
errors = append(errors, fmt.Errorf(
"%q (%q) should not end with dash(-) ", k, v))
}
} else {
errors = append(errors, fmt.Errorf(
"%q (%q) should not exceed 40 characters", k, v))
}

} else {
errors = append(errors, fmt.Errorf(
"%q (%q) should contain only lowercase alphanumeric,dash and should begin with lowercase character", k, v))
}
return
}

0 comments on commit 3bd0ff2

Please sign in to comment.