Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add provider delay config for app delete #158

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
## 1.7.1 (Unreleased)

FEATURES:

IMPROVEMENTS:
* Add configurable delay for post app deletion [#158](https://github.com/terraform-providers/terraform-provider-heroku/pull/158)

BUG FIXES:

## 1.7.0 (December 14, 2018)

FEATURES:
Expand Down
10 changes: 8 additions & 2 deletions heroku/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (

const (
DefaultPostAppCreateDelay = int64(5)
DefaultPostAppDeleteDelay = int64(5)
DefaultPostSpaceCreateDelay = int64(5)
DefaultPostDomainCreateDelay = int64(5)
)
Expand All @@ -29,20 +30,22 @@ type Config struct {
Email string
Headers http.Header
PostAppCreateDelay int64
PostAppDeleteDelay int64
PostDomainCreateDelay int64
PostSpaceCreateDelay int64
URL string
}

func (c Config) String() string {
return fmt.Sprintf("{APIKey:xxx Email:%s URL:%s Headers:xxx DebugHTTP:%t PostAppCreateDelay:%d PostDomainCreateDelay:%d PostSpaceCreateDelay:%d}",
c.Email, c.URL, c.DebugHTTP, c.PostAppCreateDelay, c.PostDomainCreateDelay, c.PostSpaceCreateDelay)
return fmt.Sprintf("{APIKey:xxx Email:%s URL:%s Headers:xxx DebugHTTP:%t PostAppCreateDelay:%d PostAppDeleteDelay:%d PostDomainCreateDelay:%d PostSpaceCreateDelay:%d}",
c.Email, c.URL, c.DebugHTTP, c.PostAppCreateDelay, c.PostAppDeleteDelay, c.PostDomainCreateDelay, c.PostSpaceCreateDelay)
}

func NewConfig() *Config {
config := &Config{
Headers: make(http.Header),
PostAppCreateDelay: DefaultPostAppCreateDelay,
PostAppDeleteDelay: DefaultPostAppDeleteDelay,
PostDomainCreateDelay: DefaultPostDomainCreateDelay,
PostSpaceCreateDelay: DefaultPostSpaceCreateDelay,
}
Expand Down Expand Up @@ -104,6 +107,9 @@ func (c *Config) applySchema(d *schema.ResourceData) (err error) {
if v, ok := delaysConfig["post_app_create_delay"].(int); ok {
c.PostAppCreateDelay = int64(v)
}
if v, ok := delaysConfig["post_app_delete_delay"].(int); ok {
c.PostAppDeleteDelay = int64(v)
}
if v, ok := delaysConfig["post_space_create_delay"].(int); ok {
c.PostSpaceCreateDelay = int64(v)
}
Expand Down
6 changes: 6 additions & 0 deletions heroku/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ func Provider() terraform.ResourceProvider {
Default: DefaultPostAppCreateDelay,
ValidateFunc: validation.IntAtLeast(0),
},
"post_app_delete_delay": {
Type: schema.TypeInt,
Optional: true,
Default: DefaultPostAppDeleteDelay,
ValidateFunc: validation.IntAtLeast(0),
},
"post_space_create_delay": {
Type: schema.TypeInt,
Optional: true,
Expand Down
4 changes: 4 additions & 0 deletions heroku/resource_heroku_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,10 @@ func resourceHerokuAppDelete(d *schema.ResourceData, meta interface{}) error {
}

d.SetId("")

config := meta.(*Config)
time.Sleep(time.Duration(config.PostAppDeleteDelay) * time.Second)

return nil
}

Expand Down
3 changes: 0 additions & 3 deletions heroku/resource_heroku_space.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,6 @@ func resourceHerokuSpaceCreate(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] Set Trusted IP Ranges to %s for Space %s", ips.List(), d.Id())
}

config := meta.(*Config)
time.Sleep(time.Duration(config.PostSpaceCreateDelay) * time.Second)

return resourceHerokuSpaceRead(d, meta)
}

Expand Down