Merge pull request #13862 from bernerdschaefer/bs-heroku-app-space
Create Heroku app in a private space
This commit is contained in:
commit
b0f8ab492e
|
@ -16,6 +16,7 @@ import (
|
|||
type herokuApplication struct {
|
||||
Name string
|
||||
Region string
|
||||
Space string
|
||||
Stack string
|
||||
GitURL string
|
||||
WebURL string
|
||||
|
@ -63,6 +64,9 @@ func (a *application) Update() error {
|
|||
a.App.Stack = app.Stack.Name
|
||||
a.App.GitURL = app.GitURL
|
||||
a.App.WebURL = app.WebURL
|
||||
if app.Space != nil {
|
||||
a.App.Space = app.Space.Name
|
||||
}
|
||||
if app.Organization != nil {
|
||||
a.App.OrganizationName = app.Organization.Name
|
||||
} else {
|
||||
|
@ -102,6 +106,12 @@ func resourceHerokuApp() *schema.Resource {
|
|||
Required: true,
|
||||
},
|
||||
|
||||
"space": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"region": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
|
@ -275,6 +285,11 @@ func resourceHerokuOrgAppCreate(d *schema.ResourceData, meta interface{}) error
|
|||
log.Printf("[DEBUG] App region: %s", vs)
|
||||
opts.Region = &vs
|
||||
}
|
||||
if v, ok := d.GetOk("space"); ok {
|
||||
vs := v.(string)
|
||||
log.Printf("[DEBUG] App space: %s", vs)
|
||||
opts.Space = &vs
|
||||
}
|
||||
if v, ok := d.GetOk("stack"); ok {
|
||||
vs := v.(string)
|
||||
log.Printf("[DEBUG] App stack: %s", vs)
|
||||
|
@ -344,6 +359,8 @@ func resourceHerokuAppRead(d *schema.ResourceData, meta interface{}) error {
|
|||
d.Set("config_vars", configVarsValue)
|
||||
d.Set("all_config_vars", app.Vars)
|
||||
if organizationApp {
|
||||
d.Set("space", app.App.Space)
|
||||
|
||||
orgDetails := map[string]interface{}{
|
||||
"name": app.App.OrganizationName,
|
||||
"locked": app.App.Locked,
|
||||
|
|
|
@ -197,7 +197,37 @@ func TestAccHerokuApp_Organization(t *testing.T) {
|
|||
Config: testAccCheckHerokuAppConfig_organization(appName, org),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckHerokuAppExistsOrg("heroku_app.foobar", &app),
|
||||
testAccCheckHerokuAppAttributesOrg(&app, appName, org),
|
||||
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),
|
||||
),
|
||||
},
|
||||
},
|
||||
|
@ -352,14 +382,23 @@ func testAccCheckHerokuAppNoBuildpacks(appName string) resource.TestCheckFunc {
|
|||
}
|
||||
}
|
||||
|
||||
func testAccCheckHerokuAppAttributesOrg(app *heroku.OrganizationApp, appName string, org string) resource.TestCheckFunc {
|
||||
func testAccCheckHerokuAppAttributesOrg(app *heroku.OrganizationApp, appName, space, org string) resource.TestCheckFunc {
|
||||
return func(s *terraform.State) error {
|
||||
client := testAccProvider.Meta().(*heroku.Service)
|
||||
|
||||
if app.Region.Name != "us" {
|
||||
if app.Region.Name != "us" && app.Region.Name != "virginia" {
|
||||
return fmt.Errorf("Bad region: %s", app.Region.Name)
|
||||
}
|
||||
|
||||
var appSpace string
|
||||
if app.Space != nil {
|
||||
appSpace = app.Space.Name
|
||||
}
|
||||
|
||||
if appSpace != space {
|
||||
return fmt.Errorf("Bad space: %s", appSpace)
|
||||
}
|
||||
|
||||
if app.Stack.Name != "cedar-14" {
|
||||
return fmt.Errorf("Bad stack: %s", app.Stack.Name)
|
||||
}
|
||||
|
@ -535,3 +574,20 @@ resource "heroku_app" "foobar" {
|
|||
}
|
||||
}`, appName, org)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@ The following arguments are supported:
|
|||
variables, but rather variables you want present. That is, other
|
||||
configuration variables set externally won't be removed by Terraform
|
||||
if they aren't present in this list.
|
||||
* `space` - (Optional) The name of a private space to create the app in.
|
||||
* `organization` - (Optional) A block that can be specified once to define
|
||||
organization settings for this app. The fields for this block are
|
||||
documented below.
|
||||
|
@ -64,6 +65,7 @@ The following attributes are exported:
|
|||
unique ID.
|
||||
* `stack` - The application stack is what platform to run the application
|
||||
in.
|
||||
* `space` - The private space the app should run in.
|
||||
* `region` - The region that the app should be deployed in.
|
||||
* `git_url` - The Git URL for the application. This is used for
|
||||
deploying new versions of the app.
|
||||
|
|
Loading…
Reference in New Issue