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 key 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 helps you:

  • Ensure consistent configurations across environments.
  • Save time by automating API key setup.
  • Track changes with version control.

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 if you import 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 = "ops"
}

grants {
nrn = "organization=1:account=1"
role_slug = "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 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.