Skip to content

Commit

Permalink
Support importing of plugins (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
tecnobrat authored and kevholditch committed Jun 30, 2018
1 parent 4cb9265 commit 5b50d68
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -23,6 +23,7 @@ website/node_modules
*.iml
*.test
*.iml
dist

website/vendor

Expand Down
4 changes: 4 additions & 0 deletions kong/resource_kong_consumer_plugin_config.go
Expand Up @@ -17,6 +17,10 @@ func resourceKongConsumerPluginConfig() *schema.Resource {
Read: resourceKongConsumerPluginConfigRead,
Delete: resourceKongConsumerPluginConfigDelete,

Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},

Schema: map[string]*schema.Schema{
"consumer_id": &schema.Schema{
Type: schema.TypeString,
Expand Down
58 changes: 58 additions & 0 deletions kong/resource_kong_consumer_plugin_config_test.go
Expand Up @@ -61,6 +61,25 @@ func TestAccKongConsumerPluginConfigKV(t *testing.T) {
})
}

func TestAccKongConsumerPluginConfigImport(t *testing.T) {

resource.Test(t, resource.TestCase{
Providers: testAccProviders,
CheckDestroy: testAccCheckKongConsumerPluginConfig,
Steps: []resource.TestStep{
resource.TestStep{
Config: testImportConsumerPluginConfigKV,
},

resource.TestStep{
ResourceName: "kong_consumer_plugin_config.consumer_acl_config",
ImportState: true,
ImportStateVerify: false,
},
},
})
}

func testAccCheckKongConsumerPluginConfig(state *terraform.State) error {

client := testAccProvider.Meta().(*gokong.KongAdminClient)
Expand Down Expand Up @@ -252,3 +271,42 @@ resource "kong_consumer_plugin_config" "consumer_acl_config" {
}
}
`

const testImportConsumerPluginConfigKV = `
resource "kong_api" "api" {
name = "TestApi"
hosts = [ "example.com" ]
uris = [ "/example" ]
methods = [ "GET", "POST" ]
upstream_url = "http://localhost:4140"
strip_uri = false
preserve_host = false
retries = 3
upstream_connect_timeout = 60000
upstream_send_timeout = 30000
upstream_read_timeout = 10000
https_only = false
http_if_terminated = false
}
resource "kong_consumer" "my_consumer" {
username = "User1"
custom_id = "123"
}
resource "kong_plugin" "acl_plugin" {
name = "acl"
api_id = "${kong_api.api.id}"
config = {
whitelist = "apache"
}
}
resource "kong_consumer_plugin_config" "consumer_acl_config" {
consumer_id = "${kong_consumer.my_consumer.id}"
plugin_name = "acls"
config = {
group = "apache"
}
}
`
4 changes: 4 additions & 0 deletions kong/resource_kong_plugin.go
Expand Up @@ -14,6 +14,10 @@ func resourceKongPlugin() *schema.Resource {
Delete: resourceKongPluginDelete,
Update: resourceKongPluginUpdate,

Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},

Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Type: schema.TypeString,
Expand Down
45 changes: 45 additions & 0 deletions kong/resource_kong_plugin_test.go
Expand Up @@ -129,6 +129,25 @@ func TestAccKongPluginForASpecificApiAndConsumer(t *testing.T) {
})
}

func TestAccKongPluginImport(t *testing.T) {

resource.Test(t, resource.TestCase{
Providers: testAccProviders,
CheckDestroy: testAccCheckKongPluginDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testImportPluginForASpecificApiConfig,
},

resource.TestStep{
ResourceName: "kong_plugin.basic_auth",
ImportState: true,
ImportStateVerify: false,
},
},
})
}

func testAccCheckKongPluginDestroy(state *terraform.State) error {

client := testAccProvider.Meta().(*gokong.KongAdminClient)
Expand Down Expand Up @@ -375,3 +394,29 @@ resource "kong_plugin" "rate_limit" {
}
}
`

const testImportPluginForASpecificApiConfig = `
resource "kong_api" "api" {
name = "TestApi"
hosts = [ "example.com" ]
uris = [ "/example" ]
methods = [ "GET", "POST" ]
upstream_url = "http://localhost:4140"
strip_uri = false
preserve_host = false
retries = 3
upstream_connect_timeout = 60000
upstream_send_timeout = 30000
upstream_read_timeout = 10000
https_only = false
http_if_terminated = false
}
resource "kong_plugin" "basic_auth" {
name = "basic-auth"
api_id = "${kong_api.api.id}"
config = {
hide_credentials = "false"
}
}
`

0 comments on commit 5b50d68

Please sign in to comment.