| Description |
This article describes how to use API tokens to log in to FortiManager with Terraform. Terraform supports two types of authentication which are static credentials (username/password and API token) and environment variables. 'API token' also refers to API keys in this context. Since Terraform does not support letting the provider define the logout logic, the static credential using username/password is not feasible as it will fill up the login session for each Terraform execution until the limit where the FortiManager will deny the next login when the maximum login session is reached. To avoid this issue, it is recommended to use static credentials using API tokens instead. REST API admins using the token authentication method is possible as of FortiManager version 7.2.2 and above. |
| Scope | FortiManager version 7.2.2 and above. |
| Solution |
In FortiManager:
GUI Method:
When using an API key as the authentication method, the trust host must be provided to allow the source IP address access.
CLI Method:
config system admin user
2. Use the same CLI command to re-generate the API key:
execute api-user generate-key <API username>
Example:
execute api-user generate-key restapi_admin
In Terraform:
Use the token in the Terraform provider section script by adding it to the .tf script file. In this example, the user is logged in to ADOM: root.
Example:
provider "fortimanager" { scopetype = "adom" |
The Fortinet Security Fabric brings together the concepts of convergence and consolidation to provide comprehensive cybersecurity protection for all users, devices, and applications and across all network edges.
Copyright 2025 Fortinet, Inc. All Rights Reserved.