Skip to content

Commit 19b53d2

Browse files
committed
Merge branch 'master' of github.com:kevholditch/terraform-provider-kong
2 parents ba065a4 + b761b42 commit 19b53d2

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ provider "kong" {
2020
}
2121
```
2222

23+
Optionaly you can configure Username and Password for BasicAuth:
24+
```hcl
25+
provider "kong" {
26+
kong_admin_uri = "http://myKong:8001"
27+
kong_admin_username = "youruser"
28+
kong_admin_password = "yourpass"
29+
}
30+
```
31+
2332
By convention the provider will first check the env variable `KONG_ADMIN_ADDR` if that variable is not set then it will default to `http://localhost:8001` if
2433
you do not provide a provider block as above.
2534

kong/provider.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@ func Provider() terraform.ResourceProvider {
1616
DefaultFunc: envDefaultFuncWithDefault("KONG_ADMIN_ADDR", "http://localhost:8001"),
1717
Description: "The address of the kong admin url e.g. http://localhost:8001",
1818
},
19+
"kong_admin_usermame": &schema.Schema{
20+
Type: schema.TypeString,
21+
Optional: true,
22+
DefaultFunc: envDefaultFuncWithDefault("KONG_ADMIN_USERNAME", ""),
23+
Description: "An basic auth user for kong admin",
24+
},
25+
"kong_admin_password": &schema.Schema{
26+
Type: schema.TypeString,
27+
Optional: true,
28+
DefaultFunc: envDefaultFuncWithDefault("KONG_ADMIN_PASSWORD", ""),
29+
Description: "An basic auth password for kong admin",
30+
},
1931
},
2032

2133
ResourcesMap: map[string]*schema.Resource{
@@ -54,8 +66,18 @@ func envDefaultFuncWithDefault(key string, defaultValue string) schema.SchemaDef
5466
}
5567

5668
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
69+
username := ""
70+
if d.Get("kong_admin_username") != nil {
71+
username = d.Get("kong_admin_username").(string)
72+
}
73+
password := ""
74+
if d.Get("kong_admin_password") != nil {
75+
password = d.Get("kong_admin_password").(string)
76+
}
5777
config := &gokong.Config{
5878
HostAddress: d.Get("kong_admin_uri").(string),
79+
Username: username,
80+
Password: password,
5981
}
6082

6183
return gokong.NewClient(config), nil

kong/provider_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ func TestMain(m *testing.M) {
4040
if err != nil {
4141
log.Fatalf("Could not set kong host address env variable: %v", err)
4242
}
43+
err = os.Setenv(gokong.EnvKongAdminPassword, "AnUsername")
44+
if err != nil {
45+
log.Fatalf("Could not set kong admin username env variable: %v", err)
46+
}
47+
err = os.Setenv(gokong.EnvKongAdminPassword, "AnyPassword")
48+
if err != nil {
49+
log.Fatalf("Could not set kong admin password env variable: %v", err)
50+
}
4351

4452
code := m.Run()
4553

0 commit comments

Comments
 (0)