Skip to content

Commit 5121c7d

Browse files
Add support for auto-generated keys
The key doesn't need to be provided, in which case the plugin generates one for us. So mark the property as `computed` and add a test which checks that we get a value returned.
1 parent c689e4d commit 5121c7d

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

kong/resource_kong_consumer_key_auth.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ func resourceKongConsumerKeyAuth() *schema.Resource {
2424
"key": {
2525
Type: schema.TypeString,
2626
Optional: true,
27+
Computed: true,
2728
ForceNew: false,
2829
Sensitive: true,
2930
},

kong/resource_kong_consumer_key_auth_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,35 @@ func TestAccConsumerKeyAuth(t *testing.T) {
3939
})
4040
}
4141

42+
func TestAccConsumerKeyAuthComputed(t *testing.T) {
43+
44+
resource.Test(t, resource.TestCase{
45+
Providers: testAccProviders,
46+
CheckDestroy: testAccCheckConsumerKeyAuthDestroy,
47+
Steps: []resource.TestStep{
48+
{
49+
Config: testCreateConsumerKeyAuthConfigKeyComputed,
50+
Check: resource.ComposeTestCheckFunc(
51+
testAccCheckConsumerKeyAuthExists("kong_consumer_key_auth.consumer_key_auth"),
52+
resource.TestCheckResourceAttrSet("kong_consumer_key_auth.consumer_key_auth", "key"),
53+
resource.TestCheckResourceAttr("kong_consumer_key_auth.consumer_key_auth", "tags.#", "1"),
54+
resource.TestCheckResourceAttr("kong_consumer_key_auth.consumer_key_auth", "tags.0", "myTag"),
55+
),
56+
},
57+
{
58+
Config: testUpdateConsumerKeyAuthConfig,
59+
Check: resource.ComposeTestCheckFunc(
60+
testAccCheckConsumerKeyAuthExists("kong_consumer_key_auth.consumer_key_auth"),
61+
resource.TestCheckResourceAttr("kong_consumer_key_auth.consumer_key_auth", "key", "foo_updated"),
62+
resource.TestCheckResourceAttr("kong_consumer_key_auth.consumer_key_auth", "tags.#", "2"),
63+
resource.TestCheckResourceAttr("kong_consumer_key_auth.consumer_key_auth", "tags.0", "myTag"),
64+
resource.TestCheckResourceAttr("kong_consumer_key_auth.consumer_key_auth", "tags.1", "anotherTag"),
65+
),
66+
},
67+
},
68+
})
69+
}
70+
4271
func testAccCheckConsumerKeyAuthDestroy(state *terraform.State) error {
4372

4473
client := testAccProvider.Meta().(*config).adminClient.KeyAuths
@@ -125,3 +154,18 @@ resource "kong_consumer_key_auth" "consumer_key_auth" {
125154
tags = ["myTag", "anotherTag"]
126155
}
127156
`
157+
const testCreateConsumerKeyAuthConfigKeyComputed = `
158+
resource "kong_consumer" "my_consumer" {
159+
username = "User1"
160+
custom_id = "123"
161+
}
162+
163+
resource "kong_plugin" "key_auth_plugin" {
164+
name = "key-auth"
165+
}
166+
167+
resource "kong_consumer_key_auth" "consumer_key_auth" {
168+
consumer_id = "${kong_consumer.my_consumer.id}"
169+
tags = ["myTag"]
170+
}
171+
`

0 commit comments

Comments
 (0)