> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Terraform and Crossplane Together

> Use Terraform for cloud backbone and Crossplane in Kubernetes for developer-driven, GitOps provisioning while ensuring each resource is managed by only one system

How should you use Terraform and Crossplane together in a production environment?

Terraform and Crossplane are both powerful infrastructure-as-code tools that can provision cloud resources, but they excel in different roles. Many organizations get the best results by using them together: Terraform to build the cloud backbone and Crossplane to enable developer-driven provisioning inside Kubernetes.

Why use both? Consider a company that runs \~90% of its systems on Kubernetes. Every new service often requires a dozen cloud resources (databases, network rules, permissions, etc.). Creating those resources externally with Terraform for each service can be slow when multiplied across many teams. Crossplane, running inside the cluster, enables faster, declarative provisioning via YAML manifests and continuous reconciliation.

For one service, that delay is fine.

![A stylized diagram of an AWS account containing a Kubernetes cluster with many pod icons (marked 90%), flanked by Terraform and Crossplane logos. Below the cluster are icons for Databases, Network Rules, and Permissions and a progress bar at the bottom.](https://mintcdn.com/kodekloud-c4ac6d9a/IK4ISE2GFis3psR1/images/DevOps-Interview-Questions-and-Answers-Scenario-Based-Prep/CICD-DevOps/Terraform-and-Crossplane-Together/aws-k8s-pods-90-terraform-crossplane.jpg?fit=max\&auto=format\&n=IK4ISE2GFis3psR1\&q=85\&s=1a5982a4b2ca0abc9997a22fd0536d74)

Multiply that by many services and teams, and the overhead becomes significant. The recommended pattern is:

* Use Terraform to provision long-lived, high-risk, or organization-level resources (cloud accounts, VPCs, clusters, IAM policies).
* Install and configure Crossplane in the Kubernetes clusters Terraform creates.
* Let application teams request and manage per-service resources (databases, buckets, caches) with Crossplane YAML manifests, typically tracked with GitOps.

A common workflow

* Terraform creates the cloud foundation and the Kubernetes cluster, then deploys Crossplane into that cluster.
* Developers commit small Crossplane resource YAMLs (often \~10 lines) to request databases, buckets, etc.
* Crossplane reconciles those resources continuously and remediates any manual drift.

A collision to avoid
If the same resource is managed by both Terraform and Crossplane, the two systems can fight: Terraform changes a resource, Crossplane reconciles it back to its declared state, and so on. The rule to prevent that is simple and essential:

Every resource must be declared and managed in exactly one system: Terraform (outside the cluster) or Crossplane (inside the cluster). Never declare the same resource in both places.

Recommended separation (example)

```text theme={null}
main.tf
  network
  cluster

db.yaml
  database
  bucket
  cache
```

More concretely, use this table to guide which tool manages which resource types:

| Resource type | Typical owner | Why |
| -: | - | - |
| Cloud accounts, organization-level policies | Terraform | Sensitive, long-lived, requires review and strict change control |
| VPCs, subnets, core networking | Terraform | Foundational infra that many systems share |
| Kubernetes clusters | Terraform | Provisioning cluster lifecycle and cloud provider integration |
| Crossplane installation & operator | Terraform | Install Crossplane into the cluster once the cluster exists |
| Databases, object buckets, caches (service-level) | Crossplane | Developer-driven, frequently provisioned, and benefit from GitOps + reconciliation |
| Short-lived environments (feature/test) | Crossplane (or a mix with Terraform as needed) | Fast creation/destruction and managed within cluster workflows |

How Crossplane uses Terraform-created resources
When Terraform creates infrastructure, cloud providers return identifiers (for example, a VPC ID). Crossplane needs those identifiers to provision resources (for example, a database in the same network). Common patterns to pass values from Terraform to Crossplane include:

* Write Terraform outputs to a small config that the cluster can read.
* Have Terraform create Kubernetes Secrets/ConfigMaps (or use the Kubernetes provider) with the needed IDs.
* Use a bootstrap job or Helm values (installed by Terraform) to seed Crossplane provider configurations with the correct references.

Example: Terraform output → Kubernetes Secret (conceptual)

```hcl theme={null}
# Terraform: export the VPC ID
output "vpc_id" {
  value = aws_vpc.main.id
}
```

Then have Terraform or a CI step write that output into a Kubernetes Secret that Crossplane can reference, or populate a provider config Crossplane reads.

Best practices checklist

* Declare each resource in exactly one system (Terraform or Crossplane).
* Keep Terraform for infra that requires human review, audit, and slow change cycles.
* Keep Crossplane for developer-facing, frequently created resources that benefit from GitOps and continuous reconciliation.
* Use Terraform outputs or cluster-accessible secrets to pass provider/resource identifiers into Crossplane.
* Automate Crossplane installation as the final step of Terraform’s cluster provisioning.

Further reading and references

* Terraform documentation: [https://www.terraform.io/docs](https://www.terraform.io/docs)
* Crossplane documentation: [https://crossplane.io/docs](https://crossplane.io/docs)
* GitOps practices for Kubernetes: [https://www.weave.works/technologies/gitops](https://www.weave.works/technologies/gitops)

In short

* Use Terraform to build the cloud backbone and install Crossplane.
* Use Crossplane inside Kubernetes for application teams to request and manage cloud resources via YAML and GitOps.
* Never manage the same resource with both tools — choose one system per resource and stick to it. This keeps workflows efficient, avoids contention, and lets each tool play to its strengths in production.

> [card] [Watch Video](https://learn.kodekloud.com/user/courses/devops-interview-prep/module/370000ef-b6bc-4986-8d29-0793ebb2c9e7/lesson/1bbce5fc-0bc9-428e-a306-3b3ce3cd0f7f)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.