mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
terraform: counts can't be computed
This commit is contained in:
parent
ced4125037
commit
53d05cb81f
@ -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) {
|
func TestContextPlan_countVar(t *testing.T) {
|
||||||
m := testModule(t, "plan-count-var")
|
m := testModule(t, "plan-count-var")
|
||||||
p := testProvider("aws")
|
p := testProvider("aws")
|
||||||
|
@ -1595,7 +1595,15 @@ func (p *graphSharedProvider) MergeConfig(
|
|||||||
|
|
||||||
// Expand will expand this node into a subgraph if Expand is set.
|
// Expand will expand this node into a subgraph if Expand is set.
|
||||||
func (n *GraphNodeResource) Expand() ([]*depgraph.Noun, error) {
|
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()
|
count, err := n.Config.Count()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
8
terraform/test-fixtures/plan-count-computed/main.tf
Normal file
8
terraform/test-fixtures/plan-count-computed/main.tf
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
resource "aws_instance" "foo" {
|
||||||
|
num = "2"
|
||||||
|
compute = "foo"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_instance" "bar" {
|
||||||
|
count = "${aws_instance.foo.foo}"
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user