@@ -5,66 +5,65 @@ import (
5
5
"fmt"
6
6
"testing"
7
7
8
- "github.com/kong/go-kong/kong"
9
-
10
8
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
11
9
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
10
+ "github.com/kong/go-kong/kong"
12
11
)
13
12
14
- func TestAccConsumerBasicAuth (t * testing.T ) {
13
+ func TestAccConsumerKeyAuth (t * testing.T ) {
15
14
16
15
resource .Test (t , resource.TestCase {
17
16
Providers : testAccProviders ,
18
- CheckDestroy : testAccCheckConsumerBasicAuthDestroy ,
17
+ CheckDestroy : testAccCheckConsumerKeyAuthDestroy ,
19
18
Steps : []resource.TestStep {
20
19
{
21
- Config : testCreateConsumerBasicAuthConfig ,
20
+ Config : testCreateConsumerKeyAuthConfig ,
22
21
Check : resource .ComposeTestCheckFunc (
23
- testAccCheckConsumerBasicAuthExists ( "kong_consumer_basic_auth.consumer_basic_auth " ),
24
- resource .TestCheckResourceAttr ("kong_consumer_basic_auth.consumer_basic_auth " , "username " , "foo" ),
25
- resource .TestCheckResourceAttr ("kong_consumer_basic_auth.consumer_basic_auth " , "tags.#" , "1" ),
26
- resource .TestCheckResourceAttr ("kong_consumer_basic_auth.consumer_basic_auth " , "tags.0" , "myTag" ),
22
+ testAccCheckConsumerKeyAuthExists ( "kong_consumer_key_auth.consumer_key_auth " ),
23
+ resource .TestCheckResourceAttr ("kong_consumer_key_auth.consumer_key_auth " , "key " , "foo" ),
24
+ resource .TestCheckResourceAttr ("kong_consumer_key_auth.consumer_key_auth " , "tags.#" , "1" ),
25
+ resource .TestCheckResourceAttr ("kong_consumer_key_auth.consumer_key_auth " , "tags.0" , "myTag" ),
27
26
),
28
27
},
29
28
{
30
- Config : testUpdateConsumerBasicAuthConfig ,
29
+ Config : testUpdateConsumerKeyAuthConfig ,
31
30
Check : resource .ComposeTestCheckFunc (
32
- testAccCheckConsumerBasicAuthExists ( "kong_consumer_basic_auth.consumer_basic_auth " ),
33
- resource .TestCheckResourceAttr ("kong_consumer_basic_auth.consumer_basic_auth " , "username " , "foo_updated" ),
34
- resource .TestCheckResourceAttr ("kong_consumer_basic_auth.consumer_basic_auth " , "tags.#" , "2" ),
35
- resource .TestCheckResourceAttr ("kong_consumer_basic_auth.consumer_basic_auth " , "tags.0" , "myTag" ),
36
- resource .TestCheckResourceAttr ("kong_consumer_basic_auth.consumer_basic_auth " , "tags.1" , "anotherTag" ),
31
+ testAccCheckConsumerKeyAuthExists ( "kong_consumer_key_auth.consumer_key_auth " ),
32
+ resource .TestCheckResourceAttr ("kong_consumer_key_auth.consumer_key_auth " , "key " , "foo_updated" ),
33
+ resource .TestCheckResourceAttr ("kong_consumer_key_auth.consumer_key_auth " , "tags.#" , "2" ),
34
+ resource .TestCheckResourceAttr ("kong_consumer_key_auth.consumer_key_auth " , "tags.0" , "myTag" ),
35
+ resource .TestCheckResourceAttr ("kong_consumer_key_auth.consumer_key_auth " , "tags.1" , "anotherTag" ),
37
36
),
38
37
},
39
38
},
40
39
})
41
40
}
42
41
43
- func testAccCheckConsumerBasicAuthDestroy (state * terraform.State ) error {
42
+ func testAccCheckConsumerKeyAuthDestroy (state * terraform.State ) error {
44
43
45
- client := testAccProvider .Meta ().(* config ).adminClient .BasicAuths
44
+ client := testAccProvider .Meta ().(* config ).adminClient .KeyAuths
46
45
47
- resources := getResourcesByType ("kong_consumer_basic_auth " , state )
46
+ resources := getResourcesByType ("kong_consumer_key_auth " , state )
48
47
49
48
if len (resources ) != 1 {
50
- return fmt .Errorf ("expecting only 1 consumer basic auth resource found %v" , len (resources ))
49
+ return fmt .Errorf ("expecting only 1 consumer key auth resource found %v" , len (resources ))
51
50
}
52
51
53
52
id , err := splitConsumerID (resources [0 ].Primary .ID )
54
- ConsumerBasicAuth , err := client .Get (context .Background (), kong .String (id .ConsumerID ), kong .String (id .ID ))
53
+ ConsumerKeyAuth , err := client .Get (context .Background (), kong .String (id .ConsumerID ), kong .String (id .ID ))
55
54
56
55
if ! kong .IsNotFoundErr (err ) && err != nil {
57
56
return fmt .Errorf ("error calling get consumer auth by id: %v" , err )
58
57
}
59
58
60
- if ConsumerBasicAuth != nil {
61
- return fmt .Errorf ("jwt auth %s still exists, %+v" , id .ID , ConsumerBasicAuth )
59
+ if ConsumerKeyAuth != nil {
60
+ return fmt .Errorf ("key auth %s still exists, %+v" , id .ID , ConsumerKeyAuth )
62
61
}
63
62
64
63
return nil
65
64
}
66
65
67
- func testAccCheckConsumerBasicAuthExists (resourceKey string ) resource.TestCheckFunc {
66
+ func testAccCheckConsumerKeyAuthExists (resourceKey string ) resource.TestCheckFunc {
68
67
69
68
return func (s * terraform.State ) error {
70
69
rs , ok := s .RootModule ().Resources [resourceKey ]
@@ -77,54 +76,52 @@ func testAccCheckConsumerBasicAuthExists(resourceKey string) resource.TestCheckF
77
76
return fmt .Errorf ("no ID is set" )
78
77
}
79
78
80
- client := testAccProvider .Meta ().(* config ).adminClient .BasicAuths
79
+ client := testAccProvider .Meta ().(* config ).adminClient .KeyAuths
81
80
id , err := splitConsumerID (rs .Primary .ID )
82
81
83
- ConsumerBasicAuth , err := client .Get (context .Background (), kong .String (id .ConsumerID ), kong .String (id .ID ))
82
+ ConsumerKeyAuth , err := client .Get (context .Background (), kong .String (id .ConsumerID ), kong .String (id .ID ))
84
83
85
84
if err != nil {
86
85
return err
87
86
}
88
87
89
- if ConsumerBasicAuth == nil {
90
- return fmt .Errorf ("ConsumerBasicAuth with id %v not found" , id .ID )
88
+ if ConsumerKeyAuth == nil {
89
+ return fmt .Errorf ("ConsumerKeyAuth with id %v not found" , id .ID )
91
90
}
92
91
93
92
return nil
94
93
}
95
94
}
96
95
97
- const testCreateConsumerBasicAuthConfig = `
96
+ const testCreateConsumerKeyAuthConfig = `
98
97
resource "kong_consumer" "my_consumer" {
99
98
username = "User1"
100
99
custom_id = "123"
101
100
}
102
101
103
- resource "kong_plugin" "basic_auth_plugin " {
104
- name = "basic -auth"
102
+ resource "kong_plugin" "key_auth_plugin " {
103
+ name = "key -auth"
105
104
}
106
105
107
- resource "kong_consumer_basic_auth" "consumer_basic_auth" {
108
- consumer_id = "${kong_consumer.my_consumer.id}"
109
- username = "foo"
110
- password = "bar"
111
- tags = ["myTag"]
106
+ resource "kong_consumer_key_auth" "consumer_key_auth" {
107
+ consumer_id = "${kong_consumer.my_consumer.id}"
108
+ key = "foo"
109
+ tags = ["myTag"]
112
110
}
113
111
`
114
- const testUpdateConsumerBasicAuthConfig = `
112
+ const testUpdateConsumerKeyAuthConfig = `
115
113
resource "kong_consumer" "my_consumer" {
116
114
username = "User1"
117
115
custom_id = "123"
118
116
}
119
117
120
- resource "kong_plugin" "basic_auth_plugin " {
121
- name = "basic -auth"
118
+ resource "kong_plugin" "key_auth_plugin " {
119
+ name = "key -auth"
122
120
}
123
121
124
- resource "kong_consumer_basic_auth" "consumer_basic_auth" {
125
- consumer_id = "${kong_consumer.my_consumer.id}"
126
- username = "foo_updated"
127
- password = "bar_updated"
128
- tags = ["myTag", "anotherTag"]
122
+ resource "kong_consumer_key_auth" "consumer_key_auth" {
123
+ consumer_id = "${kong_consumer.my_consumer.id}"
124
+ key = "foo_updated"
125
+ tags = ["myTag", "anotherTag"]
129
126
}
130
127
`
0 commit comments