Ankra Terraform Provider
The provider is published on the Terraform Registry as ankraio/ankra. Since 0.3.0 it covers what the ankra CLI can create, change or delete: 97 resources and 42 data sources. On 0.2.x only the six cluster resources and ankra_clusters exist; everything else on this page needs 0.3.0 or later. Check which version the user can install (terraform providers or the Registry) before writing HCL for a newer resource. Describe the provider exactly as here: do not invent arguments, and check the Registry docs for each resource's full schema.
Operational commands stay in the CLI: logs, exec, metrics, runs and reruns, cluster scale, cluster upgrade, chat, the AI board. Never wrap them in local-exec.
Recommended path
This is the infrastructure as code golden path in ankra-platform-principles: use the provider when the organisation already runs Terraform; otherwise GitOps as the source of truth (ankra-gitops, ankra cluster apply) is the default. Keep one source of truth per object: a given cluster's Stacks live in GitOps YAML or in ankra_cluster, never both, and nothing Terraform manages is also changed in the portal or with the CLI. Applications still ship through ankra-ship and Ankra Pipelines; Terraform declares them, it does not replace the pipeline.
Provider block
terraform {
required_providers {
ankra = {
source = "ankraio/ankra"
version = "~> 0.3.0"
}
}
}
provider "ankra" {
project_id = var.ankra_project_id # required in organisations with more than one project
}
variable "ankra_project_id" {
type = string
}
tokenorANKRA_TOKEN: an Ankra API token (ankra tokens create). Prefer the environment variable, or asensitivevariable fed from the secret store; never a literal in committed HCL. If no token reaches a resource, it fails withMissing API tokenand sends no request.base_urlorANKRA_BASE_URL: defaults tohttps://platform.ankra.app.organisation_idorANKRA_ORG(the CLI's variable for--org): act in another organisation the token's user belongs to. An ID, not a slug. The provider ignoresANKRA_ORGANISATION_ID, which Ankra Pipelines sets in every step to the run's organisation.project_idorANKRA_PROJECT_ID: the project to act in. Set it in any organisation that uses projects. Without it a token acts in the organisation's default project, or the oldest project a project-only member reaches, never the project its user last picked in the portal. The resources added in 0.3.0 refuse to run in an organisation with more than one project until it is set. An ID, not a slug.- Terraform 1.0 or newer.
ankra_application_env_secret.value_wo(write-only) needs Terraform 1.11.
What exists (0.3.0, plus 0.5.0 where marked)
| Area | Resources | Data sources |
|---|---|---|
| Clusters Ankra builds | ankra_hetzner_cluster, ankra_digitalocean_cluster, ankra_ovh_cluster, ankra_upcloud_cluster, ankra_scaleway_cluster, ankra_aws_cluster, ankra_proxmox_cluster, ankra_morpheus_cluster, ankra_ankracloud_cluster, ankra_playground | ankra_clusters, ankra_cluster, ankra_kubernetes_versions, ankra_playground_plans |
| Managed Kubernetes (DOKS, UKS, GKE, AKS, EKS, OVHcloud MKS, Kapsule, Ankra Cloud Kubernetes) | ankra_managed_cluster, ankra_managed_node_pool | |
| Node groups | ankra_node_group | ankra_node_groups |
| Imported clusters and Stacks | ankra_cluster | |
| Credentials | ankra_{hetzner,digitalocean,upcloud,ovh,scaleway,azure,ankracloud,morpheus,proxmox}_credential, ankra_aws_role_credential, ankra_aws_keys_credential, ankra_ssh_key_credential | ankra_credentials, ankra_credential |
| Helm and variables | ankra_helm_registry, ankra_helm_registry_credential, ankra_organisation_variable, ankra_cluster_variable | ankra_helm_registries, ankra_helm_registry_credentials, ankra_helm_chart, ankra_organisation_variables, ankra_cluster_variables |
| Cluster settings | ankra_cluster_access_grant, ankra_cluster_ssh_keys, ankra_cluster_custom_dns_zone, ankra_cluster_power_schedule, ankra_cluster_agent_auto_upgrade, ankra_cluster_agent_ci_settings, ankra_cluster_log_shipping, ankra_cluster_mesh, ankra_cluster_mesh_member | ankra_cluster_access_grants, ankra_cluster_custom_dns_zones, ankra_cluster_power_schedules, ankra_cluster_meshes |
| Alerts and DNS | ankra_alert_destination, ankra_alert_route, ankra_organisation_dns_record, ankra_organisation_custom_dns_zone, ankra_organisation_domain, ankra_dns_credential, ankra_cloudflare_credential, ankra_cloudflare_dns_record | ankra_alert_destinations, ankra_alert_routes, ankra_organisation_dns_zone, ankra_organisation_dns_records, ankra_organisation_custom_dns_zones, ankra_dns_credentials, ankra_cloudflare_credentials, ankra_cloudflare_domains |
| Applications and pipelines | ankra_application, ankra_application_settings, ankra_application_auto_deploy, ankra_application_ai_config, ankra_application_demo_config, ankra_application_env_secret, ankra_application_deployment, ankra_pipeline_repository, ankra_pipeline_definition, ankra_pipeline_schedule, ankra_pipeline_merge_train | ankra_applications, ankra_application, ankra_pipeline_repositories |
| Stack profiles, backups, image registry | ankra_stack_profile, ankra_stack_profile_version, ankra_stack_profile_share, ankra_stack_profile_logo, ankra_backup_vault, ankra_object_storage_bucket, ankra_registry_project, ankra_registry_robot, ankra_registry_retention | ankra_stack_profiles, ankra_backup_vaults, ankra_object_storage_buckets, ankra_registry_projects, ankra_registry_robots |
| Organisation and access | ankra_organisation, ankra_organisation_member, ankra_project (0.5.0), ankra_oidc_trust_policy (0.5.0), ankra_api_token, ankra_service_token, ankra_mcp_server, ankra_mcp_tool_grant, ankra_ci_settings, ankra_ci_pool_member, ankra_ai_review_repository, ankra_ai_review_related_repository, ankra_ai_spend_cap, ankra_ai_environment | ankra_organisation, ankra_organisations, ankra_mcp_servers, ankra_projects, ankra_project, ankra_oidc_trust_policies, ankra_cluster_access_policy (all 0.5.0) |
| AI, cost, security, services, targets | ankra_ai_provider, ankra_ai_anthropic_key, ankra_ai_openrouter_key, ankra_ai_openai_compatible, ankra_ai_endpoint, ankra_ai_model, ankra_ai_lane_model, ankra_ai_board_identity, ankra_cost_budget, ankra_cost_autopilot, ankra_cost_autopilot_override, ankra_cost_settings, ankra_security_disposition, ankra_security_compliance_framework, ankra_security_report_schedule, ankra_service_placement_policy, ankra_service_consumer, ankra_host_join_token | ankra_ai_models, ankra_ai_endpoints, ankra_ai_lanes, ankra_cost_budgets, ankra_security_compliance_frameworks, ankra_host_targets, ankra_deploy_environments |
Projects and GitHub OIDC trust (provider 0.5.0). These belong to the organisation and need no provider project_id, however many projects exist.
resource "ankra_project" "payments" {
name = "Payments"
slug = "payments" # immutable on the platform: changing it replaces the project
}
resource "ankra_service_token" "payments_ci" {
name = "payments-ci"
role_slug = "member"
project_id = ankra_project.payments.id # pin the CI token to the project
}
resource "ankra_oidc_trust_policy" "deploy" {
name = "payments-deploy"
repository_owner = "my-org"
repository_name = "payments"
repository_owner_id = 1234567 # gh api users/my-org --jq .id
repository_id = 89012345 # gh api repos/my-org/payments --jq .id
ref = "refs/heads/main" # pin ref, environment or job_workflow_ref above viewer
role_slug = "operator"
}
ankra_projectneedsprojects.manage; destroy is refused while the project holds resources (ankra project movethem first), and the Default project is never deleted. Import by ID or slug.ankra_oidc_trust_policyhas no in-place update: changing any argument deletes the policy (revoking every token it minted) and creates a new one. It needsmembers.manageon a person's own API token; service tokens and project-pinned tokens are refused.ttl_seconds60-3600 (900),allow_pull_requestfalse,scopesonlymcp:read/mcp:writeand never empty. The workflow signs in withankra login --github-oidc.data.ankra_cluster_access_policyis read-only on purpose: changing the policy needs the human-onlykube_access.policy, which no token carries. Propose withankra org access-policy setand have an owner or admin apply it; use the data source in acheckblock.
Not available as Terraform: stack variables (stack-scoped ankra cluster stacks variables; use cluster or organisation variables, or the stack's own YAML), managed services setup, stack profile builder drafts, restore points and restores, migrations, and every operational command above.
A cluster from scratch
resource "ankra_hetzner_credential" "main" {
name = "hetzner-main"
api_token = var.hcloud_token
}
resource "ankra_ssh_key_credential" "ops" {
name = "ops"
ssh_public_key = file(pathexpand("~/.ssh/id_ed25519.pub"))
}
resource "ankra_hetzner_cluster" "prod" {
name = "prod"
credential_id = ankra_hetzner_credential.main.id
location = "fsn1"
ssh_key_credential_id = ankra_ssh_key_credential.ops.id
control_plane_count = 3
control_plane_server_type = "cpx32"
worker_count = 2
worker_server_type = "cpx32"
gitops_repository = "my-org/platform-gitops"
gitops_branch = "main"
gitops_credential_name = "my-github-credential"
}
resource "ankra_node_group" "gpu" {
cluster_id = ankra_hetzner_cluster.prod.cluster_id
name = "gpu"
instance_type = "cpx42"
node_count = 2
labels = { accelerator = "gpu" }
}
resource "ankra_cluster_variable" "domain" {
cluster_id = ankra_hetzner_cluster.prod.cluster_id
name = "ingress_domain"
value = "apps.example.com"
}
variable "hcloud_token" {
type = string
sensitive = true
}
Clusters
- Lane arguments keep each cloud's own words: Hetzner
*_server_type+location; DigitalOcean*_size+region; OVHcloud*_flavor_id+region; UpCloud*_plan+zone; Scaleway*_type+region+zone; AWS, Proxmox, Morpheus and Ankra Cloud likewise.ssh_key_credential_idis anankra_ssh_key_credential.id; set it on Hetzner too, because a Hetzner cluster needs an SSH key credential. - A cluster's own provisioning arguments force replacement (counts and sizes on the cluster resource included). Resize with
ankra_node_group(node_count,instance_type,labels,taints,autoscalingupdate in place; an instance-type change drains and power-cycles each node and the apply waits for the roll) or withankra cluster scale. Never present a replacement as a resize; read the plan. distributiondefaults tokubeadm,cnitocilium. Create waits forrunning(default 60m);wait_for_ready = falsereturns at once.- Destroy waits until the cluster has left Ankra on the newer lanes.
force_destroydefaults tofalseon AWS, Proxmox, Morpheus and Ankra Cloud and totrueon the original five;accept_volume_data_loss(AWS, Ankra Cloud) must be set before the platform deletes a cluster that still holds persistent volumes. ankra_managed_cluster:provider_name+credential_id+location, provider-specific options asprovider_options = jsonencode({...}), andnode_poolsas a map keyed by pool name.node_countandautoscalingchange in place; adding a key adds a pool, removing one deletes it. To change a pool's size, rename its key: the new pool is added and the old one is deleted only after the new pool's nodes are Ready (UKS and OVHcloud MKS cannot be verified, so both pools are kept and the apply errors).destroy_modeisdelete_provider_clusterfor clusters this resource created anddisconnectfor imported ones.wait_for_agent = truewaits until the agent isonline.ankra_playground: moving from a paid plan totrialis refused unlessallow_trial_downgrade = true.
`ankra_cluster` (an existing cluster and its Stacks)
resource "ankra_helm_registry" "traefik" {
name = "traefik"
url = "https://traefik.github.io/charts"
}
resource "ankra_cluster" "prod" {
cluster_name = "my-cluster"
github_credential_name = "my-github-credential"
github_repository = "my-org/my-repo"
github_branch = "main"
stacks {
name = "ingress"
manifests {
name = "traefik-namespace"
manifest_base64 = base64encode(file("${path.module}/traefik-namespace.yaml"))
}
addons {
name = "traefik"
chart_name = "traefik"
chart_version = "37.1.1"
registry_name = ankra_helm_registry.traefik.name
registry_url = ankra_helm_registry.traefik.url
namespace = "traefik"
parents = ["manifest:traefik-namespace"]
configuration = file("${path.module}/traefik-values.yaml")
job_configuration = jsonencode({ create_job_timeout = 600 })
}
}
}
parents:"manifest:<name>"or"addon:<name>"; a bare name only when exactly one member has it. Unset keeps the stored order;[]removes it.- Add-ons:
registry_url(https://oroci://) is required;registry_name/registry_credential_namename anankra_helm_registry/ankra_helm_registry_credential. Pinchart_version, for example fromdata.ankra_helm_chart.<name>.latest_version. cluster_nameforces replacement; creating with an existing name adopts that cluster.helm_command(sensitive) installs the agent and is issued only on first registration; the user runs it. Stack variables are kept when the stack spec does not mention them.- Changing
github_repositoryorgithub_branchfails with a 409: repoint withankra cluster apply -f cluster.yaml --allow-repoint(seeankra-import-cluster), then update the HCL.
Rules that hold across resources
ankra_registry_robotreaches one project. Changingprojectdestroys and recreates it, with a newsecret. A robot reaching several projects is made with the CLI, the API or the portal, not this resource.- Secrets are write-only. API tokens, keys, passwords and webhook URLs are
Sensitive; the platform never returns them, so a secret changed outside Terraform is not detected. State still holds what the configuration set (prefervalue_woonankra_application_env_secretwith Terraform 1.11+). One-time values (ankra_api_token.token,ankra_service_token.token,ankra_registry_robotsecret, a generated SSH private key,ankra_host_join_token) are captured once into state. - A scope change is not a deletion. When
organisation_idorproject_idchanges, objects from the old scope are reported "not visible in the provider's current scope": they are neither recreated nor reported destroyed. Point the provider back, orterraform state rmto stop managing them. - Settings resources (
ankra_ci_settings,ankra_ai_environment,ankra_ai_spend_cap,ankra_cluster_agent_ci_settings,ankra_cost_settings,ankra_cost_autopilot) write only the attributes the configuration sets and reset only those on destroy. Some refuse to create over settings already customised in the portal; import them instead. - Tokens. Changing a token's expiry, scopes, label or project mints a new token value in place (the new one first, then the old one is retired), so every holder must get the new value;
scopes = []is refused because an empty list means full authority. A service account's role and a member's role are changed in the portal, not Terraform; the plan stops when they differ. - Destructive replacements are refused at plan where they would lose data: a backup vault or bucket replacement while
destroy_provider_resources = true, a key change on a bring-your-own vault, a node pool shape change, a lane'sretention_policychange. - Applications. Creating
ankra_applicationopens a setup pull request on its repository (merged unattended ifankra_application_settings.auto_merge_setup_pull_requestsis on); replacing one tears down every deployment. Recommendlifecycle { prevent_destroy = true }.ankra_application_deploymentwaits (create timeout, default 30m) until setup is complete.ankra_pipeline_definitionis for repositories without a committed.ankra/pipeline.yaml, and protected sections still need an admin'sdefinitions approve. - Plan-time validation refuses what the platform would refuse at apply: reserved names, names with
/, values with surrounding whitespace the platform trims, enum values, past timestamps.
Import
Every resource imports, usually by its ID; cluster-scoped objects by <cluster_id>/<key> and managed clusters by <provider_name>/<cluster_id> (the Registry docs list each format). Cluster resources and credentials adopt the configured build arguments and secrets on the first apply after an import instead of planning a replacement, because the platform does not return them: write the configuration to match the real object before applying. ankra_host_join_token cannot be imported.
Known limits
- Stack variables cannot be managed: the token API offers no safe per-variable write yet.
- Resizes made outside Terraform to a cluster's own arguments are not detected; node groups and node pools do refresh.
- A credential or other secret changed outside Terraform is not detected (see above).
- On 0.2.x: only the six cluster resources and
ankra_clusters; the cloud lanes' provisioning arguments always force replacement, including after an import.
Upgrading
- 0.2.x to 0.3.0: set
project_idif the organisation uses projects. Imports of the original five cloud clusters now adopt the configuration instead of planning a rebuild. Read the first plan: validation is stricter. - 0.1.x to 0.2.x: set
distribution = "k3s"andcni = "flannel"on clusters created with the old defaults before upgrading, move the token to the provider, useregistry_url+registry_nameandjob_configuration = jsonencode({...})on add-ons, prefixparentswithmanifest:/addon:, and rotate any agent token a 0.1.x plan printed (helm_commandwas not sensitive).
Rules
- Read every
terraform planbefore applying; stop on any destroy or replace of a cluster, credential, token, vault, bucket or application and show it to the user. - Pin the provider version in
required_providers. - Protect Terraform state with a locking, encrypted remote backend: it holds tokens, secrets and
helm_command. - One source of truth. Manage a given object from Terraform, the CLI, the portal or GitOps YAML, never two of them.
- Without a provider resource for what the user needs, use the CLI rather than
local-exec.
Related skills
ankra-cloud-clustersandankra-managed-kubernetesfor choosing regions, machine types and providers.ankra-import-clusterfor the ImportCluster YAML thatankra cluster apply -ftakes.ankra-gitopsfor keeping cluster and Stack definitions in Git.ankra-securityfor token scopes, roles and access grants.ankra-clifor creating the token (ankra tokens create).ankra-platform-principlesfor credential and review discipline.