From b9d3362ecc013b0da832428b35fc510a0c98d8b6 Mon Sep 17 00:00:00 2001 From: Wonchul Lee Date: Wed, 23 Nov 2022 08:52:33 +0900 Subject: [PATCH 1/5] Add `ncloud_servers` data source resource --- docs/data-sources/servers.md | 47 +++++++ ncloud/data_source_ncloud_servers.go | 85 +++++++++++++ ncloud/data_source_ncloud_servers_test.go | 144 ++++++++++++++++++++++ 3 files changed, 276 insertions(+) create mode 100644 docs/data-sources/servers.md create mode 100644 ncloud/data_source_ncloud_servers.go create mode 100644 ncloud/data_source_ncloud_servers_test.go diff --git a/docs/data-sources/servers.md b/docs/data-sources/servers.md new file mode 100644 index 000000000..eac3f419a --- /dev/null +++ b/docs/data-sources/servers.md @@ -0,0 +1,47 @@ +# Data Source: ncloud_servers + +Use this data source to get multiple `ncloud_server` ids + +## Example Usage + +#### Basic usage + +```hcl +data "ncloud_servers" "servers" { + ids = [ncloud_server.example1.id, ncloud_server.example2.id] +} +``` + +#### Usage of using filter + +```hcl +data "ncloud_servers" "servers" { + filter { + name = "subnet_no" + values = [ncloud_subnet.example1.id, ncloud_subnet.example2.id] + } +} +``` + +#### Usage of `ncloud_servers` data source in `ncloud_nas_volume` + +```hcl +data "ncloud_servers" "servers" { + ids = [ncloud_server.example1.id, ncloud_server.example2.id] +} + +resource "ncloud_nas_volume" "vol" { + volume_name_postfix = "vol" + volume_size = "500" + volume_allotment_protocol_type = "NFS" + server_instance_no_list = data.ncloud_servers.servers.ids +} +``` + +The following arguments are supported: + +* `ids` - (Optional) The set of ID of the Server instances. +* `filter` - (Optional) Custom filter block as described below. + * `name` - (Required) The name of the field to filter by + * `values` - (Required) Set of values that are accepted for the given field. + * `regex` - (Optional) is `values` treated as a regular expression. diff --git a/ncloud/data_source_ncloud_servers.go b/ncloud/data_source_ncloud_servers.go new file mode 100644 index 000000000..a8d889419 --- /dev/null +++ b/ncloud/data_source_ncloud_servers.go @@ -0,0 +1,85 @@ +package ncloud + +import ( + "fmt" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func init() { + RegisterDataSource("ncloud_servers", dataSourceNcloudServers()) +} + +func dataSourceNcloudServers() *schema.Resource { + return &schema.Resource{ + Read: dataSourceNcloudServersRead, + Schema: map[string]*schema.Schema{ + "ids": { + Type: schema.TypeSet, + Optional: true, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "filter": dataSourceFiltersSchema(), + }, + } +} + +func dataSourceNcloudServersRead(d *schema.ResourceData, meta interface{}) error { + config := meta.(*ProviderConfig) + + instances, err := getServerList(d, config) + if err != nil { + return err + } + + if len(instances) < 1 { + return fmt.Errorf("no results. there is no available server resource") + } + + if values, ok := d.GetOk("ids"); ok { + return readServersIDs(d, values.(*schema.Set).List(), instances) + } + + resources := ConvertToArrayMap(instances) + if f, ok := d.GetOk("filter"); ok { + resources = ApplyFilters(f.(*schema.Set), resources, dataSourceNcloudServer().Schema) + } + + if len(resources) == 0 { + return fmt.Errorf("no results with filter. there is no available server resource") + } + + var ids []string + for _, r := range resources { + for k, v := range r { + if k == "instance_no" { + ids = append(ids, v.(string)) + } + } + } + + d.SetId(dataResourceIdHash(ids)) + d.Set("ids", ids) + return nil +} + +func readServersIDs(d *schema.ResourceData, values []interface{}, serverInstances []*ServerInstance) error { + var ids []string + for _, id := range values { + for _, s := range serverInstances { + if *s.ServerInstanceNo == id.(string) { + ids = append(ids, id.(string)) + break + } + } + } + + if len(values) != len(ids) { + return fmt.Errorf("invalid server id specified") + } + + d.SetId(dataResourceIdHash(ids)) + d.Set("ids", ids) + return nil +} diff --git a/ncloud/data_source_ncloud_servers_test.go b/ncloud/data_source_ncloud_servers_test.go new file mode 100644 index 000000000..3f5cd5ba1 --- /dev/null +++ b/ncloud/data_source_ncloud_servers_test.go @@ -0,0 +1,144 @@ +package ncloud + +import ( + "fmt" + "regexp" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +const ( + dataName = "data.ncloud_servers.by_id" + dataName2 = "data.ncloud_servers.by_filter" + serverName = "ncloud_server.test" +) + +func TestAccDataSourceNcloudServers_vpc_basic(t *testing.T) { + testServerName := getTestServerName() + testServerName2 := getTestServerName() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceServersVpcConfig(testServerName, testServerName2), + Check: resource.ComposeTestCheckFunc( + testAccCheckDataSourceID(dataName), + resource.TestMatchResourceAttr(dataName, "id", regexp.MustCompile(`^\d+$`)), + resource.TestCheckResourceAttr(dataName, "ids.#", "2"), + testAccCheckDataSourceID(dataName2), + resource.TestCheckResourceAttr(dataName2, "ids.#", "1"), + resource.TestCheckResourceAttrPair(dataName2, "ids.0", serverName, "id"), + ), + }, + }, + }) +} + +func TestAccDataSourceNcloudServers_classic_basic(t *testing.T) { + testServerName := getTestServerName() + testServerName2 := getTestServerName() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccClassicProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceServersClassicConfig(testServerName, testServerName2), + Check: resource.ComposeTestCheckFunc( + testAccCheckDataSourceID(dataName), + resource.TestMatchResourceAttr(dataName, "id", regexp.MustCompile(`^\d+$`)), + resource.TestCheckResourceAttr(dataName, "ids.#", "2"), + testAccCheckDataSourceID(dataName2), + resource.TestCheckResourceAttr(dataName2, "ids.#", "1"), + resource.TestCheckResourceAttrPair(dataName2, "ids.0", serverName, "id"), + ), + }, + }, + }) +} + +func testAccDataSourceServersVpcConfig(testServerName, testServerName2 string) string { + return fmt.Sprintf(` +resource "ncloud_login_key" "loginkey" { + key_name = "%[1]s-key" +} + +resource "ncloud_vpc" "test" { + name = "%[1]s" + ipv4_cidr_block = "10.5.0.0/16" +} + +resource "ncloud_subnet" "test" { + vpc_no = ncloud_vpc.test.vpc_no + name = "%[1]s" + subnet = "10.5.0.0/24" + zone = "KR-2" + network_acl_no = ncloud_vpc.test.default_network_acl_no + subnet_type = "PUBLIC" + usage_type = "GEN" +} + +resource "ncloud_server" "test" { + subnet_no = ncloud_subnet.test.id + name = "%[1]s" + server_image_product_code = "SW.VSVR.OS.LNX64.CNTOS.0703.B050" + server_product_code = "SVR.VSVR.STAND.C002.M008.NET.HDD.B050.G002" + login_key_name = ncloud_login_key.loginkey.key_name +} + +resource "ncloud_server" "test2" { + subnet_no = ncloud_subnet.test.id + name = "%[2]s" + server_image_product_code = "SW.VSVR.OS.LNX64.CNTOS.0703.B050" + server_product_code = "SVR.VSVR.STAND.C002.M008.NET.HDD.B050.G002" + login_key_name = ncloud_login_key.loginkey.key_name +} + +data "ncloud_servers" "by_id" { + ids = [ncloud_server.test.id, ncloud_server.test2.id] +} + +data "ncloud_servers" "by_filter" { + filter { + name = "instance_no" + values = [ncloud_server.test.id] + } +} +`, testServerName, testServerName2) +} + +func testAccDataSourceServersClassicConfig(testServerName, testServerName2 string) string { + return fmt.Sprintf(` +resource "ncloud_login_key" "loginkey" { + key_name = "%[1]s-key" +} + +resource "ncloud_server" "test" { + name = "%[1]s" + server_image_product_code = "SPSW0LINUX000139" + server_product_code = "SPSVRSSD00000003" + login_key_name = "${ncloud_login_key.loginkey.key_name}" +} + +resource "ncloud_server" "test2" { + name = "%[2]s" + server_image_product_code = "SPSW0LINUX000139" + server_product_code = "SPSVRSSD00000003" + login_key_name = "${ncloud_login_key.loginkey.key_name}" +} + +data "ncloud_servers" "by_id" { + ids = [ncloud_server.test.id, ncloud_server.test2.id] +} + +data "ncloud_servers" "by_filter" { + filter { + name = "instance_no" + values = [ncloud_server.test.id] + } +} +`, testServerName, testServerName2) +} From 5d2e5978e80dff56fb6ca2524a6d3737884e0581 Mon Sep 17 00:00:00 2001 From: yoogle Date: Wed, 23 Nov 2022 16:40:44 +0900 Subject: [PATCH 2/5] feat: support protocol number --- go.mod | 2 +- go.sum | 4 +- ...source_ncloud_access_control_group_rule.go | 42 +++++++++++++++++-- 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 47e369274..7898f48b9 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/terraform-providers/terraform-provider-ncloud go 1.16 require ( - github.com/NaverCloudPlatform/ncloud-sdk-go-v2 v1.5.3 + github.com/NaverCloudPlatform/ncloud-sdk-go-v2 v1.5.5 github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 github.com/hashicorp/terraform-plugin-sdk/v2 v2.13.0 gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c diff --git a/go.sum b/go.sum index 1039410d9..450dbee3b 100644 --- a/go.sum +++ b/go.sum @@ -4,8 +4,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03 github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA= github.com/Microsoft/go-winio v0.4.16 h1:FtSW/jqD+l4ba5iPBj9CODVtgfYAD8w2wS923g/cFDk= github.com/Microsoft/go-winio v0.4.16/go.mod h1:XB6nPKklQyQ7GC9LdcBEcBl8PF76WugXOPRXwdLnMv0= -github.com/NaverCloudPlatform/ncloud-sdk-go-v2 v1.5.3 h1:0xKNV67NN6Dnra8Ycvdrd7jig2IrNlQAjsk6Iq9ICPA= -github.com/NaverCloudPlatform/ncloud-sdk-go-v2 v1.5.3/go.mod h1:KWd9AT+YSM6qgsMzPnE23h2/r0bsPSIdJzZIg3BUcfI= +github.com/NaverCloudPlatform/ncloud-sdk-go-v2 v1.5.5 h1:HJijRCjpGph/VXR5X4/u8D0++RmugpGg54KlB5CKJ9M= +github.com/NaverCloudPlatform/ncloud-sdk-go-v2 v1.5.5/go.mod h1:KWd9AT+YSM6qgsMzPnE23h2/r0bsPSIdJzZIg3BUcfI= github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 h1:YoJbenK9C67SkzkDfmQuVln04ygHj3vjZfd9FL+GmQQ= github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7/go.mod h1:z4/9nQmJSSwwds7ejkxaJwO37dru3geImFUdJlaLzQo= github.com/acomagu/bufpipe v1.0.3 h1:fxAGrHZTgQ9w5QqVItgzwj235/uYZYgbXitB+dLupOk= diff --git a/ncloud/resource_ncloud_access_control_group_rule.go b/ncloud/resource_ncloud_access_control_group_rule.go index ab0a64b1b..cdef6454c 100644 --- a/ncloud/resource_ncloud_access_control_group_rule.go +++ b/ncloud/resource_ncloud_access_control_group_rule.go @@ -8,6 +8,8 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "log" + "regexp" + "strconv" "time" ) @@ -36,7 +38,8 @@ func resourceNcloudAccessControlGroupRule() *schema.Resource { "protocol": { Type: schema.TypeString, Required: true, - ValidateDiagFunc: ToDiagFunc(validation.StringInSlice([]string{"TCP", "UDP", "ICMP"}, false)), + ValidateDiagFunc: ToDiagFunc(validation.StringMatch(regexp.MustCompile(`TCP|UDP|ICMP|\b([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-2])\b`), "only TCP, UDP, ICMP and 1-252 are valid values.")), + StateFunc: ProtocolStateFunc, }, "port_range": { Type: schema.TypeString, @@ -73,7 +76,8 @@ func resourceNcloudAccessControlGroupRule() *schema.Resource { "protocol": { Type: schema.TypeString, Required: true, - ValidateDiagFunc: ToDiagFunc(validation.StringInSlice([]string{"TCP", "UDP", "ICMP"}, false)), + ValidateDiagFunc: ToDiagFunc(validation.StringMatch(regexp.MustCompile(`TCP|UDP|ICMP|\b([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-2])\b`), "only TCP, UDP, ICMP and 1-252 are valid values.")), + StateFunc: ProtocolStateFunc, }, "port_range": { Type: schema.TypeString, @@ -148,8 +152,15 @@ func resourceNcloudAccessControlGroupRuleRead(d *schema.ResourceData, meta inter oSet := schema.NewSet(schema.HashResource(resourceNcloudAccessControlGroupRule().Schema["outbound"].Elem.(*schema.Resource)), []interface{}{}) for _, r := range rules { + var protocol string + if allowedProtocolCodes[*r.ProtocolType.Code] { + protocol = *r.ProtocolType.Code + } else { + protocol = strconv.Itoa(int(*r.ProtocolType.Number)) + } + m := map[string]interface{}{ - "protocol": *r.ProtocolType.Code, + "protocol": protocol, "port_range": *r.PortRange, "ip_block": *r.IpBlock, "source_access_control_group_no": *r.AccessControlGroupSequence, @@ -444,3 +455,28 @@ func expandRemoveAccessControlGroupRule(rules []interface{}) []*vserver.RemoveAc return acgRuleList } + +var allowedProtocolCodes = map[string]bool{ + "TCP": true, + "UDP": true, + "ICMP": true, +} + +var allowedProtocolNumbers = map[int]string{ + 6: "TCP", + 17: "UDP", + 1: "ICMP", +} + +func ProtocolStateFunc(v interface{}) string { + switch v := v.(type) { + case string: + if number, err := strconv.Atoi(v); err == nil { + if code, ok := allowedProtocolNumbers[number]; ok { + return code + } + } + return v + } + return "" +} From 04ebceb906cf9203d406d8ee4398fa23d6783090 Mon Sep 17 00:00:00 2001 From: yoogle Date: Tue, 29 Nov 2022 11:29:53 +0900 Subject: [PATCH 3/5] feat: add tcp, udp, icmp protocol number validation --- ...source_ncloud_access_control_group_rule.go | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/ncloud/resource_ncloud_access_control_group_rule.go b/ncloud/resource_ncloud_access_control_group_rule.go index cdef6454c..78515d5a4 100644 --- a/ncloud/resource_ncloud_access_control_group_rule.go +++ b/ncloud/resource_ncloud_access_control_group_rule.go @@ -36,10 +36,13 @@ func resourceNcloudAccessControlGroupRule() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "protocol": { - Type: schema.TypeString, - Required: true, - ValidateDiagFunc: ToDiagFunc(validation.StringMatch(regexp.MustCompile(`TCP|UDP|ICMP|\b([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-2])\b`), "only TCP, UDP, ICMP and 1-252 are valid values.")), - StateFunc: ProtocolStateFunc, + Type: schema.TypeString, + Required: true, + ValidateDiagFunc: ToDiagFunc(validation.All( + validation.StringMatch(regexp.MustCompile(`TCP|UDP|ICMP|\b([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-2])\b`), "only TCP, UDP, ICMP and 1-252 are valid values."), + validation.StringNotInSlice([]string{"1", "6", "17"}, false), + )), + StateFunc: ProtocolStateFunc, }, "port_range": { Type: schema.TypeString, @@ -74,10 +77,13 @@ func resourceNcloudAccessControlGroupRule() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "protocol": { - Type: schema.TypeString, - Required: true, - ValidateDiagFunc: ToDiagFunc(validation.StringMatch(regexp.MustCompile(`TCP|UDP|ICMP|\b([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-2])\b`), "only TCP, UDP, ICMP and 1-252 are valid values.")), - StateFunc: ProtocolStateFunc, + Type: schema.TypeString, + Required: true, + ValidateDiagFunc: ToDiagFunc(validation.All( + validation.StringMatch(regexp.MustCompile(`TCP|UDP|ICMP|\b([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-2])\b`), "only TCP, UDP, ICMP and 1-252 are valid values."), + validation.StringNotInSlice([]string{"1", "6", "17"}, false), + )), + StateFunc: ProtocolStateFunc, }, "port_range": { Type: schema.TypeString, From 09c6fdc07d50ad536740b8aeff238d8f74601894 Mon Sep 17 00:00:00 2001 From: Sungminlee Date: Tue, 29 Nov 2022 14:35:12 +0900 Subject: [PATCH 4/5] add_bm_attribute --- go.mod | 2 +- go.sum | 4 ++-- ncloud/data_source_ncloud_server_image.go | 5 +++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 47e369274..7898f48b9 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/terraform-providers/terraform-provider-ncloud go 1.16 require ( - github.com/NaverCloudPlatform/ncloud-sdk-go-v2 v1.5.3 + github.com/NaverCloudPlatform/ncloud-sdk-go-v2 v1.5.5 github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 github.com/hashicorp/terraform-plugin-sdk/v2 v2.13.0 gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c diff --git a/go.sum b/go.sum index 1039410d9..450dbee3b 100644 --- a/go.sum +++ b/go.sum @@ -4,8 +4,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03 github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA= github.com/Microsoft/go-winio v0.4.16 h1:FtSW/jqD+l4ba5iPBj9CODVtgfYAD8w2wS923g/cFDk= github.com/Microsoft/go-winio v0.4.16/go.mod h1:XB6nPKklQyQ7GC9LdcBEcBl8PF76WugXOPRXwdLnMv0= -github.com/NaverCloudPlatform/ncloud-sdk-go-v2 v1.5.3 h1:0xKNV67NN6Dnra8Ycvdrd7jig2IrNlQAjsk6Iq9ICPA= -github.com/NaverCloudPlatform/ncloud-sdk-go-v2 v1.5.3/go.mod h1:KWd9AT+YSM6qgsMzPnE23h2/r0bsPSIdJzZIg3BUcfI= +github.com/NaverCloudPlatform/ncloud-sdk-go-v2 v1.5.5 h1:HJijRCjpGph/VXR5X4/u8D0++RmugpGg54KlB5CKJ9M= +github.com/NaverCloudPlatform/ncloud-sdk-go-v2 v1.5.5/go.mod h1:KWd9AT+YSM6qgsMzPnE23h2/r0bsPSIdJzZIg3BUcfI= github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 h1:YoJbenK9C67SkzkDfmQuVln04ygHj3vjZfd9FL+GmQQ= github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7/go.mod h1:z4/9nQmJSSwwds7ejkxaJwO37dru3geImFUdJlaLzQo= github.com/acomagu/bufpipe v1.0.3 h1:fxAGrHZTgQ9w5QqVItgzwj235/uYZYgbXitB+dLupOk= diff --git a/ncloud/data_source_ncloud_server_image.go b/ncloud/data_source_ncloud_server_image.go index 7bbda2cd9..74767abb0 100644 --- a/ncloud/data_source_ncloud_server_image.go +++ b/ncloud/data_source_ncloud_server_image.go @@ -170,8 +170,9 @@ func getVpcServerImageProductList(d *schema.ResourceData, config *ProviderConfig regionCode := config.RegionCode reqParams := &vserver.GetServerImageProductListRequest{ - ProductCode: StringPtrOrNil(d.GetOk("product_code")), - RegionCode: ®ionCode, + ProductCode: StringPtrOrNil(d.GetOk("product_code")), + RegionCode: ®ionCode, + InfraResourceDetailTypeCode: StringPtrOrNil(d.GetOk("infra_resource_detail_type_code")), } if v, ok := d.GetOk("platform_type"); ok { From 33811bb83727949e8412a3e18d56f7ddb78a7470 Mon Sep 17 00:00:00 2001 From: yoogle Date: Tue, 29 Nov 2022 16:40:55 +0900 Subject: [PATCH 5/5] feat: remove protocol state function --- ...source_ncloud_access_control_group_rule.go | 21 ------------------- 1 file changed, 21 deletions(-) diff --git a/ncloud/resource_ncloud_access_control_group_rule.go b/ncloud/resource_ncloud_access_control_group_rule.go index 78515d5a4..eb3da12e8 100644 --- a/ncloud/resource_ncloud_access_control_group_rule.go +++ b/ncloud/resource_ncloud_access_control_group_rule.go @@ -42,7 +42,6 @@ func resourceNcloudAccessControlGroupRule() *schema.Resource { validation.StringMatch(regexp.MustCompile(`TCP|UDP|ICMP|\b([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-2])\b`), "only TCP, UDP, ICMP and 1-252 are valid values."), validation.StringNotInSlice([]string{"1", "6", "17"}, false), )), - StateFunc: ProtocolStateFunc, }, "port_range": { Type: schema.TypeString, @@ -83,7 +82,6 @@ func resourceNcloudAccessControlGroupRule() *schema.Resource { validation.StringMatch(regexp.MustCompile(`TCP|UDP|ICMP|\b([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-2])\b`), "only TCP, UDP, ICMP and 1-252 are valid values."), validation.StringNotInSlice([]string{"1", "6", "17"}, false), )), - StateFunc: ProtocolStateFunc, }, "port_range": { Type: schema.TypeString, @@ -467,22 +465,3 @@ var allowedProtocolCodes = map[string]bool{ "UDP": true, "ICMP": true, } - -var allowedProtocolNumbers = map[int]string{ - 6: "TCP", - 17: "UDP", - 1: "ICMP", -} - -func ProtocolStateFunc(v interface{}) string { - switch v := v.(type) { - case string: - if number, err := strconv.Atoi(v); err == nil { - if code, ok := allowedProtocolNumbers[number]; ok { - return code - } - } - return v - } - return "" -}