Skip to content

Commit

Permalink
fix: update testacc vdcgroup and vdc resource
Browse files Browse the repository at this point in the history
  • Loading branch information
David MICHENEAU committed Sep 15, 2023
1 parent 9a7b5fe commit fa5213c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 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 vcgroup 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
23 changes: 12 additions & 11 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 All @@ -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"},
},
},
})
Expand Down

0 comments on commit fa5213c

Please sign in to comment.