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

enhancement: Custom BYOIP changes #2355

Merged
merged 1 commit into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions ibm/resource_ibm_is_vpc_address_prefix.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ func resourceIBMISAddressPrefixValidator() *ResourceValidator {
Type: TypeString,
ForceNew: true,
Required: true})
validateSchema = append(validateSchema,
ValidateSchema{
Identifier: isVPCAddressPrefixCIDR,
ValidateFunctionIdentifier: ValidateOverlappingAddress,
Type: TypeString,
ForceNew: true,
Required: true})

ibmISAddressPrefixResourceValidator := ResourceValidator{ResourceName: "ibm_is_address_prefix", Schema: validateSchema}
return &ibmISAddressPrefixResourceValidator
Expand Down
34 changes: 34 additions & 0 deletions ibm/resource_ibm_is_vpc_address_prefix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package ibm
import (
"errors"
"fmt"
"regexp"
"testing"

"github.com/IBM/vpc-go-sdk/vpcclassicv1"
Expand Down Expand Up @@ -42,6 +43,26 @@ func TestAccIBMISVPCAddressPrefix_basic(t *testing.T) {
"ibm_is_vpc_address_prefix.testacc_vpc_address_prefix", "name", prefixName1),
),
},
{
Config: testAccCheckIBMISVPCAddressPrefixConfig1(name1, prefixName1),
ExpectError: regexp.MustCompile(fmt.Sprintf("the request is overlapping with reserved address ranges")),
},
},
})
}

func TestAccIBMISVPCAddressPrefix_InvalidCidr(t *testing.T) {
name1 := fmt.Sprintf("tfvpcuat-%d", acctest.RandIntRange(10, 100))
prefixName2 := fmt.Sprintf("tfaddprename-%d", acctest.RandIntRange(10, 100))

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccCheckIBMISVPCAddressPrefixConfig1(name1, prefixName2),
ExpectError: regexp.MustCompile(fmt.Sprintf("the request is overlapping with reserved address ranges")),
},
},
})
}
Expand Down Expand Up @@ -157,3 +178,16 @@ resource "ibm_is_vpc_address_prefix" "testacc_vpc_address_prefix" {
cidr = "%s"
}`, name, prefixName, ISZoneName, ISAddressPrefixCIDR)
}

func testAccCheckIBMISVPCAddressPrefixConfig1(name, prefixName string) string {
return fmt.Sprintf(`
resource "ibm_is_vpc" "testacc_vpc" {
name = "%s"
}
resource "ibm_is_vpc_address_prefix" "testacc_vpc_address_prefix" {
name = "%s"
zone = "%s"
vpc = "${ibm_is_vpc.testacc_vpc.id}"
cidr = "127.0.0.0/8"
}`, name, prefixName, ISZoneName)
}
2 changes: 1 addition & 1 deletion ibm/resource_ibm_is_vpc_routing_table_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func resourceIBMISVPCRoutingTableRoute() *schema.Resource {
func resourceIBMISVPCRoutingTableRouteValidator() *ResourceValidator {

validateSchema := make([]ValidateSchema, 2)
actionAllowedValues := "delegate, deliver, drop"
actionAllowedValues := "delegate, delegate_vpc, deliver, drop"

validateSchema = append(validateSchema,
ValidateSchema{
Expand Down
25 changes: 25 additions & 0 deletions ibm/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,28 @@ func validateCIDRAddress() schema.SchemaValidateFunc {
}
}

//validateOverlappingAddress...
func validateOverlappingAddress() schema.SchemaValidateFunc {
return func(v interface{}, k string) (ws []string, errors []error) {
nonOverlappingCIDR := map[string]bool{
"127.0.0.0/8": true,
"161.26.0.0/16": true,
"166.8.0.0/14": true,
"169.254.0.0/16": true,
"224.0.0.0/4": true,
}

address := v.(string)
_, found := nonOverlappingCIDR[address]
if found {
errors = append(errors, fmt.Errorf(
"%q the request is overlapping with reserved address ranges",
k))
}
return
}
}

//validateRemoteIP...
func validateRemoteIP(v interface{}, k string) (ws []string, errors []error) {
_, err1 := validateCIDR(v, k)
Expand Down Expand Up @@ -1068,6 +1090,7 @@ const (
ValidateJSONString
ValidateJSONParam
ValidateBindedPackageName
ValidateOverlappingAddress
)

// ValueType -- Copied from Terraform for now. You can refer to Terraform ValueType directly.
Expand Down Expand Up @@ -1234,6 +1257,8 @@ func invokeValidatorInternal(schema ValidateSchema) schema.SchemaValidateFunc {
return validateJSONString()
case ValidateBindedPackageName:
return validateBindedPackageName()
case ValidateOverlappingAddress:
return validateOverlappingAddress()

default:
return nil
Expand Down