Skip to main content

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.

You need an ADMIN or OPS role to create and manage API keys.

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:

Secure your API keys
  • 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.
  1. 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
}
  1. Initialize the IaC tool.

    Run the initialization command for your chosen tool:

    tofu init
  2. Review your changes.

    Preview the changes before applying them:

    tofu plan
  3. Apply the configuration.

    If your changes look good, apply the configuration:

    tofu apply

Verify the API keys

After applying the configuration:

  1. Navigate to Platform settings > API keys in the nullplatform UI.

  2. Verify that your API keys are configured correctly.