From 3533a1d5231e334c684d210fbb679cf5cdd03101 Mon Sep 17 00:00:00 2001 From: Schuyler Jager Date: Tue, 18 Oct 2022 09:59:50 -0700 Subject: [PATCH 1/7] Refactor Valid4ByteAsn validation function to common lib, add to Core Network Policy Doc DS --- .../ec2/transitgateway_connect_peer.go | 2 +- internal/service/ec2/validate.go | 15 --------- internal/service/ec2/validate_test.go | 31 ------------------- .../service/ec2/vpnsite_customer_gateway.go | 2 +- ...ore_network_policy_document_data_source.go | 7 +++-- .../core_network_policy_model.go | 2 +- internal/verify/validate.go | 15 +++++++++ internal/verify/validate_test.go | 31 +++++++++++++++++++ 8 files changed, 53 insertions(+), 52 deletions(-) diff --git a/internal/service/ec2/transitgateway_connect_peer.go b/internal/service/ec2/transitgateway_connect_peer.go index a73c5101a35..c752332efe0 100644 --- a/internal/service/ec2/transitgateway_connect_peer.go +++ b/internal/service/ec2/transitgateway_connect_peer.go @@ -50,7 +50,7 @@ func ResourceTransitGatewayConnectPeer() *schema.Resource { Optional: true, Computed: true, ForceNew: true, - ValidateFunc: valid4ByteASN, + ValidateFunc: verify.Valid4ByteASN, }, "inside_cidr_blocks": { Type: schema.TypeSet, diff --git a/internal/service/ec2/validate.go b/internal/service/ec2/validate.go index 1e651c9610b..abe4b81514f 100644 --- a/internal/service/ec2/validate.go +++ b/internal/service/ec2/validate.go @@ -64,18 +64,3 @@ func validAmazonSideASN(v interface{}, k string) (ws []string, errors []error) { } return } - -func valid4ByteASN(v interface{}, k string) (ws []string, errors []error) { - value := v.(string) - - asn, err := strconv.ParseInt(value, 10, 64) - if err != nil { - errors = append(errors, fmt.Errorf("%q (%q) must be a 64-bit integer", k, v)) - return - } - - if asn < 0 || asn > 4294967295 { - errors = append(errors, fmt.Errorf("%q (%q) must be in the range 0 to 4294967295", k, v)) - } - return -} diff --git a/internal/service/ec2/validate_test.go b/internal/service/ec2/validate_test.go index 8d271ff8ac0..5bf3e49152d 100644 --- a/internal/service/ec2/validate_test.go +++ b/internal/service/ec2/validate_test.go @@ -74,34 +74,3 @@ func TestValidAmazonSideASN(t *testing.T) { } } } - -func TestValid4ByteASN(t *testing.T) { - validAsns := []string{ - "0", - "1", - "65534", - "65535", - "4294967294", - "4294967295", - } - for _, v := range validAsns { - _, errors := valid4ByteASN(v, "bgp_asn") - if len(errors) != 0 { - t.Fatalf("%q should be a valid ASN: %q", v, errors) - } - } - - invalidAsns := []string{ - "-1", - "ABCDEFG", - "", - "4294967296", - "9999999999", - } - for _, v := range invalidAsns { - _, errors := valid4ByteASN(v, "bgp_asn") - if len(errors) == 0 { - t.Fatalf("%q should be an invalid ASN", v) - } - } -} diff --git a/internal/service/ec2/vpnsite_customer_gateway.go b/internal/service/ec2/vpnsite_customer_gateway.go index 9fdd2f2ea57..55b0a32ed37 100644 --- a/internal/service/ec2/vpnsite_customer_gateway.go +++ b/internal/service/ec2/vpnsite_customer_gateway.go @@ -37,7 +37,7 @@ func ResourceCustomerGateway() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: valid4ByteASN, + ValidateFunc: verify.Valid4ByteASN, }, "certificate_arn": { Type: schema.TypeString, diff --git a/internal/service/networkmanager/core_network_policy_document_data_source.go b/internal/service/networkmanager/core_network_policy_document_data_source.go index 30ce32bc5a6..49db4319687 100644 --- a/internal/service/networkmanager/core_network_policy_document_data_source.go +++ b/internal/service/networkmanager/core_network_policy_document_data_source.go @@ -160,8 +160,9 @@ func DataSourceCoreNetworkPolicyDocument() *schema.Resource { ValidateFunc: verify.ValidRegionName, }, "asn": { - Type: schema.TypeInt, - Optional: true, + Type: schema.TypeString, + Optional: true, + ValidateFunc: verify.Valid4ByteASN, }, "inside_cidr_blocks": { Type: schema.TypeList, @@ -626,7 +627,7 @@ func expandDataCoreNetworkPolicyNetworkConfigurationEdgeLocations(tfList []inter } if v, ok := cfgEdgeLocation["asn"]; ok { - edgeLocation.Asn = v.(int) + edgeLocation.Asn = v.(string) } if cidrs := cfgEdgeLocation["inside_cidr_blocks"].([]interface{}); len(cidrs) > 0 { diff --git a/internal/service/networkmanager/core_network_policy_model.go b/internal/service/networkmanager/core_network_policy_model.go index 9adddac9f4d..6c6a1536ea4 100644 --- a/internal/service/networkmanager/core_network_policy_model.go +++ b/internal/service/networkmanager/core_network_policy_model.go @@ -64,7 +64,7 @@ type CoreNetworkPolicyCoreNetworkConfiguration struct { type CoreNetworkEdgeLocation struct { Location string `json:"location"` - Asn int `json:"asn,omitempty"` + Asn string `json:"asn,omitempty"` InsideCidrBlocks interface{} `json:"inside-cidr-blocks,omitempty"` } diff --git a/internal/verify/validate.go b/internal/verify/validate.go index a331a08de62..7d4dc49b917 100644 --- a/internal/verify/validate.go +++ b/internal/verify/validate.go @@ -20,6 +20,21 @@ var accountIDRegexp = regexp.MustCompile(`^(aws|aws-managed|\d{12})$`) var partitionRegexp = regexp.MustCompile(`^aws(-[a-z]+)*$`) var regionRegexp = regexp.MustCompile(`^[a-z]{2}(-[a-z]+)+-\d$`) +func Valid4ByteASN(v interface{}, k string) (ws []string, errors []error) { + value := v.(string) + + asn, err := strconv.ParseInt(value, 10, 64) + if err != nil { + errors = append(errors, fmt.Errorf("%q (%q) must be a 64-bit integer", k, v)) + return + } + + if asn < 0 || asn > 4294967295 { + errors = append(errors, fmt.Errorf("%q (%q) must be in the range 0 to 4294967295", k, v)) + } + return +} + func ValidARN(v interface{}, k string) (ws []string, errors []error) { value := v.(string) diff --git a/internal/verify/validate_test.go b/internal/verify/validate_test.go index 8f1db93a4e9..df126e31f9f 100644 --- a/internal/verify/validate_test.go +++ b/internal/verify/validate_test.go @@ -9,6 +9,37 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) +func TestValid4ByteASN(t *testing.T) { + validAsns := []string{ + "0", + "1", + "65534", + "65535", + "4294967294", + "4294967295", + } + for _, v := range validAsns { + _, errors := valid4ByteASN(v, "bgp_asn") + if len(errors) != 0 { + t.Fatalf("%q should be a valid ASN: %q", v, errors) + } + } + + invalidAsns := []string{ + "-1", + "ABCDEFG", + "", + "4294967296", + "9999999999", + } + for _, v := range invalidAsns { + _, errors := valid4ByteASN(v, "bgp_asn") + if len(errors) == 0 { + t.Fatalf("%q should be an invalid ASN", v) + } + } +} + func TestValidTypeStringNullableBoolean(t *testing.T) { testCases := []struct { val interface{} From a8289439ff487be042b983af56e85a7c189aa15b Mon Sep 17 00:00:00 2001 From: Schuyler Jager Date: Tue, 18 Oct 2022 11:28:29 -0700 Subject: [PATCH 2/7] Fix JSON validation for Core Network Policy Docs, Valid4ByteASN capitalization in validation tests --- .../core_network_policy_document_data_source_test.go | 4 ++-- internal/verify/validate_test.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/service/networkmanager/core_network_policy_document_data_source_test.go b/internal/service/networkmanager/core_network_policy_document_data_source_test.go index 25a001d4160..7f1541f1bfc 100644 --- a/internal/service/networkmanager/core_network_policy_document_data_source_test.go +++ b/internal/service/networkmanager/core_network_policy_document_data_source_test.go @@ -284,7 +284,7 @@ func testAccPolicyDocumentExpectedJSON() string { "edge-locations": [ { "location": "us-east-1", - "asn": 64555, + "asn": "64555", "inside-cidr-blocks": [ "2001:4860:F000::/40", "192.128.0.0/10", @@ -293,7 +293,7 @@ func testAccPolicyDocumentExpectedJSON() string { }, { "location": "eu-west-1", - "asn": 4200000001, + "asn": "4200000001", "inside-cidr-blocks": [ "2001:4860:E000::/40", "192.192.0.0/10" diff --git a/internal/verify/validate_test.go b/internal/verify/validate_test.go index df126e31f9f..b8c38d050f0 100644 --- a/internal/verify/validate_test.go +++ b/internal/verify/validate_test.go @@ -19,7 +19,7 @@ func TestValid4ByteASN(t *testing.T) { "4294967295", } for _, v := range validAsns { - _, errors := valid4ByteASN(v, "bgp_asn") + _, errors := Valid4ByteASN(v, "bgp_asn") if len(errors) != 0 { t.Fatalf("%q should be a valid ASN: %q", v, errors) } @@ -33,7 +33,7 @@ func TestValid4ByteASN(t *testing.T) { "9999999999", } for _, v := range invalidAsns { - _, errors := valid4ByteASN(v, "bgp_asn") + _, errors := Valid4ByteASN(v, "bgp_asn") if len(errors) == 0 { t.Fatalf("%q should be an invalid ASN", v) } From 4f9aebd78e5efa65df5357e404ee9f51972486bf Mon Sep 17 00:00:00 2001 From: Schuyler Jager Date: Fri, 21 Oct 2022 11:31:37 -0700 Subject: [PATCH 3/7] Split Valid4ByteASN into two functions for different input types, add changelog --- .changelog/27305.txt | 3 ++ .../ec2/transitgateway_connect_peer.go | 2 +- .../service/ec2/vpnsite_customer_gateway.go | 2 +- ...ore_network_policy_document_data_source.go | 4 +-- ...etwork_policy_document_data_source_test.go | 4 +-- .../core_network_policy_model.go | 2 +- internal/verify/validate.go | 6 ++++ internal/verify/validate_test.go | 35 +++++++++++++++++-- 8 files changed, 48 insertions(+), 10 deletions(-) create mode 100644 .changelog/27305.txt diff --git a/.changelog/27305.txt b/.changelog/27305.txt new file mode 100644 index 00000000000..499f79f8e2d --- /dev/null +++ b/.changelog/27305.txt @@ -0,0 +1,3 @@ +```release-note:note +Add plan-time validation for `aws_networkmanager_core_network_policy_document.core_network_configuration.edge_locations[].asn` +``` \ No newline at end of file diff --git a/internal/service/ec2/transitgateway_connect_peer.go b/internal/service/ec2/transitgateway_connect_peer.go index c752332efe0..9fe016eafba 100644 --- a/internal/service/ec2/transitgateway_connect_peer.go +++ b/internal/service/ec2/transitgateway_connect_peer.go @@ -50,7 +50,7 @@ func ResourceTransitGatewayConnectPeer() *schema.Resource { Optional: true, Computed: true, ForceNew: true, - ValidateFunc: verify.Valid4ByteASN, + ValidateFunc: verify.Valid4ByteASNString, }, "inside_cidr_blocks": { Type: schema.TypeSet, diff --git a/internal/service/ec2/vpnsite_customer_gateway.go b/internal/service/ec2/vpnsite_customer_gateway.go index 55b0a32ed37..e236fdd10ef 100644 --- a/internal/service/ec2/vpnsite_customer_gateway.go +++ b/internal/service/ec2/vpnsite_customer_gateway.go @@ -37,7 +37,7 @@ func ResourceCustomerGateway() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: verify.Valid4ByteASN, + ValidateFunc: verify.Valid4ByteASNString, }, "certificate_arn": { Type: schema.TypeString, diff --git a/internal/service/networkmanager/core_network_policy_document_data_source.go b/internal/service/networkmanager/core_network_policy_document_data_source.go index 49db4319687..bd0c21f0b79 100644 --- a/internal/service/networkmanager/core_network_policy_document_data_source.go +++ b/internal/service/networkmanager/core_network_policy_document_data_source.go @@ -160,7 +160,7 @@ func DataSourceCoreNetworkPolicyDocument() *schema.Resource { ValidateFunc: verify.ValidRegionName, }, "asn": { - Type: schema.TypeString, + Type: schema.TypeInt, Optional: true, ValidateFunc: verify.Valid4ByteASN, }, @@ -627,7 +627,7 @@ func expandDataCoreNetworkPolicyNetworkConfigurationEdgeLocations(tfList []inter } if v, ok := cfgEdgeLocation["asn"]; ok { - edgeLocation.Asn = v.(string) + edgeLocation.Asn = v.(int) } if cidrs := cfgEdgeLocation["inside_cidr_blocks"].([]interface{}); len(cidrs) > 0 { diff --git a/internal/service/networkmanager/core_network_policy_document_data_source_test.go b/internal/service/networkmanager/core_network_policy_document_data_source_test.go index 7f1541f1bfc..25a001d4160 100644 --- a/internal/service/networkmanager/core_network_policy_document_data_source_test.go +++ b/internal/service/networkmanager/core_network_policy_document_data_source_test.go @@ -284,7 +284,7 @@ func testAccPolicyDocumentExpectedJSON() string { "edge-locations": [ { "location": "us-east-1", - "asn": "64555", + "asn": 64555, "inside-cidr-blocks": [ "2001:4860:F000::/40", "192.128.0.0/10", @@ -293,7 +293,7 @@ func testAccPolicyDocumentExpectedJSON() string { }, { "location": "eu-west-1", - "asn": "4200000001", + "asn": 4200000001, "inside-cidr-blocks": [ "2001:4860:E000::/40", "192.192.0.0/10" diff --git a/internal/service/networkmanager/core_network_policy_model.go b/internal/service/networkmanager/core_network_policy_model.go index 6c6a1536ea4..9adddac9f4d 100644 --- a/internal/service/networkmanager/core_network_policy_model.go +++ b/internal/service/networkmanager/core_network_policy_model.go @@ -64,7 +64,7 @@ type CoreNetworkPolicyCoreNetworkConfiguration struct { type CoreNetworkEdgeLocation struct { Location string `json:"location"` - Asn string `json:"asn,omitempty"` + Asn int `json:"asn,omitempty"` InsideCidrBlocks interface{} `json:"inside-cidr-blocks,omitempty"` } diff --git a/internal/verify/validate.go b/internal/verify/validate.go index 7d4dc49b917..8b41af850af 100644 --- a/internal/verify/validate.go +++ b/internal/verify/validate.go @@ -21,6 +21,12 @@ var partitionRegexp = regexp.MustCompile(`^aws(-[a-z]+)*$`) var regionRegexp = regexp.MustCompile(`^[a-z]{2}(-[a-z]+)+-\d$`) func Valid4ByteASN(v interface{}, k string) (ws []string, errors []error) { + stringValue := strconv.Itoa(v.(int)) + + return Valid4ByteASNString(stringValue, k) +} + +func Valid4ByteASNString(v interface{}, k string) (ws []string, errors []error) { value := v.(string) asn, err := strconv.ParseInt(value, 10, 64) diff --git a/internal/verify/validate_test.go b/internal/verify/validate_test.go index b8c38d050f0..3a45db18cf3 100644 --- a/internal/verify/validate_test.go +++ b/internal/verify/validate_test.go @@ -9,7 +9,36 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) -func TestValid4ByteASN(t *testing.T) { +func TestValid4ByteAsn(t *testing.T) { + validAsns := []int{ + 0, + 1, + 65534, + 65535, + 4294967294, + 4294967295, + } + for _, v := range validAsns { + _, errors := Valid4ByteASN(v, "bgp_asn") + if len(errors) != 0 { + t.Fatalf("%q should be a valid ASN: %q", v, errors) + } + } + + invalidAsns := []int{ + -1, + 4294967296, + 9999999999, + } + for _, v := range invalidAsns { + _, errors := Valid4ByteASN(v, "bgp_asn") + if len(errors) == 0 { + t.Fatalf("%q should be an invalid ASN", v) + } + } +} + +func TestValid4ByteASNString(t *testing.T) { validAsns := []string{ "0", "1", @@ -19,7 +48,7 @@ func TestValid4ByteASN(t *testing.T) { "4294967295", } for _, v := range validAsns { - _, errors := Valid4ByteASN(v, "bgp_asn") + _, errors := Valid4ByteASNString(v, "bgp_asn") if len(errors) != 0 { t.Fatalf("%q should be a valid ASN: %q", v, errors) } @@ -33,7 +62,7 @@ func TestValid4ByteASN(t *testing.T) { "9999999999", } for _, v := range invalidAsns { - _, errors := Valid4ByteASN(v, "bgp_asn") + _, errors := Valid4ByteASNString(v, "bgp_asn") if len(errors) == 0 { t.Fatalf("%q should be an invalid ASN", v) } From 3f5165be00778f92456b1d9f450fa530994be09a Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Thu, 3 Nov 2022 09:12:28 -0400 Subject: [PATCH 4/7] Tweak CHANGELOG entry. --- .changelog/27305.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.changelog/27305.txt b/.changelog/27305.txt index 499f79f8e2d..aacb6dd7f1c 100644 --- a/.changelog/27305.txt +++ b/.changelog/27305.txt @@ -1,3 +1,3 @@ -```release-note:note -Add plan-time validation for `aws_networkmanager_core_network_policy_document.core_network_configuration.edge_locations[].asn` +```release-note:enhancement +data-source/aws_networkmanager_core_network_policy_document: Add plan-time validation for `core_network_configuration.edge_locations.asn` ``` \ No newline at end of file From 434ff35b2c7e4f27e18c010a116251845ec3ac9d Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Thu, 3 Nov 2022 09:23:58 -0400 Subject: [PATCH 5/7] d/aws_networkmanager_core_network_policy_document: 'core_network_configuration.edge_locations.asn' -> 'TypeString'. --- .../service/ec2/vpnsite_customer_gateway.go | 17 ++++++++++------- .../core_network_policy_document_data_source.go | 14 ++++++++++---- .../networkmanager/core_network_policy_model.go | 2 +- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/internal/service/ec2/vpnsite_customer_gateway.go b/internal/service/ec2/vpnsite_customer_gateway.go index e236fdd10ef..89bac58ea01 100644 --- a/internal/service/ec2/vpnsite_customer_gateway.go +++ b/internal/service/ec2/vpnsite_customer_gateway.go @@ -76,19 +76,22 @@ func resourceCustomerGatewayCreate(d *schema.ResourceData, meta interface{}) err defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig tags := defaultTagsConfig.MergeTags(tftags.New(d.Get("tags").(map[string]interface{}))) - i64BgpAsn, err := strconv.ParseInt(d.Get("bgp_asn").(string), 10, 64) - - if err != nil { - return err - } - input := &ec2.CreateCustomerGatewayInput{ - BgpAsn: aws.Int64(i64BgpAsn), IpAddress: aws.String(d.Get("ip_address").(string)), TagSpecifications: tagSpecificationsFromKeyValueTags(tags, ec2.ResourceTypeCustomerGateway), Type: aws.String(d.Get("type").(string)), } + if v, ok := d.GetOk("bgp_asn"); ok { + v, err := strconv.ParseInt(v.(string), 10, 64) + + if err != nil { + return err + } + + input.BgpAsn = aws.Int64(v) + } + if v, ok := d.GetOk("certificate_arn"); ok { input.CertificateArn = aws.String(v.(string)) } diff --git a/internal/service/networkmanager/core_network_policy_document_data_source.go b/internal/service/networkmanager/core_network_policy_document_data_source.go index bd0c21f0b79..8f8e8765e17 100644 --- a/internal/service/networkmanager/core_network_policy_document_data_source.go +++ b/internal/service/networkmanager/core_network_policy_document_data_source.go @@ -160,9 +160,9 @@ func DataSourceCoreNetworkPolicyDocument() *schema.Resource { ValidateFunc: verify.ValidRegionName, }, "asn": { - Type: schema.TypeInt, + Type: schema.TypeString, Optional: true, - ValidateFunc: verify.Valid4ByteASN, + ValidateFunc: verify.Valid4ByteASNString, }, "inside_cidr_blocks": { Type: schema.TypeList, @@ -626,8 +626,14 @@ func expandDataCoreNetworkPolicyNetworkConfigurationEdgeLocations(tfList []inter locMap[edgeLocation.Location] = struct{}{} } - if v, ok := cfgEdgeLocation["asn"]; ok { - edgeLocation.Asn = v.(int) + if v, ok := cfgEdgeLocation["asn"].(string); ok && v != "" { + v, err := strconv.ParseInt(v, 10, 64) + + if err != nil { + return nil, err + } + + edgeLocation.Asn = v } if cidrs := cfgEdgeLocation["inside_cidr_blocks"].([]interface{}); len(cidrs) > 0 { diff --git a/internal/service/networkmanager/core_network_policy_model.go b/internal/service/networkmanager/core_network_policy_model.go index 9adddac9f4d..a34d165d1f7 100644 --- a/internal/service/networkmanager/core_network_policy_model.go +++ b/internal/service/networkmanager/core_network_policy_model.go @@ -64,7 +64,7 @@ type CoreNetworkPolicyCoreNetworkConfiguration struct { type CoreNetworkEdgeLocation struct { Location string `json:"location"` - Asn int `json:"asn,omitempty"` + Asn int64 `json:"asn,omitempty"` InsideCidrBlocks interface{} `json:"inside-cidr-blocks,omitempty"` } From 0de69f801760b5b1200ab8858545124224488f16 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Thu, 3 Nov 2022 09:35:51 -0400 Subject: [PATCH 6/7] Remove 'verify.Valid4ByteASN'. --- internal/verify/validate.go | 6 ------ internal/verify/validate_test.go | 29 ----------------------------- 2 files changed, 35 deletions(-) diff --git a/internal/verify/validate.go b/internal/verify/validate.go index 8b41af850af..0d091480720 100644 --- a/internal/verify/validate.go +++ b/internal/verify/validate.go @@ -20,12 +20,6 @@ var accountIDRegexp = regexp.MustCompile(`^(aws|aws-managed|\d{12})$`) var partitionRegexp = regexp.MustCompile(`^aws(-[a-z]+)*$`) var regionRegexp = regexp.MustCompile(`^[a-z]{2}(-[a-z]+)+-\d$`) -func Valid4ByteASN(v interface{}, k string) (ws []string, errors []error) { - stringValue := strconv.Itoa(v.(int)) - - return Valid4ByteASNString(stringValue, k) -} - func Valid4ByteASNString(v interface{}, k string) (ws []string, errors []error) { value := v.(string) diff --git a/internal/verify/validate_test.go b/internal/verify/validate_test.go index 3a45db18cf3..721f61310e0 100644 --- a/internal/verify/validate_test.go +++ b/internal/verify/validate_test.go @@ -9,35 +9,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) -func TestValid4ByteAsn(t *testing.T) { - validAsns := []int{ - 0, - 1, - 65534, - 65535, - 4294967294, - 4294967295, - } - for _, v := range validAsns { - _, errors := Valid4ByteASN(v, "bgp_asn") - if len(errors) != 0 { - t.Fatalf("%q should be a valid ASN: %q", v, errors) - } - } - - invalidAsns := []int{ - -1, - 4294967296, - 9999999999, - } - for _, v := range invalidAsns { - _, errors := Valid4ByteASN(v, "bgp_asn") - if len(errors) == 0 { - t.Fatalf("%q should be an invalid ASN", v) - } - } -} - func TestValid4ByteASNString(t *testing.T) { validAsns := []string{ "0", From 2cf8aac0c848fbffea3e890f012e1f09afe0fb00 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Thu, 3 Nov 2022 09:36:57 -0400 Subject: [PATCH 7/7] 'verify.Valid4ByteASNString' -> 'verify.Valid4ByteASN'. --- internal/service/ec2/transitgateway_connect_peer.go | 2 +- internal/service/ec2/vpnsite_customer_gateway.go | 2 +- .../core_network_policy_document_data_source.go | 2 +- internal/verify/validate.go | 2 +- internal/verify/validate_test.go | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/service/ec2/transitgateway_connect_peer.go b/internal/service/ec2/transitgateway_connect_peer.go index 9fe016eafba..c752332efe0 100644 --- a/internal/service/ec2/transitgateway_connect_peer.go +++ b/internal/service/ec2/transitgateway_connect_peer.go @@ -50,7 +50,7 @@ func ResourceTransitGatewayConnectPeer() *schema.Resource { Optional: true, Computed: true, ForceNew: true, - ValidateFunc: verify.Valid4ByteASNString, + ValidateFunc: verify.Valid4ByteASN, }, "inside_cidr_blocks": { Type: schema.TypeSet, diff --git a/internal/service/ec2/vpnsite_customer_gateway.go b/internal/service/ec2/vpnsite_customer_gateway.go index 89bac58ea01..28680ed5d21 100644 --- a/internal/service/ec2/vpnsite_customer_gateway.go +++ b/internal/service/ec2/vpnsite_customer_gateway.go @@ -37,7 +37,7 @@ func ResourceCustomerGateway() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: verify.Valid4ByteASNString, + ValidateFunc: verify.Valid4ByteASN, }, "certificate_arn": { Type: schema.TypeString, diff --git a/internal/service/networkmanager/core_network_policy_document_data_source.go b/internal/service/networkmanager/core_network_policy_document_data_source.go index 8f8e8765e17..ccedee089ef 100644 --- a/internal/service/networkmanager/core_network_policy_document_data_source.go +++ b/internal/service/networkmanager/core_network_policy_document_data_source.go @@ -162,7 +162,7 @@ func DataSourceCoreNetworkPolicyDocument() *schema.Resource { "asn": { Type: schema.TypeString, Optional: true, - ValidateFunc: verify.Valid4ByteASNString, + ValidateFunc: verify.Valid4ByteASN, }, "inside_cidr_blocks": { Type: schema.TypeList, diff --git a/internal/verify/validate.go b/internal/verify/validate.go index 0d091480720..7d4dc49b917 100644 --- a/internal/verify/validate.go +++ b/internal/verify/validate.go @@ -20,7 +20,7 @@ var accountIDRegexp = regexp.MustCompile(`^(aws|aws-managed|\d{12})$`) var partitionRegexp = regexp.MustCompile(`^aws(-[a-z]+)*$`) var regionRegexp = regexp.MustCompile(`^[a-z]{2}(-[a-z]+)+-\d$`) -func Valid4ByteASNString(v interface{}, k string) (ws []string, errors []error) { +func Valid4ByteASN(v interface{}, k string) (ws []string, errors []error) { value := v.(string) asn, err := strconv.ParseInt(value, 10, 64) diff --git a/internal/verify/validate_test.go b/internal/verify/validate_test.go index 721f61310e0..5b04a40dffe 100644 --- a/internal/verify/validate_test.go +++ b/internal/verify/validate_test.go @@ -19,7 +19,7 @@ func TestValid4ByteASNString(t *testing.T) { "4294967295", } for _, v := range validAsns { - _, errors := Valid4ByteASNString(v, "bgp_asn") + _, errors := Valid4ByteASN(v, "bgp_asn") if len(errors) != 0 { t.Fatalf("%q should be a valid ASN: %q", v, errors) } @@ -33,7 +33,7 @@ func TestValid4ByteASNString(t *testing.T) { "9999999999", } for _, v := range invalidAsns { - _, errors := Valid4ByteASNString(v, "bgp_asn") + _, errors := Valid4ByteASN(v, "bgp_asn") if len(errors) == 0 { t.Fatalf("%q should be an invalid ASN", v) }