Skip to content

Commit

Permalink
Fix identity domain destruction by deactivating the identity domain b…
Browse files Browse the repository at this point in the history
…efore deletion
  • Loading branch information
F21 committed Oct 17, 2023
1 parent 8131026 commit ea5aa29
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions internal/service/identity/identity_domain_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,21 +590,42 @@ func (s *IdentityDomainResourceCrud) Update() error {
}

func (s *IdentityDomainResourceCrud) Delete() error {
request := oci_identity.DeleteDomainRequest{}

tmp := s.D.Id()
request.DomainId = &tmp

request.RequestMetadata.RetryPolicy = tfresource.GetRetryPolicy(s.DisableNotFoundRetries, "identity")
deactivateRequest := oci_identity.DeactivateDomainRequest{}

deactivateRequest.DomainId = &tmp

deactivateRequest.RequestMetadata.RetryPolicy = tfresource.GetRetryPolicy(s.DisableNotFoundRetries, "identity")

response, err := s.Client.DeleteDomain(context.Background(), request)
deactivateResponse, err := s.Client.DeactivateDomain(context.Background(), deactivateRequest)
if err != nil {
return err
}

workId := response.OpcWorkRequestId
deactivateWorkId := deactivateResponse.OpcWorkRequestId
// Wait until it finishes
_, deactivateWorkRequestErr := domainWaitForWorkRequest(deactivateWorkId, "domain",
oci_identity.IamWorkRequestResourceActionTypeUpdated, s.D.Timeout(schema.TimeoutDelete), s.DisableNotFoundRetries, s.Client)

if deactivateWorkRequestErr != nil {
return deactivateWorkRequestErr
}

deleteRequest := oci_identity.DeleteDomainRequest{}

deleteRequest.DomainId = &tmp

deleteRequest.RequestMetadata.RetryPolicy = tfresource.GetRetryPolicy(s.DisableNotFoundRetries, "identity")

deleteResponse, err := s.Client.DeleteDomain(context.Background(), deleteRequest)
if err != nil {
return err
}

deleteWorkId := deleteResponse.OpcWorkRequestId
// Wait until it finishes
_, delWorkRequestErr := domainWaitForWorkRequest(workId, "domain",
_, delWorkRequestErr := domainWaitForWorkRequest(deleteWorkId, "domain",
oci_identity.IamWorkRequestResourceActionTypeUpdated, s.D.Timeout(schema.TimeoutDelete), s.DisableNotFoundRetries, s.Client)
return delWorkRequestErr
}
Expand Down

0 comments on commit ea5aa29

Please sign in to comment.