If both types of credentials are present in a Terraform configuration, you will be authenticated as your user account.
Authenticating with a service account
Service accounts are intended for managing resources in Nebius AI Cloud through non-UI interfaces, such as the Terraform provider.We recommend using a service account belonging to the project that contains the resources you want to manage.
- Create a service account if you haven’t already.
- Add the service account to a group to grant it necessary permissions. In most cases, a group with the
editorrole should be enough; add the account to a group with theadminrole only if you want to manage other accounts’ group memberships through Terraform. Learn more about groups and their permissions. - Create an authorized key.
service_account block to the provider configuration block (provider "nebius"). You can specify the required credentials (see below) directly in service_account, or indirectly by referring to environment variables that hold the values. Here are examples of both approaches:
- Directly
- Indirectly (with environment variables)
service_account:
-
Service account ID (field in
service_account:account_idoraccount_id_env). You can get the ID with this Nebius AI Cloud CLI command:Alternatively, usenebius iam service-account listand get the ID from.items[*].metadata.id. -
Authorized key ID (
public_key_idorpublic_key_id_env). You can list the authorized keys created for the service account with this command: -
Path to the private key that you used to create the authorized key (
private_key_fileorprivate_key_file_env).
account_id_env and public_key_id_env while specifying the private key path directly in private_key_file. If both fields in a pair are specified (e.g. account_id and account_id_env), the “direct” field (without _env, e.g. account_id) is used.
Authenticating with your user account
You can configure the Terraform provider to perform actions on behalf of your Nebius AI Cloud user account. However, this is less secure. It is recommended to use this authentication method only in local development environments. User account authentication uses access tokens. The lifetime of an access token is 12 hours. To get an access token: You can specify the token:-
In the
NEBIUS_IAM_TOKENenvironment variable (recommended). For example: -
In the provider configuration: