Skip to content

Commit

Permalink
fix: update testacc vdcgroup and vdc resource (#521)
Browse files Browse the repository at this point in the history
Co-authored-by: David MICHENEAU <[email protected]>
  • Loading branch information
dmicheneau and David MICHENEAU authored Sep 15, 2023
1 parent 9a7b5fe commit 08f92c9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .changelog/521.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
`resource/cloudavenue_vdc` - Fix bug in vdc about vdcgroup field or vdc_group resource.
```
17 changes: 16 additions & 1 deletion internal/provider/vdc/vdc_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
13 changes: 7 additions & 6 deletions internal/testsacc/vdc_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -52,7 +56,6 @@ resource "cloudavenue_vdc" "example" {
default = true
limit = 500
}]
}
resource "cloudavenue_vdc" "example2" {
Expand Down Expand Up @@ -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"),
Expand All @@ -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"),
Expand Down

0 comments on commit 08f92c9

Please sign in to comment.