From f424085f44bff1f4392455d57bf897707d071988 Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Thu, 25 Jun 2015 11:20:54 +0100 Subject: [PATCH] provider/aws: Add validation for aws_vpc.cidr_block - closes #2340 --- builtin/providers/aws/resource_aws_vpc.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/builtin/providers/aws/resource_aws_vpc.go b/builtin/providers/aws/resource_aws_vpc.go index 2ee2473b2..f8c5217cb 100644 --- a/builtin/providers/aws/resource_aws_vpc.go +++ b/builtin/providers/aws/resource_aws_vpc.go @@ -3,6 +3,7 @@ package aws import ( "fmt" "log" + "net" "time" "github.com/aws/aws-sdk-go/aws" @@ -24,6 +25,16 @@ func resourceAwsVpc() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, + ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) { + value := v.(string) + _, ipnet, err := net.ParseCIDR(value) + + if err != nil || ipnet == nil || value != ipnet.String() { + errors = append(errors, fmt.Errorf( + "%q must contain a valid CIDR", k)) + } + return + }, }, "instance_tenancy": &schema.Schema{