Skip to content

Commit 2510022

Browse files
authored
fix default int ptr values (#58)
* fix int ptr default which should be nil not 0 * fixing default port should be 80 not 0 * fixing default port on service - should be port 80 not 0 - int ptr was being returned as 0 not nil from resource
1 parent a9584a3 commit 2510022

File tree

3 files changed

+13
-51
lines changed

3 files changed

+13
-51
lines changed

kong/resource_kong_service.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ func resourceKongService() *schema.Resource {
3737
Type: schema.TypeInt,
3838
Optional: true,
3939
ForceNew: false,
40+
Default: 80,
4041
},
4142
"path": &schema.Schema{
4243
Type: schema.TypeString,

kong/resource_kong_service_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func TestAccKongService(t *testing.T) {
2121
resource.TestCheckResourceAttr("kong_service.service", "name", "test"),
2222
resource.TestCheckResourceAttr("kong_service.service", "protocol", "http"),
2323
resource.TestCheckResourceAttr("kong_service.service", "host", "test.org"),
24-
resource.TestCheckResourceAttr("kong_service.service", "port", "8080"),
24+
resource.TestCheckResourceAttr("kong_service.service", "port", "80"),
2525
resource.TestCheckResourceAttr("kong_service.service", "path", "/mypath"),
2626
resource.TestCheckResourceAttr("kong_service.service", "retries", "5"),
2727
resource.TestCheckResourceAttr("kong_service.service", "connect_timeout", "1000"),
@@ -121,7 +121,6 @@ resource "kong_service" "service" {
121121
name = "test"
122122
protocol = "http"
123123
host = "test.org"
124-
port = 8080
125124
path = "/mypath"
126125
retries = 5
127126
connect_timeout = 1000

kong/resource_reader.go

Lines changed: 11 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,6 @@ import (
55
"github.com/kevholditch/gokong"
66
)
77

8-
func readStringArrayFromResource(d *schema.ResourceData, key string) []string {
9-
10-
if attr, ok := d.GetOk(key); ok {
11-
var array []string
12-
items := attr.([]interface{})
13-
for _, x := range items {
14-
item := x.(string)
15-
array = append(array, item)
16-
}
17-
18-
return array
19-
}
20-
21-
return nil
22-
}
23-
248
func readStringArrayPtrFromResource(d *schema.ResourceData, key string) []*string {
259

2610
if attr, ok := d.GetOk(key); ok {
@@ -37,40 +21,24 @@ func readStringArrayPtrFromResource(d *schema.ResourceData, key string) []*strin
3721
return nil
3822
}
3923

40-
func readIntArrayFromResource(d *schema.ResourceData, key string) []int {
41-
42-
if attr, ok := d.GetOk(key); ok {
43-
var array []int
44-
items := attr.([]interface{})
45-
for _, x := range items {
46-
item := x.(int)
47-
array = append(array, item)
48-
}
49-
50-
return array
51-
}
52-
53-
return nil
54-
}
55-
5624
func readStringFromResource(d *schema.ResourceData, key string) string {
57-
if attr, ok := d.GetOk(key); ok {
58-
return attr.(string)
25+
if value, ok := d.GetOk(key); ok {
26+
return value.(string)
5927
}
6028
return ""
6129
}
6230

6331
func readIdPtrFromResource(d *schema.ResourceData, key string) *gokong.Id {
64-
if attr, ok := d.GetOk(key); ok {
65-
id := gokong.Id(attr.(string))
32+
if value, ok := d.GetOk(key); ok {
33+
id := gokong.Id(value.(string))
6634
return &id
6735
}
6836
return nil
6937
}
7038

7139
func readStringPtrFromResource(d *schema.ResourceData, key string) *string {
72-
if attr, ok := d.GetOk(key); ok {
73-
return gokong.String(attr.(string))
40+
if value, ok := d.GetOk(key); ok {
41+
return gokong.String(value.(string))
7442
}
7543
return nil
7644
}
@@ -80,22 +48,16 @@ func readBoolPtrFromResource(d *schema.ResourceData, key string) *bool {
8048
}
8149

8250
func readIntFromResource(d *schema.ResourceData, key string) int {
83-
if attr, ok := d.GetOk(key); ok {
84-
return attr.(int)
51+
if value, ok := d.GetOk(key); ok {
52+
return value.(int)
8553
}
8654
return 0
8755
}
8856

8957
func readIntPtrFromResource(d *schema.ResourceData, key string) *int {
90-
return gokong.Int(d.Get(key).(int))
91-
}
92-
93-
func readMapFromResource(d *schema.ResourceData, key string) map[string]interface{} {
94-
95-
if attr, ok := d.GetOk(key); ok {
96-
result := attr.(map[string]interface{})
97-
return result
58+
value, ok := d.GetOk(key)
59+
if ok {
60+
return gokong.Int(value.(int))
9861
}
99-
10062
return nil
10163
}

0 commit comments

Comments
 (0)