Deleting a service account
Warning
Deleting a service account is permanent. You cannot restore a deleted service account; you can only re-create it.
- In the management console
, navigate to the folder the service account belongs to. - In the list of services, select Identity and Access Management.
- In the left-hand panel, select
Service accounts. - In the row with the service account you need, click
and select Delete. - In the window that opens, click Delete.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
-
See the description of the delete service account command:
yc iam service-account delete --help
-
Select a service account, e.g.,
my-robot
:yc iam service-account list
Result:
+----------------------+------------------+-------------------------------+ | ID | NAME | DESCRIPTION | +----------------------+------------------+-------------------------------+ | aje6o61dvog2******** | my-robot | | | aje9sda1ufvq******** | account_name | account_description | +----------------------+------------------+-------------------------------+
-
Delete the service account:
yc iam service-account delete my-robot
If you don't have Terraform, install it and configure the Yandex Cloud provider.
To delete a service account:
-
Open the Terraform configuration file and delete the fragment with the service account description.
Example of the service account description in the Terraform configuration:... resource "yandex_iam_service_account" "sa" { name = "my-robot" description = "this is my favorite service account" } ...
-
In the command line, go to the directory with the Terraform configuration file.
-
Check the configuration using this command:
terraform validate
If the configuration is correct, you will get this message:
Success! The configuration is valid.
-
Run this command:
terraform plan
The terminal will display a list of resources with parameters. No changes will be made at this step. If the configuration contains any errors, Terraform will point them out.
-
Apply the configuration changes:
terraform apply
-
Confirm the changes: type
yes
into the terminal and press Enter.You can verify that the service account was deleted in the management console
or using the CLI command:yc iam service-account list
To delete a service account, use the delete REST API method for the ServiceAccount resource or the ServiceAccountService/Delete gRPC API call.
Note
You cannot delete a service account while it is linked to some cloud resources, such as instance groups. First, update the service account in the resource settings or delete the resource and then delete the service account.