Skip to content

Commit

Permalink
Merge pull request #138 from andrew-bulford-form3/fix-consumer-semi-o…
Browse files Browse the repository at this point in the history
…ptional-properties

Fix consumer creation with missing properties
  • Loading branch information
kevholditch-f3 authored Oct 8, 2021
2 parents d5e1e8f + 6896fc7 commit f3e7282
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
4 changes: 2 additions & 2 deletions kong/resource_kong_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ func resourceKongConsumer() *schema.Resource {
func resourceKongConsumerCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {

consumerRequest := &kong.Consumer{
Username: kong.String(d.Get("username").(string)),
CustomID: kong.String(d.Get("custom_id").(string)),
Username: NilString(d.Get("username").(string)),
CustomID: NilString(d.Get("custom_id").(string)),
Tags: readStringArrayPtrFromResource(d, "tags"),
}

Expand Down
26 changes: 26 additions & 0 deletions kong/resource_kong_consumer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,26 @@ func TestAccKongConsumer(t *testing.T) {
})
}

func TestAccKongConsumerNilIDs(t *testing.T) {

resource.Test(t, resource.TestCase{
Providers: testAccProviders,
CheckDestroy: testAccCheckKongConsumerDestroy,
Steps: []resource.TestStep{
{
Config: testCreateConsumerConfigNoCustomID,
Check: resource.ComposeTestCheckFunc(
testAccCheckKongConsumerExists("kong_consumer.consumer"),
resource.TestCheckResourceAttr("kong_consumer.consumer", "username", "User3"),
resource.TestCheckResourceAttr("kong_consumer.consumer", "custom_id", ""),
resource.TestCheckResourceAttr("kong_consumer.consumer", "tags.#", "1"),
resource.TestCheckResourceAttr("kong_consumer.consumer", "tags.0", "c"),
),
},
},
})
}

func TestAccKongConsumerImport(t *testing.T) {

resource.Test(t, resource.TestCase{
Expand Down Expand Up @@ -126,3 +146,9 @@ resource "kong_consumer" "consumer" {
tags = ["a"]
}
`
const testCreateConsumerConfigNoCustomID = `
resource "kong_consumer" "consumer" {
username = "User3"
tags = ["c"]
}
`
10 changes: 10 additions & 0 deletions kong/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,13 @@ func IDToString(v *string) string {
}
return *v
}

// NilString converts a string to a string pointer,
// or if empty returns nil.
func NilString(str string) *string {
if str == "" {
return nil
} else {
return kong.String(str)
}
}

0 comments on commit f3e7282

Please sign in to comment.