Skip to content

Commit

Permalink
Merge branch 'master' of github.com:kevholditch/terraform-provider-kong
Browse files Browse the repository at this point in the history
  • Loading branch information
kevholditch committed Mar 20, 2018
2 parents ba065a4 + b761b42 commit 19b53d2
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ provider "kong" {
}
```

Optionaly you can configure Username and Password for BasicAuth:
```hcl
provider "kong" {
kong_admin_uri = "http://myKong:8001"
kong_admin_username = "youruser"
kong_admin_password = "yourpass"
}
```

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
you do not provide a provider block as above.

Expand Down
22 changes: 22 additions & 0 deletions kong/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ func Provider() terraform.ResourceProvider {
DefaultFunc: envDefaultFuncWithDefault("KONG_ADMIN_ADDR", "http://localhost:8001"),
Description: "The address of the kong admin url e.g. http://localhost:8001",
},
"kong_admin_usermame": &schema.Schema{
Type: schema.TypeString,
Optional: true,
DefaultFunc: envDefaultFuncWithDefault("KONG_ADMIN_USERNAME", ""),
Description: "An basic auth user for kong admin",
},
"kong_admin_password": &schema.Schema{
Type: schema.TypeString,
Optional: true,
DefaultFunc: envDefaultFuncWithDefault("KONG_ADMIN_PASSWORD", ""),
Description: "An basic auth password for kong admin",
},
},

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

func providerConfigure(d *schema.ResourceData) (interface{}, error) {
username := ""
if d.Get("kong_admin_username") != nil {
username = d.Get("kong_admin_username").(string)
}
password := ""
if d.Get("kong_admin_password") != nil {
password = d.Get("kong_admin_password").(string)
}
config := &gokong.Config{
HostAddress: d.Get("kong_admin_uri").(string),
Username: username,
Password: password,
}

return gokong.NewClient(config), nil
Expand Down
8 changes: 8 additions & 0 deletions kong/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ func TestMain(m *testing.M) {
if err != nil {
log.Fatalf("Could not set kong host address env variable: %v", err)
}
err = os.Setenv(gokong.EnvKongAdminPassword, "AnUsername")
if err != nil {
log.Fatalf("Could not set kong admin username env variable: %v", err)
}
err = os.Setenv(gokong.EnvKongAdminPassword, "AnyPassword")
if err != nil {
log.Fatalf("Could not set kong admin password env variable: %v", err)
}

code := m.Run()

Expand Down

0 comments on commit 19b53d2

Please sign in to comment.