terraform: multi-variables work with count = 1 [GH-115]
This commit is contained in:
parent
b19a976696
commit
87f4b49f85
|
@ -13,6 +13,7 @@ IMPROVEMENTS:
|
|||
BUG FIXES:
|
||||
|
||||
* core: Default variable file "terraform.tfvars" is auto-loaded. [GH-59]
|
||||
* core: Multi-variables (`foo.*.bar`) work even when `count = 1`. [GH-115]
|
||||
* providers/cloudflare: Include the proper bins so the cloudflare
|
||||
provider is compiled
|
||||
* providers/aws: Engine version for RDS now properly set [GH-118]
|
||||
|
|
|
@ -406,6 +406,13 @@ func (c *Context) computeResourceMultiVariable(
|
|||
var values []string
|
||||
for i := 0; i < cr.Count; i++ {
|
||||
id := fmt.Sprintf("%s.%d", v.ResourceId(), i)
|
||||
|
||||
// If we're dealing with only a single resource, then the
|
||||
// ID doesn't have a trailing index.
|
||||
if cr.Count == 1 {
|
||||
id = v.ResourceId()
|
||||
}
|
||||
|
||||
r, ok := c.state.Resources[id]
|
||||
if !ok {
|
||||
continue
|
||||
|
|
|
@ -1781,6 +1781,29 @@ func TestContextPlan_taint(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestContextPlan_varMultiCountOne(t *testing.T) {
|
||||
c := testConfig(t, "plan-var-multi-count-one")
|
||||
p := testProvider("aws")
|
||||
p.DiffFn = testDiffFn
|
||||
ctx := testContext(t, &ContextOpts{
|
||||
Config: c,
|
||||
Providers: map[string]ResourceProviderFactory{
|
||||
"aws": testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
plan, err := ctx.Plan(nil)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
actual := strings.TrimSpace(plan.String())
|
||||
expected := strings.TrimSpace(testTerraformPlanVarMultiCountOneStr)
|
||||
if actual != expected {
|
||||
t.Fatalf("bad:\n%s", actual)
|
||||
}
|
||||
}
|
||||
|
||||
func TestContextRefresh(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
c := testConfig(t, "refresh-basic")
|
||||
|
|
|
@ -478,3 +478,19 @@ aws_instance.foo:
|
|||
ID = bar
|
||||
num = 2
|
||||
`
|
||||
|
||||
const testTerraformPlanVarMultiCountOneStr = `
|
||||
DIFF:
|
||||
|
||||
CREATE: aws_instance.bar
|
||||
foo: "" => "2"
|
||||
type: "" => "aws_instance"
|
||||
CREATE: aws_instance.foo
|
||||
num: "" => "2"
|
||||
type: "" => "aws_instance"
|
||||
|
||||
STATE:
|
||||
|
||||
<no state>
|
||||
`
|
||||
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
resource "aws_instance" "foo" {
|
||||
num = "2"
|
||||
|
||||
count = 1
|
||||
}
|
||||
|
||||
resource "aws_instance" "bar" {
|
||||
foo = "${aws_instance.foo.*.num}"
|
||||
}
|
Loading…
Reference in New Issue