Skip to content

Commit 72f5351

Browse files
swillkhos2ow
authored andcommitted
Fixed a bug which results in errors reading PF Rules, LB Rules and Network ACLs (#75)
* fixed a bug with the errors reading port forwarding rules * fixed the Network ACL and LB Rule issues with type conversion from upstream * removed 'readIntFromString(valStr string)' as I removed the last reference to it
1 parent 21885fd commit 72f5351

File tree

4 files changed

+31
-42
lines changed

4 files changed

+31
-42
lines changed

cloudca/resource_cloudca.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55
"log"
66
"regexp"
7-
"strconv"
87

98
"github.com/cloud-ca/go-cloudca"
109
"github.com/cloud-ca/go-cloudca/api"
@@ -44,14 +43,6 @@ func isID(id string) bool {
4443
return re.MatchString(id)
4544
}
4645

47-
func readIntFromString(valStr string) int {
48-
var valInt int
49-
if valStr != "" {
50-
valInt, _ = strconv.Atoi(valStr)
51-
}
52-
return valInt
53-
}
54-
5546
// Provides a common, simple way to deal with 404s.
5647
func handleNotFoundError(entity string, deleted bool, err error, d *schema.ResourceData) error {
5748
if ccaError, ok := err.(api.CcaErrorResponse); ok {

cloudca/resource_cloudca_load_balancer_rule.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package cloudca
33
import (
44
"errors"
55
"fmt"
6-
"strconv"
76

87
"github.com/cloud-ca/go-cloudca"
98
"github.com/cloud-ca/go-cloudca/services/cloudca"
@@ -37,11 +36,12 @@ func resourceCloudcaLoadBalancerRule() *schema.Resource {
3736
Type: schema.TypeString,
3837
Required: true,
3938
ForceNew: true,
40-
Description: "The public IP to which the rule should be applied",
39+
Description: "ID of the public IP to which the rule should be applied",
4140
},
4241
"public_ip": {
43-
Type: schema.TypeString,
44-
Computed: true,
42+
Type: schema.TypeString,
43+
Computed: true,
44+
Description: "The public IP to which the rule should be applied",
4545
},
4646
"network_id": {
4747
Type: schema.TypeString,
@@ -61,13 +61,13 @@ func resourceCloudcaLoadBalancerRule() *schema.Resource {
6161
Description: "The algorithm used to load balance",
6262
},
6363
"public_port": {
64-
Type: schema.TypeInt,
64+
Type: schema.TypeString,
6565
Required: true,
6666
ForceNew: true,
6767
Description: "The port on the public IP",
6868
},
6969
"private_port": {
70-
Type: schema.TypeInt,
70+
Type: schema.TypeString,
7171
Required: true,
7272
ForceNew: true,
7373
Description: "The port to which the traffic will be load balanced internally",
@@ -105,8 +105,8 @@ func createLbr(d *schema.ResourceData, meta interface{}) error {
105105
NetworkId: d.Get("network_id").(string),
106106
Protocol: d.Get("protocol").(string),
107107
Algorithm: d.Get("algorithm").(string),
108-
PublicPort: strconv.Itoa(d.Get("public_port").(int)),
109-
PrivatePort: strconv.Itoa(d.Get("private_port").(int)),
108+
PublicPort: d.Get("public_port").(string),
109+
PrivatePort: d.Get("private_port").(string),
110110
}
111111

112112
_, instanceIdsPresent := d.GetOk("instance_ids")

cloudca/resource_cloudca_network_acl_rule.go

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package cloudca
22

33
import (
44
"fmt"
5-
"strconv"
65
"strings"
76

87
"github.com/cloud-ca/go-cloudca"
@@ -36,7 +35,7 @@ func resourceCloudcaNetworkACLRule() *schema.Resource {
3635
Description: "ID of environment where the network ACL rule should be created",
3736
},
3837
"rule_number": {
39-
Type: schema.TypeInt,
38+
Type: schema.TypeString,
4039
Required: true,
4140
Description: "The rule number of network ACL",
4241
},
@@ -71,22 +70,22 @@ func resourceCloudcaNetworkACLRule() *schema.Resource {
7170
},
7271
},
7372
"icmp_type": {
74-
Type: schema.TypeInt,
73+
Type: schema.TypeString,
7574
Optional: true,
7675
Description: "The ICMP type. Can only be used with ICMP protocol.",
7776
},
7877
"icmp_code": {
79-
Type: schema.TypeInt,
78+
Type: schema.TypeString,
8079
Optional: true,
8180
Description: "The ICMP code. Can only be used with ICMP protocol.",
8281
},
8382
"start_port": {
84-
Type: schema.TypeInt,
83+
Type: schema.TypeString,
8584
Optional: true,
8685
Description: "The start port. Can only be used with TCP/UDP protocol.",
8786
},
8887
"end_port": {
89-
Type: schema.TypeInt,
88+
Type: schema.TypeString,
9089
Optional: true,
9190
Description: "The end port. Can only be used with TCP/UDP protocol.",
9291
},
@@ -107,7 +106,7 @@ func resourceCloudcaNetworkACLRuleCreate(d *schema.ResourceData, meta interface{
107106
return rerr
108107
}
109108
aclRuleToCreate := cloudca.NetworkAclRule{
110-
RuleNumber: strconv.Itoa(d.Get("rule_number").(int)),
109+
RuleNumber: d.Get("rule_number").(string),
111110
Cidr: d.Get("cidr").(string),
112111
Action: d.Get("action").(string),
113112
Protocol: d.Get("protocol").(string),
@@ -139,7 +138,7 @@ func resourceCloudcaNetworkACLRuleUpdate(d *schema.ResourceData, meta interface{
139138
}
140139
aclRuleToUpdate := cloudca.NetworkAclRule{
141140
Id: d.Id(),
142-
RuleNumber: strconv.Itoa(d.Get("rule_number").(int)),
141+
RuleNumber: d.Get("rule_number").(string),
143142
Cidr: d.Get("cidr").(string),
144143
Action: d.Get("action").(string),
145144
Protocol: d.Get("protocol").(string),
@@ -182,19 +181,19 @@ func resourceCloudcaNetworkACLRuleRead(d *schema.ResourceData, meta interface{})
182181
return fmt.Errorf("Error reading Trigger: %s", err)
183182
}
184183

185-
if err := d.Set("icmp_type", readIntFromString(aclRule.IcmpType)); err != nil {
184+
if err := d.Set("icmp_type", aclRule.IcmpType); err != nil {
186185
return fmt.Errorf("Error reading Trigger: %s", err)
187186
}
188187

189-
if err := d.Set("icmp_code", readIntFromString(aclRule.IcmpCode)); err != nil {
188+
if err := d.Set("icmp_code", aclRule.IcmpCode); err != nil {
190189
return fmt.Errorf("Error reading Trigger: %s", err)
191190
}
192191

193-
if err := d.Set("start_port", readIntFromString(aclRule.StartPort)); err != nil {
192+
if err := d.Set("start_port", aclRule.StartPort); err != nil {
194193
return fmt.Errorf("Error reading Trigger: %s", err)
195194
}
196195

197-
if err := d.Set("end_port", readIntFromString(aclRule.EndPort)); err != nil {
196+
if err := d.Set("end_port", aclRule.EndPort); err != nil {
198197
return fmt.Errorf("Error reading Trigger: %s", err)
199198
}
200199

@@ -219,18 +218,18 @@ func resourceCloudcaNetworkACLRuleDelete(d *schema.ResourceData, meta interface{
219218

220219
func fillPortFields(d *schema.ResourceData, aclRule *cloudca.NetworkAclRule) {
221220
if v, ok := d.GetOk("start_port"); ok {
222-
aclRule.StartPort = strconv.Itoa(v.(int))
221+
aclRule.StartPort = v.(string)
223222
}
224223
if v, ok := d.GetOk("end_port"); ok {
225-
aclRule.EndPort = strconv.Itoa(v.(int))
224+
aclRule.EndPort = v.(string)
226225
}
227226
}
228227

229228
func fillIcmpFields(d *schema.ResourceData, aclRule *cloudca.NetworkAclRule) {
230229
if v, ok := d.GetOk("icmp_type"); ok {
231-
aclRule.IcmpType = strconv.Itoa(v.(int))
230+
aclRule.IcmpType = v.(string)
232231
}
233232
if v, ok := d.GetOk("icmp_code"); ok {
234-
aclRule.IcmpCode = strconv.Itoa(v.(int))
233+
aclRule.IcmpCode = v.(string)
235234
}
236235
}

cloudca/resource_cloudca_port_forwarding_rule.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package cloudca
22

33
import (
44
"fmt"
5-
"strconv"
65

76
"github.com/cloud-ca/go-cloudca"
87
"github.com/cloud-ca/go-cloudca/services/cloudca"
@@ -45,26 +44,26 @@ func resourceCloudcaPortForwardingRule() *schema.Resource {
4544
Description: "The protocol that this rule should use (eg. TCP, UDP)",
4645
},
4746
"private_port_start": {
48-
Type: schema.TypeInt,
47+
Type: schema.TypeString,
4948
Required: true,
5049
ForceNew: true,
5150
Description: "The start of the private port range for this rule",
5251
},
5352
"private_port_end": {
54-
Type: schema.TypeInt,
53+
Type: schema.TypeString,
5554
Optional: true,
5655
ForceNew: true,
5756
Computed: true,
5857
Description: "The end of the private port range for this rule",
5958
},
6059
"public_port_start": {
61-
Type: schema.TypeInt,
60+
Type: schema.TypeString,
6261
Required: true,
6362
ForceNew: true,
6463
Description: "The start of the public port range for this rule",
6564
},
6665
"public_port_end": {
67-
Type: schema.TypeInt,
66+
Type: schema.TypeString,
6867
Optional: true,
6968
ForceNew: true,
7069
Computed: true,
@@ -95,17 +94,17 @@ func createPortForwardingRule(d *schema.ResourceData, meta interface{}) error {
9594
pfr := cloudca.PortForwardingRule{
9695
PublicIpId: d.Get("public_ip_id").(string),
9796
Protocol: d.Get("protocol").(string),
98-
PublicPortStart: strconv.Itoa(d.Get("public_port_start").(int)),
97+
PublicPortStart: d.Get("public_port_start").(string),
9998
PrivateIpId: d.Get("private_ip_id").(string),
100-
PrivatePortStart: strconv.Itoa(d.Get("private_port_start").(int)),
99+
PrivatePortStart: d.Get("private_port_start").(string),
101100
}
102101

103102
if _, ok := d.GetOk("public_port_end"); ok {
104-
pfr.PublicPortEnd = strconv.Itoa(d.Get("public_port_end").(int))
103+
pfr.PublicPortEnd = d.Get("public_port_end").(string)
105104
}
106105

107106
if _, ok := d.GetOk("private_port_end"); ok {
108-
pfr.PrivatePortEnd = strconv.Itoa(d.Get("private_port_end").(int))
107+
pfr.PrivatePortEnd = d.Get("private_port_end").(string)
109108
}
110109

111110
newPfr, err := ccaResources.PortForwardingRules.Create(pfr)

0 commit comments

Comments
 (0)