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

terraform: module orphans providers should inherit config #2476

Merged
merged 1 commit into from
Jun 25, 2015
Merged
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
48 changes: 48 additions & 0 deletions terraform/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4375,6 +4375,54 @@ func TestContext2Apply_moduleDestroyOrder(t *testing.T) {
}
}

func TestContext2Apply_moduleOrphanProvider(t *testing.T) {
m := testModule(t, "apply-module-orphan-provider-inherit")
p := testProvider("aws")
p.ApplyFn = testApplyFn
p.DiffFn = testDiffFn

p.ConfigureFn = func(c *ResourceConfig) error {
if _, ok := c.Get("value"); !ok {
return fmt.Errorf("value is not found")
}

return nil
}

// Create a state with an orphan module
state := &State{
Modules: []*ModuleState{
&ModuleState{
Path: []string{"root", "child"},
Resources: map[string]*ResourceState{
"aws_instance.bar": &ResourceState{
Type: "aws_instance",
Primary: &InstanceState{
ID: "bar",
},
},
},
},
},
}

ctx := testContext2(t, &ContextOpts{
Module: m,
State: state,
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
})

if _, err := ctx.Plan(); err != nil {
t.Fatalf("err: %s", err)
}

if _, err := ctx.Apply(); err != nil {
t.Fatalf("err: %s", err)
}
}

func TestContext2Apply_moduleVarResourceCount(t *testing.T) {
m := testModule(t, "apply-module-var-resource-count")
p := testProvider("aws")
Expand Down
8 changes: 6 additions & 2 deletions terraform/graph_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,12 @@ func (b *BuiltinGraphBuilder) Steps(path []string) []GraphTransformer {
&MissingProviderTransformer{Providers: b.Providers},
&ProviderTransformer{},
&CloseProviderTransformer{},
&PruneProviderTransformer{},
&DisableProviderTransformer{},

// Provisioner-related transformations
&MissingProvisionerTransformer{Provisioners: b.Provisioners},
&ProvisionerTransformer{},
&CloseProvisionerTransformer{},
&PruneProvisionerTransformer{},

// Run our vertex-level transforms
&VertexTransformer{
Expand Down Expand Up @@ -154,6 +152,12 @@ func (b *BuiltinGraphBuilder) Steps(path []string) []GraphTransformer {
// We don't do the following for modules.
if len(path) <= 1 {
steps = append(steps,
// Prune the providers and provisioners. This must happen
// only once because flattened modules might depend on empty
// providers.
&PruneProviderTransformer{},
&PruneProvisionerTransformer{},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Proactively did provisioners as well, didn't cause any tests to fail, I don't see why not.


// Create the destruction nodes
&DestroyTransformer{FullDestroy: b.Destroy},
&CreateBeforeDestroyTransformer{},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
provider "aws" {
value = "foo"
}