From 4d0b305f79b867119c78909bf6ee031568705f6a Mon Sep 17 00:00:00 2001 From: Charles Treatman Date: Fri, 29 Mar 2024 10:16:04 -0500 Subject: [PATCH] fix: correctly handle null MD5 in project BGP settings (#632) During the framework migration of the project resource, we missed that the framework-based resource doesn't correctly handle null values for the `md5` attribute in BGP config. This updates the basic project BGP test to cover that aspect of the project resource and updates the project model to avoid setting the in-state md5 value to `""` when it should be `nil`. Closes #630 --- internal/resources/metal/project/models.go | 4 ++- .../resources/metal/project/resource_test.go | 25 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/internal/resources/metal/project/models.go b/internal/resources/metal/project/models.go index f38053958..f50de7118 100644 --- a/internal/resources/metal/project/models.go +++ b/internal/resources/metal/project/models.go @@ -105,10 +105,12 @@ func parseBGPConfig(ctx context.Context, bgpConfig *metalv1.BgpConfig) fwtypes.L bgpConfigResourceModel[0] = BGPConfigModel{ DeploymentType: types.StringValue(string(bgpConfig.GetDeploymentType())), ASN: types.Int64Value(int64(bgpConfig.GetAsn())), - MD5: types.StringValue(bgpConfig.GetMd5()), Status: types.StringValue(string(bgpConfig.GetStatus())), MaxPrefix: types.Int64Value(int64(bgpConfig.GetMaxPrefix())), } + if bgpConfig.Md5.Get() != nil { + bgpConfigResourceModel[0].MD5 = types.StringValue(bgpConfig.GetMd5()) + } return fwtypes.NewListNestedObjectValueOfValueSlice[BGPConfigModel](ctx, bgpConfigResourceModel) } return fwtypes.NewListNestedObjectValueOfNull[BGPConfigModel](ctx) diff --git a/internal/resources/metal/project/resource_test.go b/internal/resources/metal/project/resource_test.go index 69e961678..f0a6c26e0 100644 --- a/internal/resources/metal/project/resource_test.go +++ b/internal/resources/metal/project/resource_test.go @@ -132,6 +132,9 @@ func TestAccMetalProject_BGPBasic(t *testing.T) { resource.TestCheckResourceAttr( "equinix_metal_project.foobar", "bgp_config.0.md5", "2SFsdfsg43"), + resource.TestCheckResourceAttr( + "equinix_metal_project.foobar", "bgp_config.0.asn", + "65000"), ), }, { @@ -139,6 +142,17 @@ func TestAccMetalProject_BGPBasic(t *testing.T) { ImportState: true, ImportStateVerify: true, }, + { + Config: testAccMetalProjectConfig_BGPWithoutMD5(rInt), + Check: resource.ComposeTestCheckFunc( + testAccMetalProjectExists("equinix_metal_project.foobar", &project), + resource.TestCheckNoResourceAttr( + "equinix_metal_project.foobar", "bgp_config.0.md5"), + resource.TestCheckResourceAttr( + "equinix_metal_project.foobar", "bgp_config.0.asn", + "65000"), + ), + }, }, }) } @@ -343,6 +357,17 @@ resource "equinix_metal_project" "foobar" { }`, r) } +func testAccMetalProjectConfig_BGPWithoutMD5(r int) string { + return fmt.Sprintf(` +resource "equinix_metal_project" "foobar" { + name = "tfacc-project-%d" + bgp_config { + deployment_type = "local" + asn = 65000 + } +}`, r) +} + func testAccMetalProjectConfig_BGP(r int, pass string) string { return fmt.Sprintf(` resource "equinix_metal_project" "foobar" {