Configure API keys with IaC tools
You can create and manage API keys using Infrastructure as Code (IaC) tools like OpenTofu or Terraform. We’ve created a plugin to help you configure API keys: API keys resource plugin.
Why use IaC for API Keys?
Managing API keys with IaC tools:
- ensures consistent configurations across environments.
- saves time by automating API key setup.
- provides version control for tracking changes.
Get started
Follow these steps to set up API keys using OpenTofu or Terraform:
- The API key's secret value is only stored in the
tfstate
file and cannot be retrieved again, even by importing the resource. - Ensure the
tfstate
file is securely stored and protected from unauthorized access.
-
Create a configuration file
Below is an example configuration to set up an API key for the nullplatform API. Replace the placeholder values in the example with your details.
terraform {
required_providers {
nullplatform = {
source = "nullplatform/nullplatform"
}
}
}
provider "nullplatform" {}
resource "nullplatform_api_key" "my_api_key" {
name = "Example API Key Name"
grants {
nrn = "organization=1:account=1"
role_slug = "account:ops"
}
grants {
nrn = "organization=1:account=1"
role_slug = "account:admin"
}
tags {
key = "example"
value = "true"
}
}
output "my_api_key_value" {
value = nullplatform_api_key.my_api_key.api_key
sensitive = true
}
-
Initialize the IaC tool.
Run the initialization command for your chosen tool:
- OpenTofu
- Terraform
tofu init
terraform init
-
Review your changes.
Preview the changes before applying them:
- OpenTofu
- Terraform
tofu plan
terraform plan
-
Apply the configuration.
If your changes look good, apply the configuration:
- OpenTofu
- Terraform
tofu apply
terraform apply
Verify the API keys
After applying the configuration:
-
Navigate to Platform settings > API keys in the nullplatform UI.
-
Verify that your API keys are configured correctly.