Handing a developer an infrastructure-as-code template is a start, but they still have to figure out where to run it, which Azure identity to use, and where to keep its state. What I'd rather do is let them request a cloud resource through a small Kubernetes API, while the platform team takes care of the provisioning and its credentials.
Crossplane lets you build that API on Kubernetes: you declare the resources you want, and provider controllers reconcile the external resources to match. I've been looking at platform engineering tooling lately, and since I use Terraform pretty much every day, I wanted to try this with provider-opentofu. It runs modules written in HashiCorp Configuration Language (HCL), the configuration language used by Terraform and OpenTofu, so we can reuse existing HCL modules while keeping the developer-facing API small.
If you've come across
provider-terraform, its README says the bundled Terraform version is frozen at 1.5.7 and points to the OpenTofu provider for newer capabilities.
If all you need is a quick, one-time resource group, running Terraform, OpenTofu, or Azure CLI directly is simpler. But if you want a repeatable provisioning workflow that you can eventually expose through a self-service developer portal, Crossplane with the OpenTofu provider is one way to do it. It's worth exploring when you want requests to fit into an existing Kubernetes workflow and stay under continuous reconciliation, as long as you're prepared to operate the control plane and govern its permissions.
In this post, I'll build the API on a small AKS cluster. We'll start by creating a resource group directly with OpenTofu, then request one through a custom resource. I picked a resource group because it keeps the walkthrough small, but any Azure resource with an OpenTofu module works the same way. Swap the module and the request parameters, and the rest of the setup stays as-is. This walkthrough is for the person building the platform API; the developer consuming it only needs the request in Step 7.
Consider this a side-quest in my Backstage with Azure series. The next post will do what this one sets up: create a Backstage template that submits an XResourceGroupRequest, so a developer can get a resource group from the portal without ever seeing the OpenTofu module.
Prerequisites
You'll need:
- Azure subscription
- Azure CLI
- kubectl
- Helm
- A Bash shell. Keep it open throughout the walkthrough so the variables stay available.
Sign in as a user who can create resources and assign Azure roles at subscription scope (Contributor alone doesn't allow role assignments). We'll use that user's object ID when granting access.
The commands below pin Crossplane to v2.5.0 and the OpenTofu provider to v1.2.0. The provider's image definition, in turn, pins OpenTofu to v1.13.10, which supports the backend authentication we'll use below. And since OpenTofu runs inside the provider's pod, you don't need it installed locally.
Use a lab or demo subscription for this walkthrough. The AKS nodes and storage incur charges until you delete them, and the provider will have broad permissions for this example.
Step 1: Create a small control plane
Sign in, then save the subscription and tenant IDs along with the signed-in user's object ID. We'll use them for authentication and role assignments:
az login
read -r AZURE_SUBSCRIPTION_ID AZURE_TENANT_ID <<< "$(az account show --query '[id, tenantId]' -o tsv | tr '\n' ' ')"
REQUESTER_OBJECT_ID=$(az ad signed-in-user show --query id -o tsv)Create a resource group and a single-node AKS cluster with workload identity and the OIDC issuer enabled. This lets the provider authenticate without a stored client secret, so we don't have to manage or rotate one.
az group create -n rg-crossplane -l westus3
az aks create \
-n aks-crossplane \
-g rg-crossplane \
--location westus3 \
--enable-workload-identity \
--enable-oidc-issuer \
--node-count 1 \
--no-ssh-keyAfter the cluster has been created, retrieve its credentials so you can interact with it using kubectl:
az aks get-credentials \
-n aks-crossplane \
-g rg-crossplaneStep 2: Install Crossplane
Install Crossplane with Helm, then confirm the deployments are ready. The custom resource definitions from the next step won't exist until they are:
helm repo add crossplane-stable https://charts.crossplane.io/stable
helm repo update
helm install crossplane \
crossplane-stable/crossplane \
--namespace crossplane-system \
--create-namespace \
--version 2.5.0 \
--wait \
--timeout 5m
kubectl get deployments -n crossplane-systemThe Crossplane and RBAC manager deployments should each show an available replica. If the install times out, check the pods in crossplane-system and their events before moving on.
Step 3: Connect the OpenTofu provider to Azure
The provider will use workload identity to exchange a Kubernetes service account token for a Microsoft Entra access token. Azure RBAC then determines what that identity can do.
Create the managed identity
First, create the managed identity OpenTofu will use to manage Azure resources:
PROVISIONER_IDENTITY=$(az identity create \
--name id-crossplane \
--resource-group rg-crossplane)
PROVISIONER_CLIENT_ID=$(echo "$PROVISIONER_IDENTITY" | jq -r .clientId)
PROVISIONER_OBJECT_ID=$(echo "$PROVISIONER_IDENTITY" | jq -r .principalId)Grant permission to create resource groups and assign access
Give that identity two Azure RBAC roles: Contributor lets it create resource groups, while Role Based Access Control Administrator lets the module grant the requester Contributor access.
az role assignment create \
--role "Contributor" \
--assignee-object-id "$PROVISIONER_OBJECT_ID" \
--assignee-principal-type ServicePrincipal \
--scope "/subscriptions/$AZURE_SUBSCRIPTION_ID"
az role assignment create \
--role "Role Based Access Control Administrator" \
--assignee-object-id "$PROVISIONER_OBJECT_ID" \
--assignee-principal-type ServicePrincipal \
--scope "/subscriptions/$AZURE_SUBSCRIPTION_ID"Because the provider creates new resource groups, these assignments are at subscription scope. That also gives it permission to assign roles throughout the subscription, so before using this on a shared platform, constrain both the provider's permissions and who can submit requests.
Trust the provider's Kubernetes service account
Next, create a federated identity credential. This is what tells Microsoft Entra ID to trust tokens issued by this cluster for the provider-opentofu service account in crossplane-system:
AKS_OIDC_ISSUER=$(az aks show \
-n aks-crossplane \
-g rg-crossplane \
--query "oidcIssuerProfile.issuerUrl" \
-o tsv)
az identity federated-credential create \
-n crossplane \
-g rg-crossplane \
--identity-name id-crossplane \
--issuer "$AKS_OIDC_ISSUER" \
--subject system:serviceaccount:crossplane-system:provider-opentofu \
--audience api://AzureADTokenExchangeThe exchange only works if all three values match what the pod actually presents, and they match exactly. Having the right Azure roles on the identity won't save you if one of them is off.
Configure and install the provider
A DeploymentRuntimeConfig controls the provider's pod and service account. It does two jobs here: it gives the provider a service account annotated with the managed identity's client and tenant IDs, and it configures the provider pod with the azure.workload.identity/use: "true" label so the AKS workload identity webhook injects tokens into it. The environment variables tell the Azure SDKs to use that injected identity instead of Azure CLI credentials.
Create this configuration before installing the provider so its first pod starts with the required settings:
kubectl apply -f - <<EOF
apiVersion: pkg.crossplane.io/v1beta1
kind: DeploymentRuntimeConfig
metadata:
name: provider-opentofu
spec:
serviceAccountTemplate:
metadata:
name: provider-opentofu
annotations:
azure.workload.identity/client-id: "${PROVISIONER_CLIENT_ID}"
azure.workload.identity/tenant-id: "${AZURE_TENANT_ID}"
deploymentTemplate:
spec:
selector: {}
template:
metadata:
labels:
app.kubernetes.io/name: provider-opentofu
azure.workload.identity/use: "true"
spec:
containers:
- name: package-runtime
args: ["--poll=5m", "--max-reconcile-rate=1", "--timeout=30m"]
env:
- name: ARM_USE_AKS_WORKLOAD_IDENTITY
value: "true"
- name: ARM_USE_CLI
value: "false"
- name: ARM_SUBSCRIPTION_ID
value: "${AZURE_SUBSCRIPTION_ID}"
- name: ARM_TENANT_ID
value: "${AZURE_TENANT_ID}"
- name: ARM_CLIENT_ID
value: "${PROVISIONER_CLIENT_ID}"
resources:
requests:
cpu: 500m
memory: 1Gi
limits:
memory: 4Gi
EOFWith the runtime config in place, install the provider itself and point it at that config with runtimeConfigRef. Then wait for it to report healthy:
kubectl apply -f - <<'EOF'
apiVersion: pkg.crossplane.io/v1
kind: Provider
metadata:
name: provider-opentofu
spec:
package: xpkg.upbound.io/upbound/provider-opentofu:v1.2.0
runtimeConfigRef:
name: provider-opentofu
EOF
kubectl wait --for=condition=Healthy providers.pkg.crossplane.io/provider-opentofu --timeout=5m
kubectl wait --for=condition=Established crd/workspaces.opentofu.m.upbound.io --timeout=2mBoth waits should succeed. A healthy provider means its runtime is ready, but we'll need the test in Step 5 to check Azure authentication.
If the provider doesn't become healthy, check its package events and pod logs before continuing:
kubectl describe providers.pkg.crossplane.io provider-opentofu
kubectl get pods -n crossplane-system -l app.kubernetes.io/name=provider-opentofu
kubectl logs -n crossplane-system -l app.kubernetes.io/name=provider-opentofu -c package-runtime --tail=80Step 4: Give the provider a place to keep state
OpenTofu, like Terraform, uses state to keep track of the resources it manages, but the provider's local working directory isn't durable storage. If the pod is replaced and that local state is lost, OpenTofu can lose track of resources it already created. We'll use Azure Storage as a remote backend so the state stays available for later reconciles and cleanup.
Create the storage account
Set the storage account name once, using the Bash expression below to add a suffix that helps us choose a globally unique name. If Azure reports that the name is taken, choose another and rerun account creation.
The account disables anonymous blob access and shared-key authorization, so we'll use Microsoft Entra authorization instead. That way, neither the provider nor our CLI needs a storage account key.
STORAGE_ACCOUNT="stcrossplane${RANDOM}"
az storage account create \
-n "$STORAGE_ACCOUNT" \
-g rg-crossplane \
-l westus3 \
--kind StorageV2 \
--sku Standard_LRS \
--min-tls-version TLS1_2 \
--allow-blob-public-access false \
--allow-shared-key-access falseThese settings require TLS 1.2 or later, but they don't disable the account's public network endpoint.
Grant blob access, then create the container
Management-plane roles alone don't grant blob data access, so assign Storage Blob Data Contributor to both the provider and your signed-in user. This lets the provider read and write state, and lets you create the container and inspect its contents.
STORAGE_ID=$(az storage account show \
-n "$STORAGE_ACCOUNT" \
-g rg-crossplane \
--query id -o tsv)
az role assignment create \
--assignee-object-id "$PROVISIONER_OBJECT_ID" \
--assignee-principal-type ServicePrincipal \
--role "Storage Blob Data Contributor" \
--scope "$STORAGE_ID"
az role assignment create \
--assignee-object-id "$REQUESTER_OBJECT_ID" \
--assignee-principal-type User \
--role "Storage Blob Data Contributor" \
--scope "$STORAGE_ID"Once the role assignments are in place, create the storage container:
az storage container create \
-n tfstate \
--account-name "$STORAGE_ACCOUNT" \
--auth-mode loginThe result should contain "created": true, or false if the container already exists. If you get AuthorizationPermissionMismatch, give the role assignments a few minutes to propagate, then retry the container command. Check that both object IDs have Storage Blob Data Contributor:
az role assignment list \
--scope "$STORAGE_ID" \
--query '[].{role:roleDefinitionName,principal:principalId}' \
-o tableConfigure the state backend
A ClusterProviderConfig supplies shared OpenTofu settings to the Workspaces that reference it. We'll use it to configure the Azure Blob backend.
The backend and the AzureRM provider authenticate separately, but workload identity authenticates both clients. The use_azuread_auth setting tells the backend to access blobs directly instead of retrieving an account key, since shared-key authorization is disabled.
Bash inserts the storage account name into the block below, while the pod reads its identity settings from the environment we configured in Step 3.
kubectl apply -f - <<EOF
apiVersion: opentofu.m.upbound.io/v1beta1
kind: ClusterProviderConfig
metadata:
name: provider-opentofu
spec:
configuration: |
terraform {
backend "azurerm" {
use_azuread_auth = true
use_aks_workload_identity = true
storage_account_name = "${STORAGE_ACCOUNT}"
container_name = "tfstate"
key = "terraform.tfstate"
}
}
EOF
kubectl get clusterproviderconfigs.opentofu.m.upbound.io provider-opentofuStep 5: Test with a Workspace
A Workspace tells the provider which OpenTofu module to run. We'll test one directly before building the API so we can sort out any Azure access or state storage problems without debugging a Composition at the same time.
This module creates an empty resource group. The Workspace's external name selects an OpenTofu CLI workspace, keeping its state separate from later requests.
kubectl apply -f - <<'EOF'
apiVersion: opentofu.m.upbound.io/v1beta1
kind: Workspace
metadata:
name: tofu-azure-rg-test
annotations:
crossplane.io/external-name: tofu-azure-rg-test
spec:
providerConfigRef:
name: provider-opentofu
kind: ClusterProviderConfig
forProvider:
source: Inline
module: |
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~> 5.0"
}
}
}
provider "azurerm" {
features {}
use_oidc = true
}
resource "azurerm_resource_group" "test" {
name = "rg-tofu-crossplane-test"
location = "westus3"
}
EOFWait for the Workspace to sync successfully and become ready, then inspect its status:
kubectl wait --for=condition=Synced workspaces.opentofu.m.upbound.io/tofu-azure-rg-test --timeout=15m
kubectl wait --for=condition=Ready workspaces.opentofu.m.upbound.io/tofu-azure-rg-test --timeout=15m
kubectl get workspaces.opentofu.m.upbound.io tofu-azure-rg-testSYNCED and READY should both be True. If either wait times out or SYNCED shows False, see Troubleshooting Workspace sync failures before continuing. Otherwise, check Azure for the resource group and make sure the backend contains a state blob:
az group show \
--name rg-tofu-crossplane-test \
--query '{name:name,location:location,provisioningState:properties.provisioningState}' \
-o yaml
az storage blob list \
--account-name "$STORAGE_ACCOUNT" \
--container-name tfstate \
--auth-mode login \
--query '[].name' -o tsvThe group should report Succeeded in westus3, and the blob list should include state for tofu-azure-rg-test.
Delete the test Workspace
Once the test succeeds, delete its Workspace so we can check the cleanup path too. With the default deletion policy, the provider destroys the resource group before removing the Workspace:
kubectl delete workspaces.opentofu.m.upbound.io tofu-azure-rg-test --wait=true --timeout=15m
az group exists -n rg-tofu-crossplane-testThe final command should return false. Until deletion finishes, leave the provider running and keep its identity and state storage available.
Step 6: Expose a platform API
We can now give the developer an API that accepts a resource group name, location, and requester object ID. Crossplane will create the Workspace behind that request, so the developer won't need to choose a module or configure a backend.
A CompositeResourceDefinition, or XRD, defines the API's schema, while a composite resource, or XR, is an instance of that API. The Composition then tells Crossplane how to create the resources behind the request using a pipeline of functions.
Define the request schema
Crossplane recommends starting the kind with an X, so we'll use XResourceGroupRequest. The XRD's metadata.name combines the plural name and API group, and we'll explicitly set namespaced scope to keep each request and its Workspace in the same namespace.
The schema rejects requests with missing parameters or resource group names that don't match our naming rule, so the developer gets feedback before OpenTofu runs.
kubectl apply -f - <<'EOF'
apiVersion: apiextensions.crossplane.io/v2
kind: CompositeResourceDefinition
metadata:
name: xresourcegrouprequests.platform.example.org
spec:
scope: Namespaced
group: platform.example.org
names:
kind: XResourceGroupRequest
plural: xresourcegrouprequests
versions:
- name: v1alpha1
served: true
referenceable: true
schema:
openAPIV3Schema:
type: object
required:
- spec
properties:
spec:
type: object
required:
- parameters
properties:
parameters:
type: object
required:
- name
- location
- requesterObjectId
properties:
name:
type: string
pattern: '^rg-[a-z0-9-]{1,60}$'
location:
type: string
requesterObjectId:
type: string
minLength: 1
EOFWait for Crossplane to establish the new API before creating any requests against it:
kubectl wait --for=condition=Established compositeresourcedefinitions.apiextensions.crossplane.io/xresourcegrouprequests.platform.example.org --timeout=2mInstall the Composition functions
function-go-templating turns the request parameters into a Workspace, and function-auto-ready checks that Workspace's readiness. That lets the developer watch the request itself for completion.
kubectl apply -f - <<'EOF'
apiVersion: pkg.crossplane.io/v1
kind: Function
metadata:
name: function-go-templating
spec:
package: xpkg.crossplane.io/crossplane-contrib/function-go-templating:v0.13.3
---
apiVersion: pkg.crossplane.io/v1
kind: Function
metadata:
name: function-auto-ready
spec:
package: xpkg.crossplane.io/crossplane-contrib/function-auto-ready:v0.7.1
EOFBoth functions must become healthy before continuing:
kubectl wait --for=condition=Healthy functions.pkg.crossplane.io/function-go-templating functions.pkg.crossplane.io/function-auto-ready --timeout=5mIf either fails, inspect its package events:
kubectl describe functions.pkg.crossplane.io function-go-templating function-auto-readyConnect the request to the OpenTofu module
I keep the module in crossplane-opentofu-demo so the platform team can review and test the HCL separately from the API schema. The developer only supplies the fields exposed by the request.
The pinned module creates the resource group and grants the supplied object ID Contributor access. We pin it to a commit so a branch update can't change what an existing request provisions on a later reconcile.
Apply the Composition below. Its inline field is an object containing a Go template, with expressions that copy values from the XR into the Workspace:
kubectl apply -f - <<'EOF'
apiVersion: apiextensions.crossplane.io/v1
kind: Composition
metadata:
name: xresourcegrouprequests.opentofu.platform.example.org
spec:
compositeTypeRef:
apiVersion: platform.example.org/v1alpha1
kind: XResourceGroupRequest
mode: Pipeline
pipeline:
- step: render-opentofu-workspace
functionRef:
name: function-go-templating
input:
apiVersion: gotemplating.fn.crossplane.io/v1beta1
kind: GoTemplate
source: Inline
inline:
template: |
apiVersion: opentofu.m.upbound.io/v1beta1
kind: Workspace
metadata:
namespace: {{ .observed.composite.resource.metadata.namespace | quote }}
labels:
platform.example.org/request: {{ .observed.composite.resource.metadata.name | quote }}
annotations:
gotemplating.fn.crossplane.io/composition-resource-name: opentofu-workspace
spec:
providerConfigRef:
kind: ClusterProviderConfig
name: provider-opentofu
forProvider:
source: Remote
module: git::https://github.com/pauldotyu/crossplane-opentofu-demo.git//modules/resource-group?ref=64433eacb882a9f0e84e278f336ea0ebc517be94
vars:
- key: resource_group_name
value: {{ .observed.composite.resource.spec.parameters.name | quote }}
- key: location
value: {{ .observed.composite.resource.spec.parameters.location | quote }}
- key: requester_object_id
value: {{ .observed.composite.resource.spec.parameters.requesterObjectId | quote }}
- step: automatically-detect-ready
functionRef:
name: function-auto-ready
EOFStep 7: Request a resource group
Submit a request with your signed-in user's object ID so the module can grant that user Contributor access to the new group. We'll name the request after the resource it creates, rg-demo-paul, so the request, its label, and the Azure group all share one name.
For this lab, we trust the supplied object ID without checking whether it belongs to the person submitting the request. Before offering the API to other users, enforce who can receive access and restrict direct access to Workspaces and the provider configuration. The small API schema doesn't enforce those boundaries on its own.
kubectl apply -f - <<EOF
apiVersion: platform.example.org/v1alpha1
kind: XResourceGroupRequest
metadata:
name: rg-demo-paul
spec:
parameters:
name: rg-demo-paul
location: westus3
requesterObjectId: "${REQUESTER_OBJECT_ID}"
EOFWait for the request to become ready, then inspect its Workspace. The label we added in the Composition lets us find the generated resource without needing to know its name:
kubectl wait --for=condition=Ready xresourcegrouprequests.platform.example.org/rg-demo-paul --timeout=15m
kubectl get xresourcegrouprequests.platform.example.org rg-demo-paul
kubectl get workspaces.opentofu.m.upbound.io -l platform.example.org/request=rg-demo-paulThe request and Workspace should both show READY as True, and the Workspace should show SYNCED as True, before you check the result in Azure:
az group show \
--name rg-demo-paul \
--query '{name:name,location:location,id:id}' \
-o yamlThen check the requester's role assignment at the new group's scope:
RG_ID=$(az group show -n rg-demo-paul --query id -o tsv)
az role assignment list \
--scope "$RG_ID" \
--query "[?principalId=='$REQUESTER_OBJECT_ID'].{role:roleDefinitionName,scope:scope}" \
-o tableYou should see a Contributor assignment for the new group. Together with the group check, this confirms that the requester has a resource group they can use.
If the request doesn't become ready or its Workspace shows SYNCED as False, inspect both objects:
kubectl describe xresourcegrouprequests.platform.example.org rg-demo-paul
kubectl get workspaces.opentofu.m.upbound.io -l platform.example.org/request=rg-demo-paul
kubectl describe workspaces.opentofu.m.upbound.io -l platform.example.org/request=rg-demo-paulIf no Workspace exists, check the request's events for function or template errors. If one exists but isn't syncing or ready, follow the Workspace sync troubleshooting steps using the generated NAME from the output above.
After fixing a request or Composition error, you can request another reconcile:
kubectl annotate xresourcegrouprequests.platform.example.org rg-demo-paul crossplane.io/reconcile-requested-at="$(date +%s)" --overwriteThis reruns the request's reconciliation, but it doesn't repair an Azure authentication error or force the Workspace's own controller to retry.
Where to go from here
I'd build on this example in a few places:
- The biggest step beyond this example is making the API self-service. In my previous post, I deployed Backstage to AKS with Entra ID sign-in. A software template that creates an
XResourceGroupRequestwould complete the setup, and because Backstage already knows who is signed in, you can derive the requester's identity from the session instead of trusting a free-formrequesterObjectIdfield. That closes the authorization gap the schema can't enforce on its own. - Keep module upgrades explicit by updating the pinned commit only after reviewing and testing the change. With the provider's default remote pull behavior, a moving branch can change what an existing request provisions on a later reconcile.
- Whenever you update the Crossplane, provider, or function versions, repeat the standalone Workspace check before testing the full API. Check the provider's bundled OpenTofu version too, since upgrading a CLI on your laptop doesn't change the engine running in the pod.
- Try adding a virtual network, a Key Vault, or a role assignment to an existing group. Related resources can stay in the same module, though a different request workflow may warrant its own XRD.
- Extend the XRD's validation with allowed locations and other platform rules. Kubernetes already checks the
patternonnamebefore accepting a request, so you don't need another function for that check. - Expose the module's
resource_group_idoutput on the XR. Since the provider publishes non-sensitive outputs in Workspace status, you can define a status field in the XRD and populate it from the Composition. If callers need a Secret, compose one explicitly for a v2 XR.
Cleanup
Delete the request before removing the control plane, and leave the provider's identity and state backend available until OpenTofu finishes destroying the Azure resources. If you delete the Workspace directly while its request is still in place, Crossplane can recreate it.
Use foreground deletion so Kubernetes waits for the composed Workspace to disappear before deleting the request. If you skipped the standalone test Workspace's earlier cleanup, the second command removes it too:
kubectl delete xresourcegrouprequests.platform.example.org rg-demo-paul --ignore-not-found --cascade=foreground --wait=true --timeout=20m
kubectl delete workspaces.opentofu.m.upbound.io tofu-azure-rg-test --ignore-not-found --wait=true --timeout=15mCheck that both Azure resource groups are gone. Both commands should return false:
az group exists -n rg-demo-paul
az group exists -n rg-tofu-crossplane-testIf deletion times out or a group remains, use the Workspace events and provider logs from Step 5 to find the cause. Restore missing permissions or backend access before retrying, since removing a finalizer can leave Azure resources behind.
Once both groups are gone, remove the two role assignments scoped to the subscription. The storage-scoped Storage Blob Data Contributor assignments die with the storage account, so they don't need individual cleanup. Deleting the managed identity later won't remove these assignments either; principal deletions leave role assignments behind, so remove them explicitly:
az role assignment delete \
--assignee-object-id "$PROVISIONER_OBJECT_ID" \
--role "Contributor" \
--scope "/subscriptions/$AZURE_SUBSCRIPTION_ID"
az role assignment delete \
--assignee-object-id "$PROVISIONER_OBJECT_ID" \
--role "Role Based Access Control Administrator" \
--scope "/subscriptions/$AZURE_SUBSCRIPTION_ID"Finally, delete the lab resource group to remove the AKS cluster, managed identity, and state storage, and confirm it's gone:
az group delete -n rg-crossplane --yes
az group exists -n rg-crossplaneThe last command should return false. Keep the shell variables until you've confirmed it.
Troubleshooting Workspace sync failures
Start with the affected Workspace. Set WORKSPACE to tofu-azure-rg-test for the standalone test, or to the generated Workspace name for a request created through the API:
WORKSPACE="tofu-azure-rg-test"
kubectl describe workspaces.opentofu.m.upbound.io "$WORKSPACE"
kubectl get workspaces.opentofu.m.upbound.io "$WORKSPACE" -o jsonpath='{range .status.conditions[*]}{.type}={.status}{" "}{.reason}{": "}{.message}{"\n"}{end}'Synced=False with ReconcileError means the provider hit an error, and the condition's message usually names the cause. ReconcilePaused means someone paused the Workspace on purpose. READY describes resource availability, so check it separately from SYNCED.
If the message doesn't explain the failure, check the Workspace's events and the provider's logs:
kubectl get events --field-selector "involvedObject.kind=Workspace,involvedObject.name=$WORKSPACE" --sort-by=.metadata.creationTimestamp
kubectl logs -n crossplane-system -l app.kubernetes.io/name=provider-opentofu -c package-runtime --since=15m --tail=80An empty Events section doesn't mean the provider is idle. The provider documents delayed event reporting during module runs, so check the logs too.
Use the error message to pick the next check:
- No tenant ID specified: check
ARM_TENANT_IDin the Step 3DeploymentRuntimeConfigand the service account'sazure.workload.identity/tenant-idannotation. A pod that started before the variable was set won't pick it up on its own; restart the provider deployment after fixing the config. - Provider configuration not found: confirm the Step 4
ClusterProviderConfigexists and matches the Workspace'sproviderConfigRef. AADSTS70021: the federated credential doesn't match the pod's token. Its subject must besystem:serviceaccount:crossplane-system:provider-opentofu, and its issuer must match the cluster's OIDC issuer URL. New credentials can take time to propagate.AuthorizationFailed: check that the provider identity has both subscription roles from Step 3.- Blob authorization error: check the storage roles from Step 4 and give the assignments a few minutes to propagate.
To inspect the federated credential and role assignments directly:
az identity federated-credential show \
-n crossplane \
-g rg-crossplane \
--identity-name id-crossplane \
--query '{issuer:issuer,subject:subject,audiences:audiences}' -o yaml
az role assignment list \
--scope "/subscriptions/$AZURE_SUBSCRIPTION_ID" \
--query "[?principalId=='$PROVISIONER_OBJECT_ID'].{role:roleDefinitionName,scope:scope}" \
-o tableAfter fixing the cause, request another reconciliation so you can check the fix without waiting for the next scheduled attempt. The annotation's value must change for each request, so --overwrite is required:
kubectl annotate workspaces.opentofu.m.upbound.io "$WORKSPACE" crossplane.io/reconcile-requested-at="$(date +%s)" --overwriteWatch until SYNCED and READY are both True. Press Ctrl+C to stop watching; the provider keeps reconciling after you do.
kubectl get workspaces.opentofu.m.upbound.io "$WORKSPACE" --watchConclusion
With this API, a developer can request a resource group and access through XResourceGroupRequest without editing the OpenTofu module or setting up its backend. The platform team can keep using HCL and decide which inputs the API exposes and which identity runs the module. Before sharing it, put the authorization boundaries described above in place and decide who will operate the control plane.
References
- Crossplane Documentation
- Composite Resource Definitions (and the
Xnaming convention) - Compositions and Functions
- provider-opentofu on GitHub
- provider-terraform on GitHub (Terraform engine pinned at 1.5.7)
- crossplane-opentofu-demo
- function-go-templating
- function-auto-ready
- Azure Workload Identity on AKS
Community discussion