From 47633cebd85ff2f38137e5a3fc3231cc78832a22 Mon Sep 17 00:00:00 2001 From: Espen Albert Date: Mon, 16 Dec 2024 13:37:11 +0000 Subject: [PATCH] chore: Fixes converting to TPF by including all attributes in replication_specs (#2894) --- internal/testutil/acc/advanced_cluster_schema_v2.go | 6 ++++-- .../testutil/acc/advanced_cluster_schema_v2_test.go | 4 +++- internal/testutil/hcl/common.go | 13 +++++++++---- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/internal/testutil/acc/advanced_cluster_schema_v2.go b/internal/testutil/acc/advanced_cluster_schema_v2.go index 1bb7fc0ae0..c8965db6a9 100644 --- a/internal/testutil/acc/advanced_cluster_schema_v2.go +++ b/internal/testutil/acc/advanced_cluster_schema_v2.go @@ -146,7 +146,9 @@ func getReplicationSpecs(t *testing.T, body *hclsyntax.Body) cty.Value { assert.Equal(t, name, block.Type, "unexpected block type: %s", block.Type) vals = append(vals, hcl.GetAttrVal(t, block.Body)) } - return cty.ObjectVal(map[string]cty.Value{ + attributeValues := map[string]cty.Value{ name: cty.TupleVal(vals), - }) + } + hcl.AddAttributes(t, body, attributeValues) + return cty.ObjectVal(attributeValues) } diff --git a/internal/testutil/acc/advanced_cluster_schema_v2_test.go b/internal/testutil/acc/advanced_cluster_schema_v2_test.go index 98848f2925..348566fb10 100644 --- a/internal/testutil/acc/advanced_cluster_schema_v2_test.go +++ b/internal/testutil/acc/advanced_cluster_schema_v2_test.go @@ -56,6 +56,7 @@ func TestConvertAdvancedClusterToSchemaV2(t *testing.T) { cluster_type = "SHARDED" replication_specs { + zone_name = "zone1" region_configs { electable_specs { disk_size_gb = 10 @@ -198,7 +199,8 @@ func TestConvertAdvancedClusterToSchemaV2(t *testing.T) { priority = 6 provider_name = "AZURE" region_name = "US_EAST_2" - }] + }] + zone_name = "zone1" }, { region_configs = [{ analytics_specs = { diff --git a/internal/testutil/hcl/common.go b/internal/testutil/hcl/common.go index 79de5a4dab..3ca51adcda 100644 --- a/internal/testutil/hcl/common.go +++ b/internal/testutil/hcl/common.go @@ -53,15 +53,20 @@ func getTF() *tfexec.Terraform { func GetAttrVal(t *testing.T, body *hclsyntax.Body) cty.Value { t.Helper() ret := make(map[string]cty.Value) + AddAttributes(t, body, ret) + for _, block := range body.Blocks { + ret[block.Type] = GetAttrVal(t, block.Body) + } + return cty.ObjectVal(ret) +} + +func AddAttributes(t *testing.T, body *hclsyntax.Body, ret map[string]cty.Value) { + t.Helper() for name, attr := range body.Attributes { val, diags := attr.Expr.Value(nil) require.False(t, diags.HasErrors(), "failed to parse attribute %s: %s", name, diags.Error()) ret[name] = val } - for _, block := range body.Blocks { - ret[block.Type] = GetAttrVal(t, block.Body) - } - return cty.ObjectVal(ret) } func PrettyHCL(t *testing.T, content string) string {