Skip to content

Commit

Permalink
fix: bug to impossible to update a vcd resource without a resource vc…
Browse files Browse the repository at this point in the history
…d_group define (#518)
  • Loading branch information
azrod authored Sep 14, 2023
1 parent 2546c4a commit 5ee4fe5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 22 deletions.
7 changes: 7 additions & 0 deletions .changelog/518.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:bug
`resource/cloudavenue_vcd` - Fix bug to impossible to update a vcd resource without a resource vcd_group define.
```

```release-note:dependency
deps: bumps github.com/orange-cloudavenue/cloudavenue-sdk-go from 0.1.2 to 0.1.3
```
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ require (
github.com/hashicorp/terraform-plugin-log v0.9.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.28.0
github.com/iancoleman/strcase v0.3.0
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.1.2
github.com/kr/pretty v0.3.1
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.1.3
github.com/rs/zerolog v1.30.0
github.com/vmware/go-vcloud-director/v2 v2.21.0
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df
Expand Down Expand Up @@ -57,7 +58,6 @@ require (
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/huandu/xstrings v1.4.0 // indirect
github.com/imdario/mergo v0.3.15 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.18 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zx
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
github.com/oklog/run v1.1.0 h1:GEenZ1cK0+q0+wsJew9qUg/DyD8k3JzYsZAi5gYi2mA=
github.com/oklog/run v1.1.0/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DVU=
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.1.2 h1:xyuYnnne38RHQqnFw1d5M9FllvlWN4qNQDKV1AQNGpI=
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.1.2/go.mod h1:bMSQ+EQ0CtwIca1J133sM9fc/4cAfLXN3r4TpnS0BDY=
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.1.3 h1:nnFO5vxf70gWZkPcM153LYwHA1fa+0QqtzH2t71AMFA=
github.com/orange-cloudavenue/cloudavenue-sdk-go v0.1.3/go.mod h1:bMSQ+EQ0CtwIca1J133sM9fc/4cAfLXN3r4TpnS0BDY=
github.com/peterhellberg/link v1.2.0 h1:UA5pg3Gp/E0F2WdX7GERiNrPQrM1K6CVJUUWfHa4t6c=
github.com/peterhellberg/link v1.2.0/go.mod h1:gYfAh+oJgQu2SrZHg5hROVRQe1ICoK0/HHJTcE0edxc=
github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4=
Expand Down
27 changes: 9 additions & 18 deletions internal/provider/vdc/vdc_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,14 @@ func (r *vdcResource) Read(ctx context.Context, req resource.ReadRequest, resp *

// Update updates the resource and sets the updated Terraform state on success.
func (r *vdcResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
var plan *vdcResourceModel
var (
plan *vdcResourceModel
state *vdcResourceModel
)

// Read Terraform plan data into the model
resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)

resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
if resp.Diagnostics.HasError() {
return
}
Expand Down Expand Up @@ -339,24 +342,9 @@ func (r *vdcResource) Update(ctx context.Context, req resource.UpdateRequest, re

var err error
var httpR *http.Response
// Get vDC info
vdc, httpR, err := r.client.APIClient.VDCApi.GetOrgVdcByName(auth, plan.Name.ValueString())
if httpR != nil {
defer func() {
err = errors.Join(err, httpR.Body.Close())
}()
}
var group string
// 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 All @@ -370,6 +358,10 @@ func (r *vdcResource) Update(ctx context.Context, req resource.UpdateRequest, re
},
}

if !state.VDCGroup.IsNull() {
body.VdcGroup = state.VDCGroup.ValueString()
}

// Iterate over the storage profiles and add them to the body.
for _, storageProfile := range plan.VDCStorageProfiles {
body.Vdc.VdcStorageProfiles = append(body.Vdc.VdcStorageProfiles, apiclient.VdcStorageProfilesV2{
Expand All @@ -386,7 +378,6 @@ func (r *vdcResource) Update(ctx context.Context, req resource.UpdateRequest, re

// Call API to update the resource and test for errors.
job, httpR, err = r.client.APIClient.VDCApi.UpdateOrgVdc(auth, body, body.Vdc.Name)

if httpR != nil {
defer func() {
err = errors.Join(err, httpR.Body.Close())
Expand Down

0 comments on commit 5ee4fe5

Please sign in to comment.