providers/heroku: serialize the addons, depend on apps

This commit is contained in:
Jack Pearkes 2014-07-25 00:08:38 -04:00
parent b9414b832c
commit 404a6ccad2
1 changed files with 13 additions and 0 deletions

View File

@ -3,6 +3,7 @@ package heroku
import ( import (
"fmt" "fmt"
"log" "log"
"sync"
"github.com/bgentry/heroku-go" "github.com/bgentry/heroku-go"
"github.com/hashicorp/terraform/flatmap" "github.com/hashicorp/terraform/flatmap"
@ -11,10 +12,18 @@ import (
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
) )
// Global lock to prevent parallelism for heroku_addon since
// the Heroku API cannot handle a single application requesting
// multiple addons simultaneously.
var addonLock sync.Mutex
func resource_heroku_addon_create( func resource_heroku_addon_create(
s *terraform.ResourceState, s *terraform.ResourceState,
d *terraform.ResourceDiff, d *terraform.ResourceDiff,
meta interface{}) (*terraform.ResourceState, error) { meta interface{}) (*terraform.ResourceState, error) {
addonLock.Lock()
defer addonLock.Unlock()
p := meta.(*ResourceProvider) p := meta.(*ResourceProvider)
client := p.client client := p.client
@ -160,6 +169,10 @@ func resource_heroku_addon_update_state(
s.Attributes[k] = v s.Attributes[k] = v
} }
s.Dependencies = []terraform.ResourceDependency{
terraform.ResourceDependency{ID: s.Attributes["app"]},
}
return s, nil return s, nil
} }