Cannot delete Amazon Web Service Account

Octopus version: 2018.7.14

Im trying to delete an Amazon Account from Infrastructure - Accounts, but I get error:
This account cannot be deleted as it is currently referenced by a variable. Please refer to account usage for more detail.

Under “Usage”, as you can see in attached image, Octopus say that its not used. And I dont think it should be used anywhere. It was used in a project variable before, but previous releases is either deleted or variables updated in them.

What could be wrong or how do I troubleshoot this?

error_delete

Hi Tobias, sorry to hear that you are running into issues.

This sounds like we are not showing all the usages in the UI. The document relationships that would be preventing the deletion should be stored in the RelatedDocuments table. You can get the account ID from the URL when on the account detail page. This account ID would look something like the following amazonwebservicesaccount-<name>. You can use this ID to query the database directly if you have access to do so.

Select * from RelatedDocument where RelatedDocumentId = 'account-id'

I would imagine that the usages being returned by the API would not be the same as the output of the SQL query. In order to confirm this, could I also get you to run the following script and provide the output, please?

Param(
  [Parameter(Mandatory=$true)]
  [string]
  $OctopusURL,
  [Parameter(Mandatory=$true)]
  [string]
  $OctopusAPIKey,
  [string]
  [Parameter(Mandatory=$true)]
  $AccountId
)

##PROCESS##
$header = @{ "X-Octopus-ApiKey" = $octopusAPIKey }
$endpoint = "$($OctopusURL)/api/accounts/$($AccountId)/usages";

Write-Host $endpoint

Invoke-WebRequest $endpoint -Method Get -Headers $header | Select-Object -ExpandProperty Content

I have created a secure upload location which you can use to provide the output of the above scripts. Please let me know if you run into any issues.

Regards,
Shaun

Hi,

thanks for response.

The first select query didnt result in any rows back.

Have ran the script and uploaded a file with result to the upload location.

/Tobias

Oh,

As you saw the script returned empty arrays so I did another attempt to remove the account now. And today it worked, so it has been deleted now.

Not really sure what we have done since yesterday but one thing is that we deployed a new release of the project that used this account before.

Anyway, Im satisified now :slight_smile:

Hi Tobias,

Thanks for that. It still feels a bit strange that the usage didn’t show up and there may still be a bug lurking here. I will try and reproduce and raise an issue if I manage to do so. I will accept the issue being resolved for you as a win for now though :slight_smile:

Please let us know if there is anything else we can help with!

Regards,
Shaun

Yes, something looked strange there.

Feel free to come back if you would like any other logs or information from me.

/Tobias