Back to all configurations
Environment

Service account, credential and data-source lookup

Create a Service Account with the all_editor role and a credential for it, keep the credential file as a sensitive output, and read the account back with the indykite_service_accounts data source.

Service account, credential and data-source lookup

A Service Account is the identity that calls the Config API and runs Terraform; it belongs to the organization, not to a project, and carries a role: all_editor may change configuration, all_viewer may only read.

This Terraform configuration:

1. Looks the organization up by name with the indykite_customer data source.

2. Creates a Service Account with the all_editor role.

3. Creates a credential for it with an expire_time within two years, so the returned credential file carries a ready-to-use token, and exposes that file as a sensitive output.

4. Reads the account back by exact name with the indykite_service_accounts data source, the pattern every list-by-name data source of the provider follows (a parent identifier plus a filter of exact names).

Use case

Scenario: a CI pipeline needs its own identity to apply the organization's Terraform modules, separate from the people's accounts.

- The account and its credential are created once by an administrator's Terraform run; the credential file goes to the pipeline's secret store through the sensitive output.

- The pipeline then authenticates with that file (INDYKITE_SERVICE_ACCOUNT_CREDENTIALS_FILE) and applies the project modules.

- Rotation is a second indykite_service_account_credential resource added before the first is removed; a read-only auditor account is the same resource with role all_viewer.

Requirements

- ServiceAccount credentials created in the IndyKite Hub for your organization, to run this configuration with.

- 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.

- The organization's name for the indykite_customer lookup.

Steps

1. Put your organization's name in the indykite_customer data source and apply.

2. Read the credential file from the sensitive output (terraform output -raw ci_credentials_file) straight into your secret store.

3. Configure the consumer, here a CI pipeline, with that file and run its own Terraform.

4. To rotate, add a second credential resource, switch the consumer to it, then remove the first.

A Service Account with a credential, exposed as a sensitive output, and a data-source lookup by name.

main.tf

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" {}

# The organization the service account belongs to, looked up by name.
data "indykite_customer" "org" {
  name = "your-organization-name"
}

# A Service Account authenticates Config API and Terraform calls. role is
# all_editor (may change configuration) or all_viewer (read only) and cannot be
# changed after creation.
resource "indykite_service_account" "ci" {
  customer_id  = data.indykite_customer.org.id
  name         = "terraform-ci"
  display_name = "CI pipeline"
  description  = "Applies this organization's Terraform modules"
  role         = "all_editor"
}

# A credential for it. With an expire_time at most two years ahead the
# credential file (service_account_config) carries a ready-to-use token.
resource "indykite_service_account_credential" "ci" {
  service_account_id = indykite_service_account.ci.id
  display_name       = "CI pipeline credential"
  expire_time        = "2027-10-01T00:00:00Z"
}

# The credential file is sensitive: write it to your secret store, never to logs.
output "ci_credentials_file" {
  value     = indykite_service_account_credential.ci.service_account_config
  sensitive = true
}

# Reading a service account back by exact name with a data source.
data "indykite_service_accounts" "ci" {
  customer_id = data.indykite_customer.org.id
  filter      = [indykite_service_account.ci.name]
  depends_on  = [indykite_service_account.ci]
}

output "ci_service_account_id" {
  value = data.indykite_service_accounts.ci.service_accounts[0].id
}