2014-07-23 06:03:30 +02:00
|
|
|
package heroku
|
|
|
|
|
|
|
|
import (
|
2017-03-10 13:00:03 +01:00
|
|
|
"context"
|
2014-07-23 06:03:30 +02:00
|
|
|
"fmt"
|
2016-01-04 19:46:52 +01:00
|
|
|
"os"
|
2014-07-23 06:03:30 +02:00
|
|
|
"testing"
|
|
|
|
|
2014-08-27 16:50:37 +02:00
|
|
|
"github.com/cyberdelia/heroku-go/v3"
|
2016-01-21 16:31:48 +01:00
|
|
|
"github.com/hashicorp/terraform/helper/acctest"
|
2014-07-23 06:03:30 +02:00
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAccHerokuApp_Basic(t *testing.T) {
|
2017-03-10 13:00:03 +01:00
|
|
|
var app heroku.AppInfoResult
|
2016-01-21 16:31:48 +01:00
|
|
|
appName := fmt.Sprintf("tftest-%s", acctest.RandString(10))
|
2014-07-23 06:03:30 +02:00
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckHerokuAppDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
2017-03-10 13:00:03 +01:00
|
|
|
{
|
2016-01-21 16:31:48 +01:00
|
|
|
Config: testAccCheckHerokuAppConfig_basic(appName),
|
2014-07-23 06:03:30 +02:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckHerokuAppExists("heroku_app.foobar", &app),
|
2016-01-21 16:31:48 +01:00
|
|
|
testAccCheckHerokuAppAttributes(&app, appName),
|
2014-07-23 06:03:30 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2016-01-21 16:31:48 +01:00
|
|
|
"heroku_app.foobar", "name", appName),
|
2014-07-23 17:09:05 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2014-07-23 18:11:58 +02:00
|
|
|
"heroku_app.foobar", "config_vars.0.FOO", "bar"),
|
2014-07-23 06:03:30 +02:00
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2014-07-23 18:38:45 +02:00
|
|
|
func TestAccHerokuApp_NameChange(t *testing.T) {
|
2017-03-10 13:00:03 +01:00
|
|
|
var app heroku.AppInfoResult
|
2016-01-21 16:31:48 +01:00
|
|
|
appName := fmt.Sprintf("tftest-%s", acctest.RandString(10))
|
|
|
|
appName2 := fmt.Sprintf("%s-v2", appName)
|
2014-07-23 18:38:45 +02:00
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckHerokuAppDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
2017-03-10 13:00:03 +01:00
|
|
|
{
|
2016-01-21 16:31:48 +01:00
|
|
|
Config: testAccCheckHerokuAppConfig_basic(appName),
|
2014-07-23 18:38:45 +02:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckHerokuAppExists("heroku_app.foobar", &app),
|
2016-01-21 16:31:48 +01:00
|
|
|
testAccCheckHerokuAppAttributes(&app, appName),
|
2014-07-23 18:38:45 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2016-01-21 16:31:48 +01:00
|
|
|
"heroku_app.foobar", "name", appName),
|
2014-07-23 18:38:45 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"heroku_app.foobar", "config_vars.0.FOO", "bar"),
|
|
|
|
),
|
|
|
|
},
|
2017-03-10 13:00:03 +01:00
|
|
|
{
|
2016-01-21 16:31:48 +01:00
|
|
|
Config: testAccCheckHerokuAppConfig_updated(appName2),
|
2014-07-23 18:38:45 +02:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckHerokuAppExists("heroku_app.foobar", &app),
|
2016-01-21 16:31:48 +01:00
|
|
|
testAccCheckHerokuAppAttributesUpdated(&app, appName2),
|
2014-07-23 18:38:45 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2016-01-21 16:31:48 +01:00
|
|
|
"heroku_app.foobar", "name", appName2),
|
2014-07-23 18:38:45 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"heroku_app.foobar", "config_vars.0.FOO", "bing"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"heroku_app.foobar", "config_vars.0.BAZ", "bar"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2014-07-23 20:46:12 +02:00
|
|
|
func TestAccHerokuApp_NukeVars(t *testing.T) {
|
2017-03-10 13:00:03 +01:00
|
|
|
var app heroku.AppInfoResult
|
2016-01-21 16:31:48 +01:00
|
|
|
appName := fmt.Sprintf("tftest-%s", acctest.RandString(10))
|
2014-07-23 20:46:12 +02:00
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckHerokuAppDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
2017-03-10 13:00:03 +01:00
|
|
|
{
|
2016-01-21 16:31:48 +01:00
|
|
|
Config: testAccCheckHerokuAppConfig_basic(appName),
|
2014-07-23 20:46:12 +02:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckHerokuAppExists("heroku_app.foobar", &app),
|
2016-01-21 16:31:48 +01:00
|
|
|
testAccCheckHerokuAppAttributes(&app, appName),
|
2014-07-23 20:46:12 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2016-01-21 16:31:48 +01:00
|
|
|
"heroku_app.foobar", "name", appName),
|
2014-07-23 20:46:12 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"heroku_app.foobar", "config_vars.0.FOO", "bar"),
|
|
|
|
),
|
|
|
|
},
|
2017-03-10 13:00:03 +01:00
|
|
|
{
|
2016-01-21 16:31:48 +01:00
|
|
|
Config: testAccCheckHerokuAppConfig_no_vars(appName),
|
2014-07-23 20:46:12 +02:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckHerokuAppExists("heroku_app.foobar", &app),
|
2016-01-21 16:31:48 +01:00
|
|
|
testAccCheckHerokuAppAttributesNoVars(&app, appName),
|
2014-07-23 20:46:12 +02:00
|
|
|
resource.TestCheckResourceAttr(
|
2016-01-21 16:31:48 +01:00
|
|
|
"heroku_app.foobar", "name", appName),
|
2017-01-24 13:10:11 +01:00
|
|
|
resource.TestCheckNoResourceAttr(
|
|
|
|
"heroku_app.foobar", "config_vars.0.FOO"),
|
2014-07-23 20:46:12 +02:00
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-04-24 20:29:28 +02:00
|
|
|
func TestAccHerokuApp_Buildpacks(t *testing.T) {
|
|
|
|
var app heroku.AppInfoResult
|
|
|
|
appName := fmt.Sprintf("tftest-%s", acctest.RandString(10))
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckHerokuAppDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
|
|
|
Config: testAccCheckHerokuAppConfig_go(appName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckHerokuAppExists("heroku_app.foobar", &app),
|
|
|
|
testAccCheckHerokuAppBuildpacks(appName, false),
|
|
|
|
resource.TestCheckResourceAttr("heroku_app.foobar", "buildpacks.0", "heroku/go"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Config: testAccCheckHerokuAppConfig_multi(appName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckHerokuAppExists("heroku_app.foobar", &app),
|
|
|
|
testAccCheckHerokuAppBuildpacks(appName, true),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"heroku_app.foobar", "buildpacks.0", "https://github.com/heroku/heroku-buildpack-multi-procfile"),
|
|
|
|
resource.TestCheckResourceAttr("heroku_app.foobar", "buildpacks.1", "heroku/go"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Config: testAccCheckHerokuAppConfig_no_vars(appName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckHerokuAppExists("heroku_app.foobar", &app),
|
|
|
|
testAccCheckHerokuAppNoBuildpacks(appName),
|
|
|
|
resource.TestCheckNoResourceAttr("heroku_app.foobar", "buildpacks.0"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAccHerokuApp_ExternallySetBuildpacks(t *testing.T) {
|
|
|
|
var app heroku.AppInfoResult
|
|
|
|
appName := fmt.Sprintf("tftest-%s", acctest.RandString(10))
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckHerokuAppDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
|
|
|
Config: testAccCheckHerokuAppConfig_no_vars(appName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckHerokuAppExists("heroku_app.foobar", &app),
|
|
|
|
testAccCheckHerokuAppNoBuildpacks(appName),
|
|
|
|
resource.TestCheckNoResourceAttr("heroku_app.foobar", "buildpacks.0"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
PreConfig: testAccInstallUnconfiguredBuildpack(t, appName),
|
|
|
|
Config: testAccCheckHerokuAppConfig_no_vars(appName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckHerokuAppExists("heroku_app.foobar", &app),
|
|
|
|
testAccCheckHerokuAppBuildpacks(appName, false),
|
|
|
|
resource.TestCheckNoResourceAttr("heroku_app.foobar", "buildpacks.0"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-01-04 19:46:52 +01:00
|
|
|
func TestAccHerokuApp_Organization(t *testing.T) {
|
|
|
|
var app heroku.OrganizationApp
|
2016-01-21 16:31:48 +01:00
|
|
|
appName := fmt.Sprintf("tftest-%s", acctest.RandString(10))
|
2016-01-04 19:46:52 +01:00
|
|
|
org := os.Getenv("HEROKU_ORGANIZATION")
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() {
|
|
|
|
testAccPreCheck(t)
|
|
|
|
if org == "" {
|
|
|
|
t.Skip("HEROKU_ORGANIZATION is not set; skipping test.")
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckHerokuAppDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
2017-03-10 13:00:03 +01:00
|
|
|
{
|
2016-01-21 16:31:48 +01:00
|
|
|
Config: testAccCheckHerokuAppConfig_organization(appName, org),
|
2016-01-04 19:46:52 +01:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckHerokuAppExistsOrg("heroku_app.foobar", &app),
|
2017-04-21 23:22:42 +02:00
|
|
|
testAccCheckHerokuAppAttributesOrg(&app, appName, "", org),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAccHerokuApp_Space(t *testing.T) {
|
|
|
|
var app heroku.OrganizationApp
|
|
|
|
appName := fmt.Sprintf("tftest-%s", acctest.RandString(10))
|
|
|
|
org := os.Getenv("HEROKU_ORGANIZATION")
|
|
|
|
space := os.Getenv("HEROKU_SPACE")
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() {
|
|
|
|
testAccPreCheck(t)
|
|
|
|
if org == "" {
|
|
|
|
t.Skip("HEROKU_ORGANIZATION is not set; skipping test.")
|
|
|
|
}
|
|
|
|
if space == "" {
|
|
|
|
t.Skip("HEROKU_SPACE is not set; skipping test.")
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckHerokuAppDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
|
|
|
Config: testAccCheckHerokuAppConfig_space(appName, space, org),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckHerokuAppExistsOrg("heroku_app.foobar", &app),
|
|
|
|
testAccCheckHerokuAppAttributesOrg(&app, appName, space, org),
|
2016-01-04 19:46:52 +01:00
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2014-07-23 06:03:30 +02:00
|
|
|
func testAccCheckHerokuAppDestroy(s *terraform.State) error {
|
2014-08-27 16:50:37 +02:00
|
|
|
client := testAccProvider.Meta().(*heroku.Service)
|
2014-07-23 06:03:30 +02:00
|
|
|
|
2014-09-17 02:20:47 +02:00
|
|
|
for _, rs := range s.RootModule().Resources {
|
2014-07-23 06:03:30 +02:00
|
|
|
if rs.Type != "heroku_app" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2017-03-10 13:00:03 +01:00
|
|
|
_, err := client.AppInfo(context.TODO(), rs.Primary.ID)
|
2014-07-23 06:03:30 +02:00
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
return fmt.Errorf("App still exists")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-03-10 13:00:03 +01:00
|
|
|
func testAccCheckHerokuAppAttributes(app *heroku.AppInfoResult, appName string) resource.TestCheckFunc {
|
2014-07-23 06:03:30 +02:00
|
|
|
return func(s *terraform.State) error {
|
2014-08-27 16:50:37 +02:00
|
|
|
client := testAccProvider.Meta().(*heroku.Service)
|
2014-07-23 17:09:05 +02:00
|
|
|
|
|
|
|
if app.Region.Name != "us" {
|
|
|
|
return fmt.Errorf("Bad region: %s", app.Region.Name)
|
|
|
|
}
|
|
|
|
|
2014-11-19 14:25:18 +01:00
|
|
|
if app.Stack.Name != "cedar-14" {
|
2014-07-23 17:09:05 +02:00
|
|
|
return fmt.Errorf("Bad stack: %s", app.Stack.Name)
|
|
|
|
}
|
|
|
|
|
2016-01-21 16:31:48 +01:00
|
|
|
if app.Name != appName {
|
2014-07-23 17:09:05 +02:00
|
|
|
return fmt.Errorf("Bad name: %s", app.Name)
|
|
|
|
}
|
2014-07-23 06:03:30 +02:00
|
|
|
|
2017-03-10 13:00:03 +01:00
|
|
|
vars, err := client.ConfigVarInfoForApp(context.TODO(), app.Name)
|
2014-07-23 17:09:05 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-03-10 13:00:03 +01:00
|
|
|
if vars["FOO"] == nil || *vars["FOO"] != "bar" {
|
2014-07-23 17:09:05 +02:00
|
|
|
return fmt.Errorf("Bad config vars: %v", vars)
|
|
|
|
}
|
2014-07-23 06:03:30 +02:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-10 13:00:03 +01:00
|
|
|
func testAccCheckHerokuAppAttributesUpdated(app *heroku.AppInfoResult, appName string) resource.TestCheckFunc {
|
2014-07-23 18:38:45 +02:00
|
|
|
return func(s *terraform.State) error {
|
2014-08-27 16:50:37 +02:00
|
|
|
client := testAccProvider.Meta().(*heroku.Service)
|
2014-07-23 18:38:45 +02:00
|
|
|
|
2016-01-21 16:31:48 +01:00
|
|
|
if app.Name != appName {
|
2014-07-23 18:38:45 +02:00
|
|
|
return fmt.Errorf("Bad name: %s", app.Name)
|
|
|
|
}
|
|
|
|
|
2017-03-10 13:00:03 +01:00
|
|
|
vars, err := client.ConfigVarInfoForApp(context.TODO(), app.Name)
|
2014-07-23 18:38:45 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure we kept the old one
|
2017-03-10 13:00:03 +01:00
|
|
|
if vars["FOO"] == nil || *vars["FOO"] != "bing" {
|
2014-07-23 18:38:45 +02:00
|
|
|
return fmt.Errorf("Bad config vars: %v", vars)
|
|
|
|
}
|
|
|
|
|
2017-03-10 13:00:03 +01:00
|
|
|
if vars["BAZ"] == nil || *vars["BAZ"] != "bar" {
|
2014-07-23 18:38:45 +02:00
|
|
|
return fmt.Errorf("Bad config vars: %v", vars)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-10 13:00:03 +01:00
|
|
|
func testAccCheckHerokuAppAttributesNoVars(app *heroku.AppInfoResult, appName string) resource.TestCheckFunc {
|
2014-07-23 20:46:12 +02:00
|
|
|
return func(s *terraform.State) error {
|
2014-08-27 16:50:37 +02:00
|
|
|
client := testAccProvider.Meta().(*heroku.Service)
|
2014-07-23 20:46:12 +02:00
|
|
|
|
2016-01-21 16:31:48 +01:00
|
|
|
if app.Name != appName {
|
2014-07-23 20:46:12 +02:00
|
|
|
return fmt.Errorf("Bad name: %s", app.Name)
|
|
|
|
}
|
|
|
|
|
2017-03-10 13:00:03 +01:00
|
|
|
vars, err := client.ConfigVarInfoForApp(context.TODO(), app.Name)
|
2014-07-23 20:46:12 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(vars) != 0 {
|
|
|
|
return fmt.Errorf("vars exist: %v", vars)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-24 20:29:28 +02:00
|
|
|
func testAccCheckHerokuAppBuildpacks(appName string, multi bool) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
client := testAccProvider.Meta().(*heroku.Service)
|
|
|
|
|
|
|
|
results, err := client.BuildpackInstallationList(context.TODO(), appName, nil)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
buildpacks := []string{}
|
|
|
|
for _, installation := range results {
|
|
|
|
buildpacks = append(buildpacks, installation.Buildpack.Name)
|
|
|
|
}
|
|
|
|
|
|
|
|
if multi {
|
|
|
|
herokuMulti := "https://github.com/heroku/heroku-buildpack-multi-procfile"
|
|
|
|
if len(buildpacks) != 2 || buildpacks[0] != herokuMulti || buildpacks[1] != "heroku/go" {
|
|
|
|
return fmt.Errorf("Bad buildpacks: %v", buildpacks)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(buildpacks) != 1 || buildpacks[0] != "heroku/go" {
|
|
|
|
return fmt.Errorf("Bad buildpacks: %v", buildpacks)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccCheckHerokuAppNoBuildpacks(appName string) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
client := testAccProvider.Meta().(*heroku.Service)
|
|
|
|
|
|
|
|
results, err := client.BuildpackInstallationList(context.TODO(), appName, nil)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
buildpacks := []string{}
|
|
|
|
for _, installation := range results {
|
|
|
|
buildpacks = append(buildpacks, installation.Buildpack.Name)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(buildpacks) != 0 {
|
|
|
|
return fmt.Errorf("Bad buildpacks: %v", buildpacks)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-21 23:22:42 +02:00
|
|
|
func testAccCheckHerokuAppAttributesOrg(app *heroku.OrganizationApp, appName, space, org string) resource.TestCheckFunc {
|
2016-01-04 19:46:52 +01:00
|
|
|
return func(s *terraform.State) error {
|
|
|
|
client := testAccProvider.Meta().(*heroku.Service)
|
|
|
|
|
2017-04-21 23:22:42 +02:00
|
|
|
if app.Region.Name != "us" && app.Region.Name != "virginia" {
|
2016-01-04 19:46:52 +01:00
|
|
|
return fmt.Errorf("Bad region: %s", app.Region.Name)
|
|
|
|
}
|
|
|
|
|
2017-04-21 23:22:42 +02:00
|
|
|
var appSpace string
|
|
|
|
if app.Space != nil {
|
|
|
|
appSpace = app.Space.Name
|
|
|
|
}
|
|
|
|
|
|
|
|
if appSpace != space {
|
|
|
|
return fmt.Errorf("Bad space: %s", appSpace)
|
|
|
|
}
|
|
|
|
|
2016-01-04 19:46:52 +01:00
|
|
|
if app.Stack.Name != "cedar-14" {
|
|
|
|
return fmt.Errorf("Bad stack: %s", app.Stack.Name)
|
|
|
|
}
|
|
|
|
|
2016-01-21 16:31:48 +01:00
|
|
|
if app.Name != appName {
|
2016-01-04 19:46:52 +01:00
|
|
|
return fmt.Errorf("Bad name: %s", app.Name)
|
|
|
|
}
|
|
|
|
|
|
|
|
if app.Organization == nil || app.Organization.Name != org {
|
|
|
|
return fmt.Errorf("Bad org: %v", app.Organization)
|
|
|
|
}
|
|
|
|
|
2017-03-10 13:00:03 +01:00
|
|
|
vars, err := client.ConfigVarInfoForApp(context.TODO(), app.Name)
|
2016-01-04 19:46:52 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-03-10 13:00:03 +01:00
|
|
|
if vars["FOO"] == nil || *vars["FOO"] != "bar" {
|
2016-01-04 19:46:52 +01:00
|
|
|
return fmt.Errorf("Bad config vars: %v", vars)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-10 13:00:03 +01:00
|
|
|
func testAccCheckHerokuAppExists(n string, app *heroku.AppInfoResult) resource.TestCheckFunc {
|
2014-07-23 06:03:30 +02:00
|
|
|
return func(s *terraform.State) error {
|
2014-09-17 02:20:47 +02:00
|
|
|
rs, ok := s.RootModule().Resources[n]
|
2014-07-23 20:46:12 +02:00
|
|
|
|
2014-07-23 06:03:30 +02:00
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Not found: %s", n)
|
|
|
|
}
|
|
|
|
|
2014-09-17 02:20:47 +02:00
|
|
|
if rs.Primary.ID == "" {
|
2014-07-23 06:03:30 +02:00
|
|
|
return fmt.Errorf("No App Name is set")
|
|
|
|
}
|
|
|
|
|
2014-08-27 16:50:37 +02:00
|
|
|
client := testAccProvider.Meta().(*heroku.Service)
|
2014-07-23 06:03:30 +02:00
|
|
|
|
2017-03-10 13:00:03 +01:00
|
|
|
foundApp, err := client.AppInfo(context.TODO(), rs.Primary.ID)
|
2014-07-23 06:03:30 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2014-09-17 02:20:47 +02:00
|
|
|
if foundApp.Name != rs.Primary.ID {
|
2014-07-23 06:03:30 +02:00
|
|
|
return fmt.Errorf("App not found")
|
|
|
|
}
|
|
|
|
|
2014-07-23 17:09:05 +02:00
|
|
|
*app = *foundApp
|
2014-07-23 06:03:30 +02:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-04 19:46:52 +01:00
|
|
|
func testAccCheckHerokuAppExistsOrg(n string, app *heroku.OrganizationApp) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
rs, ok := s.RootModule().Resources[n]
|
|
|
|
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Not found: %s", n)
|
|
|
|
}
|
|
|
|
|
|
|
|
if rs.Primary.ID == "" {
|
|
|
|
return fmt.Errorf("No App Name is set")
|
|
|
|
}
|
|
|
|
|
|
|
|
client := testAccProvider.Meta().(*heroku.Service)
|
|
|
|
|
2017-03-10 13:00:03 +01:00
|
|
|
foundApp, err := client.OrganizationAppInfo(context.TODO(), rs.Primary.ID)
|
2016-01-04 19:46:52 +01:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if foundApp.Name != rs.Primary.ID {
|
|
|
|
return fmt.Errorf("App not found")
|
|
|
|
}
|
|
|
|
|
|
|
|
*app = *foundApp
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-24 20:29:28 +02:00
|
|
|
func testAccInstallUnconfiguredBuildpack(t *testing.T, appName string) func() {
|
|
|
|
return func() {
|
|
|
|
client := testAccProvider.Meta().(*heroku.Service)
|
|
|
|
|
|
|
|
opts := heroku.BuildpackInstallationUpdateOpts{
|
|
|
|
Updates: []struct {
|
|
|
|
Buildpack string `json:"buildpack" url:"buildpack,key"`
|
|
|
|
}{
|
|
|
|
{Buildpack: "heroku/go"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err := client.BuildpackInstallationUpdate(context.TODO(), appName, opts)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Error updating buildpacks: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-21 16:31:48 +01:00
|
|
|
func testAccCheckHerokuAppConfig_basic(appName string) string {
|
|
|
|
return fmt.Sprintf(`
|
2014-07-23 06:03:30 +02:00
|
|
|
resource "heroku_app" "foobar" {
|
2016-01-21 16:31:48 +01:00
|
|
|
name = "%s"
|
2016-01-04 19:46:52 +01:00
|
|
|
region = "us"
|
2014-07-23 17:09:05 +02:00
|
|
|
|
2016-01-04 19:46:52 +01:00
|
|
|
config_vars {
|
|
|
|
FOO = "bar"
|
|
|
|
}
|
2016-01-21 16:31:48 +01:00
|
|
|
}`, appName)
|
|
|
|
}
|
2014-07-23 18:38:45 +02:00
|
|
|
|
2017-04-24 20:29:28 +02:00
|
|
|
func testAccCheckHerokuAppConfig_go(appName string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "heroku_app" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
region = "us"
|
|
|
|
|
|
|
|
buildpacks = ["heroku/go"]
|
|
|
|
}`, appName)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccCheckHerokuAppConfig_multi(appName string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "heroku_app" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
region = "us"
|
|
|
|
|
|
|
|
buildpacks = [
|
|
|
|
"https://github.com/heroku/heroku-buildpack-multi-procfile",
|
|
|
|
"heroku/go"
|
|
|
|
]
|
|
|
|
}`, appName)
|
|
|
|
}
|
|
|
|
|
2016-01-21 16:31:48 +01:00
|
|
|
func testAccCheckHerokuAppConfig_updated(appName string) string {
|
|
|
|
return fmt.Sprintf(`
|
2014-07-23 18:38:45 +02:00
|
|
|
resource "heroku_app" "foobar" {
|
2016-01-21 16:31:48 +01:00
|
|
|
name = "%s"
|
2016-01-04 19:46:52 +01:00
|
|
|
region = "us"
|
2014-07-23 18:38:45 +02:00
|
|
|
|
2016-01-04 19:46:52 +01:00
|
|
|
config_vars {
|
|
|
|
FOO = "bing"
|
|
|
|
BAZ = "bar"
|
|
|
|
}
|
2016-01-21 16:31:48 +01:00
|
|
|
}`, appName)
|
|
|
|
}
|
2014-07-23 20:46:12 +02:00
|
|
|
|
2016-01-21 16:31:48 +01:00
|
|
|
func testAccCheckHerokuAppConfig_no_vars(appName string) string {
|
|
|
|
return fmt.Sprintf(`
|
2014-07-23 20:46:12 +02:00
|
|
|
resource "heroku_app" "foobar" {
|
2016-01-21 16:31:48 +01:00
|
|
|
name = "%s"
|
2016-01-04 19:46:52 +01:00
|
|
|
region = "us"
|
2016-01-21 16:31:48 +01:00
|
|
|
}`, appName)
|
|
|
|
}
|
2016-01-04 19:46:52 +01:00
|
|
|
|
2016-01-21 16:31:48 +01:00
|
|
|
func testAccCheckHerokuAppConfig_organization(appName, org string) string {
|
|
|
|
return fmt.Sprintf(`
|
2016-01-04 19:46:52 +01:00
|
|
|
resource "heroku_app" "foobar" {
|
2016-01-21 16:31:48 +01:00
|
|
|
name = "%s"
|
2016-01-04 19:46:52 +01:00
|
|
|
region = "us"
|
|
|
|
|
|
|
|
organization {
|
|
|
|
name = "%s"
|
|
|
|
}
|
|
|
|
|
|
|
|
config_vars {
|
|
|
|
FOO = "bar"
|
|
|
|
}
|
2016-01-21 16:31:48 +01:00
|
|
|
}`, appName, org)
|
|
|
|
}
|
2017-04-21 23:22:42 +02:00
|
|
|
|
|
|
|
func testAccCheckHerokuAppConfig_space(appName, space, org string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "heroku_app" "foobar" {
|
|
|
|
name = "%s"
|
|
|
|
space = "%s"
|
|
|
|
region = "virginia"
|
|
|
|
|
|
|
|
organization {
|
|
|
|
name = "%s"
|
|
|
|
}
|
|
|
|
|
|
|
|
config_vars {
|
|
|
|
FOO = "bar"
|
|
|
|
}
|
|
|
|
}`, appName, space, org)
|
|
|
|
}
|