Skip to content

Commit

Permalink
Prevent app deletion by default
Browse files Browse the repository at this point in the history
  • Loading branch information
yknx4 committed Jan 13, 2025
1 parent b2913ef commit 1583f7b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 11 additions & 1 deletion heroku/resource_heroku_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ func resourceHerokuApp() *schema.Resource {
ForceNew: true,
},

"allow_deletion": {
Type: schema.TypeBool,
Optional: true,
},

"buildpacks": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -562,8 +567,13 @@ func resourceHerokuAppUpdate(d *schema.ResourceData, meta interface{}) error {

func resourceHerokuAppDelete(d *schema.ResourceData, meta interface{}) error {
client := meta.(*Config).Api

log.Printf("[INFO] Deleting App: %s", d.Id())

canBeDeleted := d.Get("allow_deletion").(bool)
if !canBeDeleted {
return fmt.Errorf("error deleting App: %s", "allow_deletion is false")
}

_, err := client.AppDelete(context.TODO(), d.Id())
if err != nil {
return fmt.Errorf("error deleting App: %s", err)
Expand Down
2 changes: 2 additions & 0 deletions heroku/resource_heroku_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,7 @@ func testAccCheckHerokuAppConfig_basic(appName string) string {
resource "heroku_app" "foobar" {
name = "%s"
region = "us"
allow_deletion = true
config_vars = {
FOO = "bar"
Expand Down Expand Up @@ -981,6 +982,7 @@ func testAccCheckHerokuAppConfig_locked(appName, org, locked string) string {
resource "heroku_app" "foobar" {
name = "%s"
region = "us"
allow_deletion = true
organization {
name = "%s"
Expand Down

0 comments on commit 1583f7b

Please sign in to comment.