Skip to content

Commit

Permalink
WIP: code for delete resource (rollback)
Browse files Browse the repository at this point in the history
  • Loading branch information
wojciech-bainhelixpe committed Dec 6, 2024
1 parent 25e964c commit 02e792c
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions internal/provider/resource_fmc_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ func (r *DeploymentResource) Delete(ctx context.Context, req resource.DeleteRequ
tflog.Debug(ctx, fmt.Sprintf("%s: Error getting device list from state", ""))
return
}
stateDeploymentJobId := state.Id.String()
stateDeploymentJobId := state.Id.ValueString()
var rollbackToDeploymentJobId string

// Read deployment history
Expand Down Expand Up @@ -611,7 +611,7 @@ JobIdLookup:
continue
}

if (itemMap["jobId"].(interface{}).(string) != stateDeploymentJobId) || (rollbackToDeploymentJobId == "") {
if (itemMap["id"].(interface{}).(string) != stateDeploymentJobId) && (rollbackToDeploymentJobId == "") {
continue
}

Expand Down Expand Up @@ -641,29 +641,29 @@ JobIdLookup:
rollbackToDeploymentJobId = stateDeploymentJobId
continue
} else {
rollbackToDeploymentJobId = itemMap["jobId"].(interface{}).(string)
rollbackToDeploymentJobId = itemMap["id"].(interface{}).(string)
break JobIdLookup
}
}
}
}

// Trigger rollback
if rollbackToDeploymentJobId != "" {
if rollbackToDeploymentJobId != "" && rollbackToDeploymentJobId != stateDeploymentJobId {

urlPath = "/api/fmc_config/v1/domain/{domainUUID}/deployment/rollbackrequests"
body := `{ ` + "\n"
body += ` "type": "RollbackRequest",` + "\n"
body += ` "rollbackDeviceList": [` + "\n"
body += ` {` + "\n"
body += ` "deploymentJobId": "` + rollbackToDeploymentJobId + `",` + "\n"
body := `{ `
body += ` "type": "RollbackRequest",`
body += ` "rollbackDeviceList": [`
body += ` {`
body += ` "deploymentJobId": "` + rollbackToDeploymentJobId + `",`
// *** It has to be fixed to add device list rather than single device
body += ` "deviceList": [` + "\n"
body += ` "` + stateDeviceList[0] + `"` + "\n"
body += ` ]` + "\n"
body += ` }` + "\n"
body += ` ]` + "\n"
body += `}` + "\n"
body += ` "deviceList": [`
body += ` "` + stateDeviceList[0] + `"`
body += ` ]`
body += ` }`
body += ` ]`
body += `}`

res, err = r.client.Post(urlPath, body, reqMods...)
if err != nil {
Expand Down

0 comments on commit 02e792c

Please sign in to comment.