# Environment configuration

> Create a project, an application, an application agent, an application agent credential to get an Application token.

**Category:** Environment
**Last Updated:** 2026-10-28
**Terraform Provider Docs:** https://registry.terraform.io/providers/indykite/indykite/latest/docs/resources/application_space, https://registry.terraform.io/providers/indykite/indykite/latest/docs/resources/application, https://registry.terraform.io/providers/indykite/indykite/latest/docs/resources/application_agent, https://registry.terraform.io/providers/indykite/indykite/latest/docs/resources/application_agent_credential
**Related Guides:** /guides/guide-terraform, /guides/guide-environment, /guides/guide-credentials

## Summary

This Terraform configuration sets up a complete IndyKite environment hierarchy:
1. Project: Container for applications and configurations.
2. Application: Represents your software system.
3. Application Agent: Identity that authenticates API calls.
4. Application Agent Credential: Token used for API authentication.
The configuration also creates an Identity Knowledge Graph (IKG) with an _Application node.

## Use Case

Scenario: You need to integrate your application with the IndyKite platform.
Before calling any IndyKite API (Capture, Query, Authorization), your application needs valid credentials. This configuration creates the required hierarchy and outputs an Application Agent token.
The token can be used as:
- Bearer token for REST API calls.
- API Key for SDK authentication.
Note: The Config API requires ServiceAccount credentials at the organization level, not Application Agent credentials.

## Requirements

- ServiceAccount credentials created in the IndyKite Hub for your organization.
- IndyKite Terraform provider 0.49.0 or later, the release the example pins in required_providers; the Terraform guide lists the version each feature first appeared in.
- Terraform CLI installed on your machine.

## Steps

1. Configure the Terraform provider with your ServiceAccount credentials.
2. Apply the Terraform configuration to create the environment hierarchy.
3. Retrieve the Application Agent credential from the Terraform output.
4. Use the credential as Bearer token or API Key in your application.

## Code Examples


**main.tf**

```hcl

terraform {
  required_providers {
    indykite = {
      source  = "indykite/indykite"
      version = ">= 0.49.0" # or a later release
    }
  }
}

# indykite provider integrates IndyKite platform with Terraform scripting.
# Provider for now does not support any parameters and all is set within service account credential file.
provider "indykite" {}

# call the indykite_customer datasource
data "indykite_customer" "customer1" {
  name = "your-customer-name"
}

# call the indykite_application_space resource to create a new project
resource "indykite_application_space" "appspace1" {
  customer_id  = data.indykite_customer.customer1.id
  name         = "project-name"
  display_name = "Project display name"
  description  = "Description of your project"
  region       = "europe-west1" # or us-east1
  ikg_size     = "4GB"          # default 2GB
}

# call the indykite_application resource to create a new application
resource "indykite_application" "application1" {
  app_space_id = indykite_application_space.appspace1.id
  name         = "application-name"
  display_name = "Application display name"
  description  = "Description of your application"
}

# call the indykite_application_agent to create a new application agent
resource "indykite_application_agent" "agent" {
  application_id  = indykite_application.application1.id
  name            = "application-agent-name"
  display_name    = "Application agent display name"
  description     = "Description of your application agent"
  api_permissions = ["Capture", "ContXIQ", "Authorization", "ReadDataSchema"]
}

# call the indykite_application_agent_credential to create a new application agent credential
resource "indykite_application_agent_credential" "with_public" {
  app_agent_id = indykite_application_agent.agent.id
  display_name = "Credential display name"
  expire_time  = "2026-12-31T12:34:56-01:00" #must be less than 2 years to generate a token
}


```


A replacement for the indykite_application_space block of main.tf, not an extra file: it keeps the appspace1 resource address so the application's reference still resolves, and adds ikg_schema_version. The argument is optional and defaults to v1; it cannot be changed after the project is created, and v1 is the only value the platform accepts today (v2 is refused). Needs provider 0.49.0.

**main.tf (indykite_application_space block, replacement)**

```hcl

# Replace the indykite_application_space "appspace1" block of main.tf with this one.
resource "indykite_application_space" "appspace1" {
  customer_id        = "gid:AAAAAmluZHlraURlgAABDwAAAAA" # your organization GID
  name               = "project-name"
  display_name       = "Project display name"
  description        = "Description of your project"
  region             = "europe-west1" # or us-east1
  ikg_size           = "4GB"          # default 2GB
  ikg_schema_version = "v1"           # defaults to v1; cannot be changed after creation; v1 is the only accepted value today
}

```

## Common Errors

### ALREADY_EXISTS: Resource with this name already exists

**Solution:** Use a unique name or import the existing resource into Terraform state

### PERMISSION_DENIED: Insufficient permissions

**Solution:** Ensure ServiceAccount credentials have organization-level permissions

---

Source: https://developer.indykite.com/terraform/terraform-2