Skip to content

Commit

Permalink
fix: correctly handle null MD5 in project BGP settings (#632)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ctreatma authored Mar 29, 2024
1 parent 5fa78b9 commit 4d0b305
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
4 changes: 3 additions & 1 deletion internal/resources/metal/project/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
25 changes: 25 additions & 0 deletions internal/resources/metal/project/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,27 @@ 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"),
),
},
{
ResourceName: "equinix_metal_project.foobar",
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"),
),
},
},
})
}
Expand Down Expand Up @@ -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" {
Expand Down

0 comments on commit 4d0b305

Please sign in to comment.