providers/heroku: plans work without specific plan name [GH-198]
This commit is contained in:
parent
bec5a2a9c5
commit
39c4fb2005
|
@ -61,6 +61,8 @@ BUG FIXES:
|
||||||
* providers/heroku: Domains and drains are deleted before the app.
|
* providers/heroku: Domains and drains are deleted before the app.
|
||||||
* providers/heroku: Moved from the client library bgentry/heroku-go to
|
* providers/heroku: Moved from the client library bgentry/heroku-go to
|
||||||
cyberdelia/heroku-go [GH-239].
|
cyberdelia/heroku-go [GH-239].
|
||||||
|
* providers/heroku: Plans without a specific plan name for
|
||||||
|
heroku\_addon work. [GH-198]
|
||||||
|
|
||||||
PLUGIN CHANGES:
|
PLUGIN CHANGES:
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"sync"
|
"sync"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/cyberdelia/heroku-go/v3"
|
"github.com/cyberdelia/heroku-go/v3"
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
|
@ -98,8 +99,21 @@ func resourceHerokuAddonRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Determine the plan. If we were configured without a specific plan,
|
||||||
|
// then just avoid the plan altogether (accepting anything that
|
||||||
|
// Heroku sends down).
|
||||||
|
plan := addon.Plan.Name
|
||||||
|
if v := d.Get("plan").(string); v != "" {
|
||||||
|
if idx := strings.IndexRune(v, ':'); idx == -1 {
|
||||||
|
idx = strings.IndexRune(plan, ':')
|
||||||
|
if idx > -1 {
|
||||||
|
plan = plan[:idx]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
d.Set("name", addon.Name)
|
d.Set("name", addon.Name)
|
||||||
d.Set("plan", addon.Plan.Name)
|
d.Set("plan", plan)
|
||||||
d.Set("provider_id", addon.ProviderID)
|
d.Set("provider_id", addon.ProviderID)
|
||||||
d.Set("config_vars", []interface{}{addon.ConfigVars})
|
d.Set("config_vars", []interface{}{addon.ConfigVars})
|
||||||
d.SetDependencies([]terraform.ResourceDependency{
|
d.SetDependencies([]terraform.ResourceDependency{
|
||||||
|
|
|
@ -21,7 +21,7 @@ func TestAccHerokuAddon_Basic(t *testing.T) {
|
||||||
Config: testAccCheckHerokuAddonConfig_basic,
|
Config: testAccCheckHerokuAddonConfig_basic,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckHerokuAddonExists("heroku_addon.foobar", &addon),
|
testAccCheckHerokuAddonExists("heroku_addon.foobar", &addon),
|
||||||
testAccCheckHerokuAddonAttributes(&addon),
|
testAccCheckHerokuAddonAttributes(&addon, "deployhooks:http"),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"heroku_addon.foobar", "config.0.url", "http://google.com"),
|
"heroku_addon.foobar", "config.0.url", "http://google.com"),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
|
@ -34,6 +34,41 @@ func TestAccHerokuAddon_Basic(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GH-198
|
||||||
|
func TestAccHerokuAddon_noPlan(t *testing.T) {
|
||||||
|
var addon heroku.Addon
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testAccCheckHerokuAddonDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccCheckHerokuAddonConfig_no_plan,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testAccCheckHerokuAddonExists("heroku_addon.foobar", &addon),
|
||||||
|
testAccCheckHerokuAddonAttributes(&addon, "memcachier:dev"),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"heroku_addon.foobar", "app", "terraform-test-app"),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"heroku_addon.foobar", "plan", "memcachier"),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccCheckHerokuAddonConfig_no_plan,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testAccCheckHerokuAddonExists("heroku_addon.foobar", &addon),
|
||||||
|
testAccCheckHerokuAddonAttributes(&addon, "memcachier:dev"),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"heroku_addon.foobar", "app", "terraform-test-app"),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"heroku_addon.foobar", "plan", "memcachier"),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func testAccCheckHerokuAddonDestroy(s *terraform.State) error {
|
func testAccCheckHerokuAddonDestroy(s *terraform.State) error {
|
||||||
client := testAccProvider.Meta().(*heroku.Service)
|
client := testAccProvider.Meta().(*heroku.Service)
|
||||||
|
|
||||||
|
@ -52,11 +87,11 @@ func testAccCheckHerokuAddonDestroy(s *terraform.State) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckHerokuAddonAttributes(addon *heroku.Addon) resource.TestCheckFunc {
|
func testAccCheckHerokuAddonAttributes(addon *heroku.Addon, n string) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
|
|
||||||
if addon.Plan.Name != "deployhooks:http" {
|
if addon.Plan.Name != n {
|
||||||
return fmt.Errorf("Bad plan: %s", addon.Plan)
|
return fmt.Errorf("Bad plan: %s", addon.Plan.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -106,3 +141,14 @@ resource "heroku_addon" "foobar" {
|
||||||
url = "http://google.com"
|
url = "http://google.com"
|
||||||
}
|
}
|
||||||
}`
|
}`
|
||||||
|
|
||||||
|
const testAccCheckHerokuAddonConfig_no_plan = `
|
||||||
|
resource "heroku_app" "foobar" {
|
||||||
|
name = "terraform-test-app"
|
||||||
|
region = "us"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "heroku_addon" "foobar" {
|
||||||
|
app = "${heroku_app.foobar.name}"
|
||||||
|
plan = "memcachier"
|
||||||
|
}`
|
||||||
|
|
Loading…
Reference in New Issue