Terraform Intro and Key Concepts

Terraform is an Infrastructure as Code (IaC) tool that allows you to define, provision, and manage infrastructure using a declarative configuration language. Terraform can help automate the setup and management of resources across various cloud providers (like AWS, Azure, and GCP), making infrastructure management repeatable and scalable.

Key concepts:

  1. Providers: Plugins that let Terraform manage different platforms (e.g., AWS, Azure, Kubernetes).
  2. Resources: The building blocks (e.g., VMs, storage buckets, load balancers) defined in the configuration files.
  3. State: Terraform keeps track of resources it creates in a state file, which helps manage infrastructure changes.
  4. Modules: Reusable pieces of infrastructure (e.g., a complete VPC setup) that can be shared and reused.
  5. Plan & Apply: The terraform plan command shows what will change, while terraform apply implements those changes.
  6. Variables: Allow for parameterizing configurations to make modules and resources more flexible.
  7. Outputs: These allow you to extract values from your Terraform configuration that can be used elsewhere in the system or passed to other Terraform configurations.
  8. Workspaces: A way to manage multiple environments (e.g., dev, staging, prod) within the same configuration. Each workspace has its own state file, allowing you to use the same code across environments with different parameters.
  9. Provisioners: These are used to execute scripts or commands on resources after they have been created. While not recommended for most use cases (since Terraform focuses on declarative state), they can be helpful for certain tasks like bootstrapping instances.
  10. Locking: Terraform uses a state locking mechanism (usually through the backend, such as S3 for AWS) to prevent simultaneous modifications to infrastructure from different users or automated systems.
  11. Backends: These define where your Terraform state is stored (e.g., locally, in an S3 bucket, or using a remote state service). Storing state remotely is key for collaboration in teams.
  12. Data Sources: These allow you to fetch or reference existing resources outside of your Terraform configuration. This is useful when you need to manage infrastructure alongside pre-existing components or share resources between configurations.
  13. Lifecycle Management: With lifecycle rules, you can control how Terraform manages resources over time. For instance, you can set dependencies between resources, manage how resources are created, updated, or destroyed, or prevent a resource from being accidentally destroyed.

Should I use Crossplane instead of Terraform?

Choosing Between Terraform and Crossplane for Infrastructure Management in Kubernetes

When it comes to infrastructure as code (IAC), there are two popular tools to consider if you’re using Kubernetes: Terraform and Crossplane. Both have their strengths, but which one is right for your use case? Having worked with both, here are my insights on making this decision.

Crossplane: Kubernetes-Native with Continuous Reconciliation

Crossplane is a relatively new IAC tool (introduced in 2019) and is designed specifically for Kubernetes. Everything in Crossplane is treated as a Kubernetes resource, meaning that infrastructure is continuously reconciled by Kubernetes controllers. This makes Crossplane a great option if you’re aiming for a Kubernetes-native approach to managing infrastructure.

Despite being newer and less established than Terraform, Crossplane has a strong and growing community. The ecosystem around Crossplane continues to expand, offering providers for major cloud platforms. It also integrates seamlessly with GitOps tools like Flux CD or Argo CD, making it a strong choice if you’re already using GitOps practices.

However, as with any emerging technology, there are risks. Some of the cloud providers may not be as mature as Terraform’s offerings, and troubleshooting can be more challenging. But in my experience, the community has been incredibly supportive, and new features are consistently improving the overall user experience.

Terraform: A Stable, Proven Solution

Terraform is the more established and widely used IAC tool. It’s stable and has extensive support across the cloud ecosystem. If you’re looking for a battle-tested solution, Terraform is a safe bet. Many large organizations rely on Terraform, and it has a vast library of providers, so issues tend to get resolved quickly.

One downside is that Terraform isn’t Kubernetes-native, so you’ll need to manage infrastructure outside of your Kubernetes cluster. You’ll also need to set up scripts and pipelines to trigger reconciliation processes manually, unlike Crossplane’s continuous reconciliation. That said, these are not dealbreakers, and Terraform’s reliability makes it a strong contender for most infrastructure needs.

Conclusion: Terraform or Crossplane?

Both tools have their place depending on your goals. If you’re heavily invested in Kubernetes and want everything managed as a Kubernetes resource, Crossplane offers a compelling solution. If you prefer a more established, stable option with wider support, Terraform remains a solid choice.

Ultimately, your decision should be based on your team’s expertise and your long-term infrastructure strategy.

CLI command to show status of an AKS upgrade

The other day I was monitoring an AKS Kubernetes version upgrade but the notifications Azure Portal had stopped updating. I found out that I can check the status from the command line.

emilyzall@Emilys-MBP ~ % az aks show -g my-rg -n my-cluster --query 'provisioningState'
"Upgrading"
emilyzall@Emilys-MBP ~ % az aks show -g my-rg -n my-cluster --query 'provisioningState'
"Succeeded"