Skip to content

Commit

Permalink
Resolve issue CiscoDevNet#296
Browse files Browse the repository at this point in the history
  • Loading branch information
seconroy committed Oct 15, 2024
1 parent f7055cb commit 47b182e
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions internal/provider/resource_sdwan_configuration_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,30 +330,34 @@ func (r *ConfigurationGroupResource) Read(ctx context.Context, req resource.Read
state.fromBodyConfigGroup(ctx, res)

// Read config group devices
path := fmt.Sprintf("/v1/config-group/%v/device/associate/", state.Id.ValueString())
res, err = r.client.Get(path)
if strings.Contains(res.Get("error.message").String(), "Invalid config group passed") {
resp.State.RemoveResource(ctx)
return
} else if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve object (GET), got error: %s, %s", err, res.String()))
return
}
if value := res.Get("devices"); value.Exists() && len(value.Array()) > 0 {
path := fmt.Sprintf("/v1/config-group/%v/device/associate/", state.Id.ValueString())
res, err = r.client.Get(path)
if strings.Contains(res.Get("error.message").String(), "Invalid config group passed") {
resp.State.RemoveResource(ctx)
return
} else if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve object (GET), got error: %s, %s", err, res.String()))
return
}

state.fromBodyConfigGroupDevices(ctx, res)
state.fromBodyConfigGroupDevices(ctx, res)
}

// Read config group devices
path = fmt.Sprintf("/v1/config-group/%v/device/variables/", state.Id.ValueString())
res, err = r.client.Get(path)
if strings.Contains(res.Get("error.message").String(), "Invalid config group passed") {
resp.State.RemoveResource(ctx)
return
} else if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve object (GET), got error: %s, %s", err, res.String()))
return
}
if value := res.Get("devices"); value.Exists() && len(value.Array()) > 0 {
path := fmt.Sprintf("/v1/config-group/%v/device/variables/", state.Id.ValueString())
res, err = r.client.Get(path)
if strings.Contains(res.Get("error.message").String(), "Invalid config group passed") {
resp.State.RemoveResource(ctx)
return
} else if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve object (GET), got error: %s, %s", err, res.String()))
return
}

state.fromBodyConfigGroupDeviceVariables(ctx, res)
state.fromBodyConfigGroupDeviceVariables(ctx, res)
}

state.updateTfAttributes(ctx, &oldState)

Expand Down

0 comments on commit 47b182e

Please sign in to comment.