Skip to content

Commit 69a18b0

Browse files
authored
Merge pull request #372 from heroku/randomized-herokuapp-names
Prepare for randomized herokuapp.com app names
2 parents a74bc62 + 03cade5 commit 69a18b0

6 files changed

+42
-60
lines changed

.github/workflows/acceptance-tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
HEROKU_EMAIL: terraform-provider-heroku+ci@salesforce.com
6363
HEROKU_TEST_USER: terraform-provider-heroku+ci-admin-test@salesforce.com
6464
HEROKU_NON_ADMIN_TEST_USER: terraform-provider-heroku+ci-user-test@salesforce.com
65-
HEROKU_SLUG_ID: 8527dbf3-c0a0-4255-beab-aca0aad1dfc9
65+
HEROKU_SLUG_ID: f2eba78f-25c9-476b-8998-2325241b980a
6666
HEROKU_USER_ID: aaaa7bc7-7de5-410f-a60c-3741d2c355d1
6767
# GOFLAGS: "-mod=vendor"
6868
# TF_LOG: DEBUG

heroku/data_source_heroku_app_test.go

+5-16
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,29 @@ import (
1111

1212
func TestAccDatasourceHerokuApp_Basic(t *testing.T) {
1313
appName := fmt.Sprintf("tftest-%s", acctest.RandString(10))
14-
appStack := "heroku-20"
1514
gitUrl := fmt.Sprintf("https://git.heroku.com/%s.git", appName)
16-
webUrl := fmt.Sprintf("https://%s.herokuapp.com/", appName)
17-
herokuHostname := fmt.Sprintf("%s.herokuapp.com", appName)
1815

1916
resource.Test(t, resource.TestCase{
2017
PreCheck: func() { testAccPreCheck(t) },
2118
Providers: testAccProviders,
2219
Steps: []resource.TestStep{
2320
{
24-
Config: testAccCheckHerokuAppWithDatasource_basic(appName, appStack),
21+
Config: testAccCheckHerokuAppWithDatasource_basic(appName),
2522
Check: resource.ComposeTestCheckFunc(
2623
resource.TestCheckResourceAttr(
2724
"data.heroku_app.foobar", "name", appName),
2825
resource.TestCheckResourceAttrSet(
2926
"data.heroku_app.foobar", "id"),
30-
resource.TestCheckResourceAttr(
31-
"data.heroku_app.foobar", "stack", appStack),
3227
resource.TestCheckResourceAttr(
3328
"data.heroku_app.foobar", "region", "us"),
3429
resource.TestCheckResourceAttr(
3530
"data.heroku_app.foobar", "git_url", gitUrl),
36-
resource.TestCheckResourceAttr(
37-
"data.heroku_app.foobar", "web_url", webUrl),
3831
resource.TestCheckResourceAttr(
3932
"data.heroku_app.foobar", "config_vars.FOO", "bar"),
4033
resource.TestCheckResourceAttr(
4134
"data.heroku_app.foobar", "buildpacks.0", "https://github.com/heroku/heroku-buildpack-multi-procfile"),
4235
resource.TestCheckResourceAttr(
4336
"data.heroku_app.foobar", "acm", "false"),
44-
resource.TestCheckResourceAttr(
45-
"data.heroku_app.foobar", "heroku_hostname", herokuHostname),
4637
),
4738
},
4839
},
@@ -78,11 +69,10 @@ func TestAccDatasourceHerokuApp_Organization(t *testing.T) {
7869
})
7970
}
8071

81-
func testAccCheckHerokuApp_basic(appName string, stack string) string {
72+
func testAccCheckHerokuApp_basic(appName string) string {
8273
return fmt.Sprintf(`
8374
resource "heroku_app" "foobar" {
8475
name = "%s"
85-
stack = "%s"
8676
region = "us"
8777
8878
buildpacks = [
@@ -93,14 +83,13 @@ resource "heroku_app" "foobar" {
9383
FOO = "bar"
9484
}
9585
}
96-
`, appName, stack)
86+
`, appName)
9787
}
9888

99-
func testAccCheckHerokuAppWithDatasource_basic(appName string, stack string) string {
89+
func testAccCheckHerokuAppWithDatasource_basic(appName string) string {
10090
return fmt.Sprintf(`
10191
resource "heroku_app" "foobar" {
10292
name = "%s"
103-
stack = "%s"
10493
region = "us"
10594
10695
buildpacks = [
@@ -116,7 +105,7 @@ resource "heroku_app" "foobar" {
116105
data "heroku_app" "foobar" {
117106
name = "${heroku_app.foobar.name}"
118107
}
119-
`, appName, stack)
108+
`, appName)
120109
}
121110

122111
func testAccCheckHerokuApp_organization(appName, orgName string) string {

heroku/import_heroku_app_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@ import (
1010

1111
func TestAccHerokuApp_importBasic(t *testing.T) {
1212
appName := fmt.Sprintf("tftest-%s", acctest.RandString(10))
13-
appStack := "heroku-20"
1413

1514
resource.Test(t, resource.TestCase{
1615
PreCheck: func() { testAccPreCheck(t) },
1716
Providers: testAccProviders,
1817
CheckDestroy: testAccCheckHerokuAppDestroy,
1918
Steps: []resource.TestStep{
2019
{
21-
Config: testAccCheckHerokuAppConfig_basic(appName, appStack),
20+
Config: testAccCheckHerokuAppConfig_basic(appName),
2221
},
2322
{
2423
ResourceName: "heroku_app.foobar",

heroku/resource_heroku_app.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"log"
88
"net/url"
9+
"strings"
910
"time"
1011

1112
"github.com/hashicorp/go-uuid"
@@ -362,7 +363,11 @@ func setAppDetails(d *schema.ResourceData, app *application) (err error) {
362363
err = d.Set("web_url", app.App.WebURL)
363364
err = d.Set("acm", app.App.Acm)
364365
err = d.Set("uuid", app.App.ID)
365-
err = d.Set("heroku_hostname", fmt.Sprintf("%s.herokuapp.com", app.App.Name))
366+
err = d.Set("heroku_hostname",
367+
strings.TrimPrefix(
368+
strings.TrimPrefix(
369+
strings.TrimSuffix(
370+
app.App.WebURL, "/"), "https://"), "http://"))
366371

367372
return err
368373
}

heroku/resource_heroku_app_test.go

+29-39
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"net/http"
88
"net/http/httptest"
99
"reflect"
10+
"strings"
1011
"testing"
1112

1213
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
@@ -19,18 +20,17 @@ import (
1920
func TestAccHerokuApp_Basic(t *testing.T) {
2021
var app heroku.App
2122
appName := fmt.Sprintf("tftest-%s", acctest.RandString(10))
22-
appStack := "heroku-20"
2323

2424
resource.Test(t, resource.TestCase{
2525
PreCheck: func() { testAccPreCheck(t) },
2626
Providers: testAccProviders,
2727
CheckDestroy: testAccCheckHerokuAppDestroy,
2828
Steps: []resource.TestStep{
2929
{
30-
Config: testAccCheckHerokuAppConfig_basic(appName, appStack),
30+
Config: testAccCheckHerokuAppConfig_basic(appName),
3131
Check: resource.ComposeTestCheckFunc(
3232
testAccCheckHerokuAppExists("heroku_app.foobar", &app),
33-
testAccCheckHerokuAppAttributes(&app, appName, "heroku-20"),
33+
testAccCheckHerokuAppAttributes(&app, appName),
3434
resource.TestCheckResourceAttr(
3535
"heroku_app.foobar", "name", appName),
3636
resource.TestCheckResourceAttrSet(
@@ -41,6 +41,16 @@ func TestAccHerokuApp_Basic(t *testing.T) {
4141
"heroku_app.foobar", "internal_routing", "false"),
4242
resource.TestCheckResourceAttr(
4343
"heroku_app.foobar", "all_config_vars.%", "1"),
44+
resource.TestCheckResourceAttrWith(
45+
"heroku_app.foobar", "heroku_hostname", func(value string) error {
46+
if !strings.HasSuffix(value, "herokuapp.com") {
47+
return fmt.Errorf(fmt.Sprintf("'%s' should end with 'herokuapp.com'", value))
48+
}
49+
if !strings.HasPrefix(value, appName) {
50+
return fmt.Errorf(fmt.Sprintf("'%s' should start with '%s'", value, appName))
51+
}
52+
return nil
53+
}),
4454
),
4555
},
4656
},
@@ -49,14 +59,13 @@ func TestAccHerokuApp_Basic(t *testing.T) {
4959

5060
func TestAccHerokuApp_DontSetAllConfigVars(t *testing.T) {
5161
appName := fmt.Sprintf("tftest-%s", acctest.RandString(10))
52-
appStack := "heroku-20"
5362

5463
resource.Test(t, resource.TestCase{
5564
PreCheck: func() { testAccPreCheck(t) },
5665
ProviderFactories: testAccProviderFactories,
5766
Steps: []resource.TestStep{
5867
{
59-
Config: testAccCheckHerokuAppConfig_DontSetConfigVars(appName, appStack),
68+
Config: testAccCheckHerokuAppConfig_DontSetConfigVars(appName),
6069
Check: resource.ComposeTestCheckFunc(
6170
resource.TestCheckResourceAttr(
6271
"heroku_app.foobar", "name", appName),
@@ -77,15 +86,14 @@ func TestAccHerokuApp_DontSetAllConfigVars(t *testing.T) {
7786
func TestAccHerokuApp_Disappears(t *testing.T) {
7887
var app heroku.App
7988
appName := fmt.Sprintf("tftest-%s", acctest.RandString(10))
80-
appStack := "heroku-18"
8189

8290
resource.Test(t, resource.TestCase{
8391
PreCheck: func() { testAccPreCheck(t) },
8492
Providers: testAccProviders,
8593
CheckDestroy: testAccCheckHerokuAppDestroy,
8694
Steps: []resource.TestStep{
8795
{
88-
Config: testAccCheckHerokuAppConfig_basic(appName, appStack),
96+
Config: testAccCheckHerokuAppConfig_basic(appName),
8997
Check: resource.ComposeTestCheckFunc(
9098
testAccCheckHerokuAppExists("heroku_app.foobar", &app),
9199
testAccCheckHerokuAppDisappears(appName),
@@ -100,36 +108,30 @@ func TestAccHerokuApp_Change(t *testing.T) {
100108
var app heroku.App
101109
appName := fmt.Sprintf("tftest-%s", acctest.RandString(10))
102110
appName2 := fmt.Sprintf("%s-v2", appName)
103-
appStack := "heroku-18"
104-
appStack2 := "heroku-20"
105111

106112
resource.Test(t, resource.TestCase{
107113
PreCheck: func() { testAccPreCheck(t) },
108114
Providers: testAccProviders,
109115
CheckDestroy: testAccCheckHerokuAppDestroy,
110116
Steps: []resource.TestStep{
111117
{
112-
Config: testAccCheckHerokuAppConfig_basic(appName, appStack),
118+
Config: testAccCheckHerokuAppConfig_basic(appName),
113119
Check: resource.ComposeTestCheckFunc(
114120
testAccCheckHerokuAppExists("heroku_app.foobar", &app),
115-
testAccCheckHerokuAppAttributes(&app, appName, appStack),
121+
testAccCheckHerokuAppAttributes(&app, appName),
116122
resource.TestCheckResourceAttr(
117123
"heroku_app.foobar", "name", appName),
118-
resource.TestCheckResourceAttr(
119-
"heroku_app.foobar", "stack", appStack),
120124
resource.TestCheckResourceAttr(
121125
"heroku_app.foobar", "config_vars.FOO", "bar"),
122126
),
123127
},
124128
{
125-
Config: testAccCheckHerokuAppConfig_updated(appName2, appStack2),
129+
Config: testAccCheckHerokuAppConfig_updated(appName2),
126130
Check: resource.ComposeTestCheckFunc(
127131
testAccCheckHerokuAppExists("heroku_app.foobar", &app),
128-
testAccCheckHerokuAppAttributesUpdated(&app, appName2, appStack2),
132+
testAccCheckHerokuAppAttributesUpdated(&app, appName2),
129133
resource.TestCheckResourceAttr(
130134
"heroku_app.foobar", "name", appName2),
131-
resource.TestCheckResourceAttr(
132-
"heroku_app.foobar", "stack", appStack2),
133135
resource.TestCheckResourceAttr(
134136
"heroku_app.foobar", "config_vars.FOO", "bing"),
135137
resource.TestCheckResourceAttr(
@@ -143,18 +145,17 @@ func TestAccHerokuApp_Change(t *testing.T) {
143145
func TestAccHerokuApp_NukeVars(t *testing.T) {
144146
var app heroku.App
145147
appName := fmt.Sprintf("tftest-%s", acctest.RandString(10))
146-
appStack := "heroku-20"
147148

148149
resource.Test(t, resource.TestCase{
149150
PreCheck: func() { testAccPreCheck(t) },
150151
Providers: testAccProviders,
151152
CheckDestroy: testAccCheckHerokuAppDestroy,
152153
Steps: []resource.TestStep{
153154
{
154-
Config: testAccCheckHerokuAppConfig_basic(appName, appStack),
155+
Config: testAccCheckHerokuAppConfig_basic(appName),
155156
Check: resource.ComposeTestCheckFunc(
156157
testAccCheckHerokuAppExists("heroku_app.foobar", &app),
157-
testAccCheckHerokuAppAttributes(&app, appName, "heroku-20"),
158+
testAccCheckHerokuAppAttributes(&app, appName),
158159
resource.TestCheckResourceAttr(
159160
"heroku_app.foobar", "name", appName),
160161
resource.TestCheckResourceAttr(
@@ -493,18 +494,14 @@ func testAccCheckHerokuAppDestroy(s *terraform.State) error {
493494
return nil
494495
}
495496

496-
func testAccCheckHerokuAppAttributes(app *heroku.App, appName, stackName string) resource.TestCheckFunc {
497+
func testAccCheckHerokuAppAttributes(app *heroku.App, appName string) resource.TestCheckFunc {
497498
return func(s *terraform.State) error {
498499
client := testAccProvider.Meta().(*Config).Api
499500

500501
if app.Region.Name != "us" {
501502
return fmt.Errorf("Bad region: %s", app.Region.Name)
502503
}
503504

504-
if app.BuildStack.Name != stackName {
505-
return fmt.Errorf("Bad stack: %s", app.BuildStack.Name)
506-
}
507-
508505
if app.Name != appName {
509506
return fmt.Errorf("Bad name: %s", app.Name)
510507
}
@@ -522,14 +519,10 @@ func testAccCheckHerokuAppAttributes(app *heroku.App, appName, stackName string)
522519
}
523520
}
524521

525-
func testAccCheckHerokuAppAttributesUpdated(app *heroku.App, appName, stackName string) resource.TestCheckFunc {
522+
func testAccCheckHerokuAppAttributesUpdated(app *heroku.App, appName string) resource.TestCheckFunc {
526523
return func(s *terraform.State) error {
527524
client := testAccProvider.Meta().(*Config).Api
528525

529-
if app.BuildStack.Name != stackName {
530-
return fmt.Errorf("Bad stack: %s", app.BuildStack.Name)
531-
}
532-
533526
if app.Name != appName {
534527
return fmt.Errorf("Bad name: %s", app.Name)
535528
}
@@ -765,17 +758,16 @@ func testAccCheckHerokuAppDisappears(appName string) resource.TestCheckFunc {
765758
}
766759
}
767760

768-
func testAccCheckHerokuAppConfig_basic(appName, appStack string) string {
761+
func testAccCheckHerokuAppConfig_basic(appName string) string {
769762
return fmt.Sprintf(`
770763
resource "heroku_app" "foobar" {
771764
name = "%s"
772-
stack = "%s"
773765
region = "us"
774766
775767
config_vars = {
776768
FOO = "bar"
777769
}
778-
}`, appName, appStack)
770+
}`, appName)
779771
}
780772

781773
func testAccCheckHerokuAppConfig_go(appName string) string {
@@ -801,18 +793,17 @@ resource "heroku_app" "foobar" {
801793
}`, appName)
802794
}
803795

804-
func testAccCheckHerokuAppConfig_updated(appName, appStack string) string {
796+
func testAccCheckHerokuAppConfig_updated(appName string) string {
805797
return fmt.Sprintf(`
806798
resource "heroku_app" "foobar" {
807799
name = "%s"
808-
stack = "%s"
809800
region = "us"
810801
811802
config_vars = {
812803
FOO = "bing"
813804
BAZ = "bar"
814805
}
815-
}`, appName, appStack)
806+
}`, appName)
816807
}
817808

818809
func testAccCheckHerokuAppConfig_no_vars(appName string) string {
@@ -998,7 +989,7 @@ resource "heroku_app" "foobar" {
998989
}`, appName, org, locked)
999990
}
1000991

1001-
func testAccCheckHerokuAppConfig_DontSetConfigVars(appName, appStack string) string {
992+
func testAccCheckHerokuAppConfig_DontSetConfigVars(appName string) string {
1002993
return fmt.Sprintf(`
1003994
provider "heroku" {
1004995
customizations {
@@ -1008,11 +999,10 @@ provider "heroku" {
1008999
10091000
resource "heroku_app" "foobar" {
10101001
name = "%s"
1011-
stack = "%s"
10121002
region = "us"
10131003
10141004
config_vars = {
10151005
FOO = "bar"
10161006
}
1017-
}`, appName, appStack)
1007+
}`, appName)
10181008
}

heroku/resource_heroku_slug_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ resource "heroku_slug" "foobar" {
237237
test = "echo 'Just a test'"
238238
diag = "echo 'Just diagnosis'"
239239
}
240-
stack = "heroku-18"
241240
}`, appName)
242241
}
243242

0 commit comments

Comments
 (0)