From fa5213cc1250800878e8f24c5f0b8319d4bbed7e Mon Sep 17 00:00:00 2001 From: David MICHENEAU Date: Fri, 15 Sep 2023 15:44:40 +0200 Subject: [PATCH] fix: update testacc vdcgroup and vdc resource --- .changelog/521.txt | 3 +++ internal/provider/vdc/vdc_resource.go | 17 ++++++++++++++++- internal/testsacc/vdc_resource_test.go | 23 ++++++++++++----------- 3 files changed, 31 insertions(+), 12 deletions(-) create mode 100644 .changelog/521.txt diff --git a/.changelog/521.txt b/.changelog/521.txt new file mode 100644 index 000000000..156a2fb18 --- /dev/null +++ b/.changelog/521.txt @@ -0,0 +1,3 @@ +```release-note:bug +`resource/cloudavenue_vdc` - Fix bug in vdc about vcgroup field or vdc_group resource. +``` diff --git a/internal/provider/vdc/vdc_resource.go b/internal/provider/vdc/vdc_resource.go index ff02facd4..53b1bba26 100644 --- a/internal/provider/vdc/vdc_resource.go +++ b/internal/provider/vdc/vdc_resource.go @@ -346,11 +346,26 @@ func (r *vdcResource) Update(ctx context.Context, req resource.UpdateRequest, re return } - var err error + // Get vDC info var httpR *http.Response + var err error + var group string + vdc, httpR, err := r.client.APIClient.VDCApi.GetOrgVdcByName(auth, state.Name.ValueString()) + if httpR != nil { + defer func() { + err = errors.Join(err, httpR.Body.Close()) + }() + } + // check if vdcGroup exists + if !plan.VDCGroup.IsNull() { + group = plan.VDCGroup.ValueString() + } else { + group = vdc.VdcGroup + } // Convert from Terraform data model into API data model body := apiclient.UpdateOrgVdcV2{ + VdcGroup: group, Vdc: &apiclient.OrgVdcV2{ Name: plan.Name.ValueString(), Description: plan.Description.ValueString(), diff --git a/internal/testsacc/vdc_resource_test.go b/internal/testsacc/vdc_resource_test.go index 72b926641..889c9bd52 100644 --- a/internal/testsacc/vdc_resource_test.go +++ b/internal/testsacc/vdc_resource_test.go @@ -13,7 +13,6 @@ import ( const testAccVDCResourceConfig = ` resource "cloudavenue_vdc" "example" { name = "MyVDC1" - vdc_group = "MyGroup" description = "Example vDC created by Terraform" cpu_allocated = 22000 memory_allocated = 30 @@ -28,8 +27,13 @@ resource "cloudavenue_vdc" "example" { default = true limit = 500 }] - - } +} +resource "cloudavenue_vdc_group" "example" { + name = "MyGroup" + vdc_ids = [ + cloudavenue_vdc.example.id, + ] +} ` // Temp test during deprecation notice of vdc_group attribute @@ -52,7 +56,6 @@ resource "cloudavenue_vdc" "example" { default = true limit = 500 }] - } resource "cloudavenue_vdc" "example2" { @@ -87,7 +90,6 @@ func TestAccVDCResource(t *testing.T) { Check: resource.ComposeAggregateTestCheckFunc( resource.TestMatchResourceAttr(resourceName, "id", regexp.MustCompile(uuid.VDC.String()+`[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}`)), resource.TestCheckResourceAttr(resourceName, "name", "MyVDC1"), - resource.TestCheckResourceAttr(resourceName, "vdc_group", "MyGroup"), resource.TestCheckResourceAttr(resourceName, "description", "Example vDC created by Terraform"), resource.TestCheckResourceAttr(resourceName, "cpu_allocated", "22000"), resource.TestCheckResourceAttr(resourceName, "memory_allocated", "30"), @@ -108,7 +110,6 @@ func TestAccVDCResource(t *testing.T) { Check: resource.ComposeAggregateTestCheckFunc( resource.TestMatchResourceAttr(resourceName, "id", regexp.MustCompile(uuid.VDC.String()+`[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}`)), resource.TestCheckResourceAttr(resourceName, "name", "MyVDC1"), - resource.TestCheckResourceAttr(resourceName, "vdc_group", "MyGroup"), resource.TestCheckResourceAttr(resourceName, "description", "Example vDC created by Terraform"), resource.TestCheckResourceAttr(resourceName, "cpu_allocated", "22000"), resource.TestCheckResourceAttr(resourceName, "memory_allocated", "40"), @@ -125,11 +126,11 @@ func TestAccVDCResource(t *testing.T) { // ImportruetState testing { // Import test with vdc - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateId: "MyVDC1", - ImportStateVerifyIgnore: []string{"vdc_group"}, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateId: "MyVDC1", + // ImportStateVerifyIgnore: []string{"vdc_group"}, }, }, })