Merge pull request #17035 from hashicorp/jbardin/close-providers

Close providers
This commit is contained in:
James Bardin 2018-01-05 16:54:16 -05:00 committed by GitHub
commit 3cde03bab1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 43 additions and 6 deletions

View File

@ -2401,6 +2401,32 @@ func TestContext2Plan_hook(t *testing.T) {
}
}
func TestContext2Plan_closeProvider(t *testing.T) {
// this fixture only has an aliased provider located in the module, to make
// sure that the provier name contains a path more complex than
// "provider.aws".
m := testModule(t, "plan-close-module-provider")
p := testProvider("aws")
p.DiffFn = testDiffFn
ctx := testContext2(t, &ContextOpts{
Module: m,
ProviderResolver: ResourceProviderResolverFixed(
map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
),
})
_, err := ctx.Plan()
if err != nil {
t.Fatalf("err: %s", err)
}
if !p.CloseCalled {
t.Fatal("provider not closed")
}
}
func TestContext2Plan_orphan(t *testing.T) {
m := testModule(t, "plan-orphan")
p := testProvider("aws")

View File

@ -90,7 +90,8 @@ func TestEvalInitProvider(t *testing.T) {
}
func TestEvalCloseProvider(t *testing.T) {
n := &EvalCloseProvider{Name: "foo"}
providerName := ResolveProviderName("foo", nil)
n := &EvalCloseProvider{Name: providerName}
provider := &MockResourceProvider{}
ctx := &MockEvalContext{CloseProviderProvider: provider}
if _, err := n.Eval(ctx); err != nil {
@ -100,7 +101,7 @@ func TestEvalCloseProvider(t *testing.T) {
if !ctx.CloseProviderCalled {
t.Fatal("should be called")
}
if ctx.CloseProviderName != "foo" {
if ctx.CloseProviderName != providerName {
t.Fatalf("bad: %#v", ctx.CloseProviderName)
}
}

View File

@ -0,0 +1,3 @@
module "mod" {
source = "./mod"
}

View File

@ -0,0 +1,7 @@
provider "aws" {
alias = "mod"
}
resource "aws_instance" "bar" {
provider = "aws.mod"
}

View File

@ -138,13 +138,13 @@ func (t *CloseProviderTransformer) Transform(g *Graph) error {
p := v.(GraphNodeProvider)
// get the close provider of this type if we alread created it
closer := cpm[p.ProviderName()]
closer := cpm[p.Name()]
if closer == nil {
// create a closer for this provider type
closer = &graphNodeCloseProvider{ProviderNameValue: p.ProviderName()}
closer = &graphNodeCloseProvider{ProviderNameValue: p.Name()}
g.Add(closer)
cpm[p.ProviderName()] = closer
cpm[p.Name()] = closer
}
// Close node depends on the provider itself
@ -336,7 +336,7 @@ type graphNodeCloseProvider struct {
}
func (n *graphNodeCloseProvider) Name() string {
return fmt.Sprintf("provider.%s (close)", n.ProviderNameValue)
return n.ProviderNameValue + " (close)"
}
// GraphNodeEvalable impl.