Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bug to impossible to update a vcd resource without a resource vcd_group define #518

Merged
merged 3 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading