Skip to content

Commit

Permalink
adding name to route (#63)
Browse files Browse the repository at this point in the history
fixes #62
  • Loading branch information
kevholditch authored Feb 13, 2019
1 parent 4c3c506 commit ffbb1b3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ terraform import kong_service.<service_identifier> <service_id>
## Routes
```hcl
resource "kong_route" "route" {
name = "MyRoute"
protocols = [ "http", "https" ]
methods = [ "GET", "POST" ]
hosts = [ "example2.com" ]
Expand Down
9 changes: 9 additions & 0 deletions kong/resource_kong_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ func resourceKongRoute() *schema.Resource {
},

Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Type: schema.TypeString,
Optional: true,
ForceNew: false,
},
"protocols": &schema.Schema{
Type: schema.TypeList,
Required: true,
Expand Down Expand Up @@ -146,6 +151,9 @@ func resourceKongRouteRead(d *schema.ResourceData, meta interface{}) error {
if route == nil {
d.SetId("")
} else {
if route.Name != nil {
d.Set("name", route.Name)
}
if route.Protocols != nil {
d.Set("protocols", gokong.StringValueSlice(route.Protocols))
}
Expand Down Expand Up @@ -208,6 +216,7 @@ func resourceKongRouteDelete(d *schema.ResourceData, meta interface{}) error {

func createKongRouteRequestFromResourceData(d *schema.ResourceData) *gokong.RouteRequest {
return &gokong.RouteRequest{
Name: readStringPtrFromResource(d, "name"),
Protocols: readStringArrayPtrFromResource(d, "protocols"),
Methods: readStringArrayPtrFromResource(d, "methods"),
Hosts: readStringArrayPtrFromResource(d, "hosts"),
Expand Down
4 changes: 4 additions & 0 deletions kong/resource_kong_route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func TestAccKongRoute(t *testing.T) {
Config: testCreateRouteConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckKongRouteExists("kong_route.route"),
resource.TestCheckResourceAttr("kong_route.route", "name", "foo"),
resource.TestCheckResourceAttr("kong_route.route", "protocols.0", "http"),
resource.TestCheckResourceAttr("kong_route.route", "methods.0", "GET"),
resource.TestCheckResourceAttr("kong_route.route", "hosts.0", "example.com"),
Expand All @@ -31,6 +32,7 @@ func TestAccKongRoute(t *testing.T) {
Config: testUpdateRouteConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckKongRouteExists("kong_route.route"),
resource.TestCheckResourceAttr("kong_route.route", "name", "bar"),
resource.TestCheckResourceAttr("kong_route.route", "protocols.0", "http"),
resource.TestCheckResourceAttr("kong_route.route", "protocols.1", "https"),
resource.TestCheckResourceAttr("kong_route.route", "methods.0", "GET"),
Expand Down Expand Up @@ -156,6 +158,7 @@ resource "kong_service" "service" {
}
resource "kong_route" "route" {
name = "foo"
protocols = [ "http" ]
methods = [ "GET" ]
hosts = [ "example.com" ]
Expand All @@ -174,6 +177,7 @@ resource "kong_service" "service" {
}
resource "kong_route" "route" {
name = "bar"
protocols = [ "http", "https" ]
methods = [ "GET", "POST" ]
hosts = [ "example2.com" ]
Expand Down

0 comments on commit ffbb1b3

Please sign in to comment.