Skip to content

Commit ffbb1b3

Browse files
authored
adding name to route (#63)
fixes #62
1 parent 4c3c506 commit ffbb1b3

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ terraform import kong_service.<service_identifier> <service_id>
8181
## Routes
8282
```hcl
8383
resource "kong_route" "route" {
84+
name = "MyRoute"
8485
protocols = [ "http", "https" ]
8586
methods = [ "GET", "POST" ]
8687
hosts = [ "example2.com" ]

kong/resource_kong_route.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ func resourceKongRoute() *schema.Resource {
1818
},
1919

2020
Schema: map[string]*schema.Schema{
21+
"name": &schema.Schema{
22+
Type: schema.TypeString,
23+
Optional: true,
24+
ForceNew: false,
25+
},
2126
"protocols": &schema.Schema{
2227
Type: schema.TypeList,
2328
Required: true,
@@ -146,6 +151,9 @@ func resourceKongRouteRead(d *schema.ResourceData, meta interface{}) error {
146151
if route == nil {
147152
d.SetId("")
148153
} else {
154+
if route.Name != nil {
155+
d.Set("name", route.Name)
156+
}
149157
if route.Protocols != nil {
150158
d.Set("protocols", gokong.StringValueSlice(route.Protocols))
151159
}
@@ -208,6 +216,7 @@ func resourceKongRouteDelete(d *schema.ResourceData, meta interface{}) error {
208216

209217
func createKongRouteRequestFromResourceData(d *schema.ResourceData) *gokong.RouteRequest {
210218
return &gokong.RouteRequest{
219+
Name: readStringPtrFromResource(d, "name"),
211220
Protocols: readStringArrayPtrFromResource(d, "protocols"),
212221
Methods: readStringArrayPtrFromResource(d, "methods"),
213222
Hosts: readStringArrayPtrFromResource(d, "hosts"),

kong/resource_kong_route_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ func TestAccKongRoute(t *testing.T) {
1818
Config: testCreateRouteConfig,
1919
Check: resource.ComposeTestCheckFunc(
2020
testAccCheckKongRouteExists("kong_route.route"),
21+
resource.TestCheckResourceAttr("kong_route.route", "name", "foo"),
2122
resource.TestCheckResourceAttr("kong_route.route", "protocols.0", "http"),
2223
resource.TestCheckResourceAttr("kong_route.route", "methods.0", "GET"),
2324
resource.TestCheckResourceAttr("kong_route.route", "hosts.0", "example.com"),
@@ -31,6 +32,7 @@ func TestAccKongRoute(t *testing.T) {
3132
Config: testUpdateRouteConfig,
3233
Check: resource.ComposeTestCheckFunc(
3334
testAccCheckKongRouteExists("kong_route.route"),
35+
resource.TestCheckResourceAttr("kong_route.route", "name", "bar"),
3436
resource.TestCheckResourceAttr("kong_route.route", "protocols.0", "http"),
3537
resource.TestCheckResourceAttr("kong_route.route", "protocols.1", "https"),
3638
resource.TestCheckResourceAttr("kong_route.route", "methods.0", "GET"),
@@ -156,6 +158,7 @@ resource "kong_service" "service" {
156158
}
157159
158160
resource "kong_route" "route" {
161+
name = "foo"
159162
protocols = [ "http" ]
160163
methods = [ "GET" ]
161164
hosts = [ "example.com" ]
@@ -174,6 +177,7 @@ resource "kong_service" "service" {
174177
}
175178
176179
resource "kong_route" "route" {
180+
name = "bar"
177181
protocols = [ "http", "https" ]
178182
methods = [ "GET", "POST" ]
179183
hosts = [ "example2.com" ]

0 commit comments

Comments
 (0)