integrationtest: include dynblock usage in the "terraformlike" test
Terraform is the prime use-case for the dynblock extension, so we'll include this here currently as a proof-of-concept for Terraform's usage, but eventually (once Terraform is actually using it) this'll give some insurance that it doesn't get broken.
This commit is contained in:
parent
d6fc633aa0
commit
60b539d5d7
@ -5,17 +5,14 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/zclconf/go-cty/cty"
|
|
||||||
|
|
||||||
"github.com/hashicorp/hcl2/hcldec"
|
|
||||||
|
|
||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
|
"github.com/hashicorp/hcl2/ext/dynblock"
|
||||||
"github.com/hashicorp/hcl2/gohcl"
|
"github.com/hashicorp/hcl2/gohcl"
|
||||||
|
|
||||||
"github.com/hashicorp/hcl2/hcl"
|
"github.com/hashicorp/hcl2/hcl"
|
||||||
"github.com/hashicorp/hcl2/hcl/hclsyntax"
|
"github.com/hashicorp/hcl2/hcl/hclsyntax"
|
||||||
"github.com/hashicorp/hcl2/hcl/json"
|
"github.com/hashicorp/hcl2/hcl/json"
|
||||||
|
"github.com/hashicorp/hcl2/hcldec"
|
||||||
|
"github.com/zclconf/go-cty/cty"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TestTerraformLike parses both a native syntax and a JSON representation
|
// TestTerraformLike parses both a native syntax and a JSON representation
|
||||||
@ -127,7 +124,22 @@ func TestTerraformLike(t *testing.T) {
|
|||||||
t.Errorf("wrong type %q; want %q", got, want)
|
t.Errorf("wrong type %q; want %q", got, want)
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg, diags := hcldec.Decode(r.Config, securityGroupDecode, nil)
|
// For this one we're including support for the dynamic block
|
||||||
|
// extension, since Terraform uses this to allow dynamic
|
||||||
|
// generation of blocks within resource configuration.
|
||||||
|
forEachCtx := &hcl.EvalContext{
|
||||||
|
Variables: map[string]cty.Value{
|
||||||
|
"var": cty.ObjectVal(map[string]cty.Value{
|
||||||
|
"extra_private_cidr_blocks": cty.ListVal([]cty.Value{
|
||||||
|
cty.StringVal("172.16.0.0/12"),
|
||||||
|
cty.StringVal("169.254.0.0/16"),
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
dynBody := dynblock.Expand(r.Config, forEachCtx)
|
||||||
|
|
||||||
|
cfg, diags := hcldec.Decode(dynBody, securityGroupDecode, nil)
|
||||||
if len(diags) != 0 {
|
if len(diags) != 0 {
|
||||||
t.Errorf("unexpected diagnostics decoding Config")
|
t.Errorf("unexpected diagnostics decoding Config")
|
||||||
for _, diag := range diags {
|
for _, diag := range diags {
|
||||||
@ -143,6 +155,12 @@ func TestTerraformLike(t *testing.T) {
|
|||||||
cty.ObjectVal(map[string]cty.Value{
|
cty.ObjectVal(map[string]cty.Value{
|
||||||
"cidr_block": cty.StringVal("192.168.0.0/16"),
|
"cidr_block": cty.StringVal("192.168.0.0/16"),
|
||||||
}),
|
}),
|
||||||
|
cty.ObjectVal(map[string]cty.Value{
|
||||||
|
"cidr_block": cty.StringVal("172.16.0.0/12"),
|
||||||
|
}),
|
||||||
|
cty.ObjectVal(map[string]cty.Value{
|
||||||
|
"cidr_block": cty.StringVal("169.254.0.0/16"),
|
||||||
|
}),
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
if !cfg.RawEquals(wantCfg) {
|
if !cfg.RawEquals(wantCfg) {
|
||||||
@ -280,6 +298,12 @@ resource "happycloud_security_group" "private" {
|
|||||||
ingress {
|
ingress {
|
||||||
cidr_block = "192.168.0.0/16"
|
cidr_block = "192.168.0.0/16"
|
||||||
}
|
}
|
||||||
|
dynamic "ingress" {
|
||||||
|
for_each = var.extra_private_cidr_blocks
|
||||||
|
content {
|
||||||
|
cidr_block = ingress.value
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
`
|
`
|
||||||
@ -313,7 +337,16 @@ const terraformLikeJSON = `
|
|||||||
{
|
{
|
||||||
"cidr_block": "192.168.0.0/16"
|
"cidr_block": "192.168.0.0/16"
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
"dynamic": {
|
||||||
|
"ingress": {
|
||||||
|
"for_each": "${var.extra_private_cidr_blocks}",
|
||||||
|
"iterator": "block",
|
||||||
|
"content": {
|
||||||
|
"cidr_block": "${block.value}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user