terraform: counts can't be computed

This commit is contained in:
Mitchell Hashimoto 2014-10-02 16:21:17 -07:00
parent ced4125037
commit 53d05cb81f
3 changed files with 34 additions and 1 deletions

View File

@ -2428,6 +2428,23 @@ func TestContextPlan_count(t *testing.T) {
}
}
func TestContextPlan_countComputed(t *testing.T) {
m := testModule(t, "plan-count-computed")
p := testProvider("aws")
p.DiffFn = testDiffFn
ctx := testContext(t, &ContextOpts{
Module: m,
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
})
_, err := ctx.Plan(nil)
if err == nil {
t.Fatal("should error")
}
}
func TestContextPlan_countVar(t *testing.T) {
m := testModule(t, "plan-count-var")
p := testProvider("aws")

View File

@ -1595,7 +1595,15 @@ func (p *graphSharedProvider) MergeConfig(
// Expand will expand this node into a subgraph if Expand is set.
func (n *GraphNodeResource) Expand() ([]*depgraph.Noun, error) {
// Expand the count out, which should be interpolated at this point
// If the count configuration is empty then it means that the
// count is computed. In this case, we set the count to one
// but set a flag telling upstream that we're computing.
if len(n.Config.RawConfig.Config()) == 0 {
return nil, fmt.Errorf(
"%s: computed count attribute not allowed", n.Resource.Id)
}
// Expand the count out, which should be interpolated at this point.
count, err := n.Config.Count()
if err != nil {
return nil, err

View File

@ -0,0 +1,8 @@
resource "aws_instance" "foo" {
num = "2"
compute = "foo"
}
resource "aws_instance" "bar" {
count = "${aws_instance.foo.foo}"
}