Crunchy Bridge Terraform Provider

In a world where everything is stored in git following IaC (infrastructure as code) you may want the same from your database. For many following this style of engineering modernization we see a focus on IaC and K8s. We have many users standardizing on our PGO Kubernetes Operator to help. But following an IaC approach doesn’t mean you always want to manage your database and be in Kubernetes. For those wanting to forget about their database and trust the uptime, safety, and security of it to someone else - but still want to evolve their development practices - you can have your cake and eat it too.

Crunchy Bridge is excited to announce that we have released a verified Terraform provider. Many of our Crunchy Bridge customers are already using Terraform to manage their cloud infrastructure. This addition to our platform will allow Crunchy Bridge PostgreSQL resources to be integrated into infrastructure as code and DevOps workflows for our customers.

Working with terraform allows our customers to manage their cloud infrastructure with configuration files that can be shared, reused, and version controlled across their organization. To get started with Terraform, see HashiCorp’s documentation. The Crunchy Bridge Terraform provider is intended for use with both open-source Terraform and Terraform Cloud.

Get started with our Terraform provider

Sample Provisioning

Add this code to your main.tf Terraform configuration file

terraform {
  required_providers {
    crunchybridge = {
      source = "CrunchyData/crunchybridge"
      version = "0.1.0"
    }
  }
}

provider "crunchybridge" {
  // Set these to your API key
  application_id     = "pato7ykzflmwsex54pbvym"
  application_secret = "ZZbjH3LZWhP1be2Nt5KX-I3g79aGeK8JNQFHn8"
}

data "crunchybridge_account" "user" {}

resource "crunchybridge_cluster" "demo" {
  team_id = data.crunchybridge_account.user.default_team
  name    = "famously-fragile-impala-47"
  provider_id = "aws"
  region_id = "us-east-1"
  plan_id = "standard-8"
  is_ha = "false"
  storage = "100"
  major_version = "14"
}

data "crunchybridge_clusterstatus" "status" {
  id = crunchybridge_cluster.demo.id
}

output "demo_status" {
  value = data.crunchybridge_clusterstatus.status
}

The provider section above calls out the Crunchy Bridge provider. The resource specification will allow you to input specifications for the database provision you want to create like the cloud provider, region, plan, storage, and Postgres version. The data specifications define data which will be queried to identify the user's default team and to query the cluster status for the output.

To get your database up and running, do a terraform init and then terraform apply and you're off and running.

Sample Deprovisioning

You’ll just keep your terraform and provider code in there, but remove the data and resource definitions. In the declarative model, by removing definitions we are declaring that we want any previously created definitions deprovisioned.

Update main.tf:

terraform {
    required_providers {
        crunchybridge = {
      source = "CrunchyData/crunchybridge"
      version = "0.1.0"
        }
    }
}

provider "crunchybridge" {
    application_id     = "pato7ykzflmwsex54pbvym"
    application_secret = "ZZbjH3LZWhP1be2Nt5KX-I3g79aGeK8JNQFHn8"
}

Now a terraform apply and you’ll destroy the cluster you just created.

Have at it!

See our docs for additional details about Terraform and working with the Crunchy Bridge platform. Feel free to throw in an issue to the GitHub repo if you see something you’d like to fix with the provider or the documentation. Have fun out there!

Avatar for Elizabeth Christensen

Written by

Elizabeth Christensen

August 8, 2022 More by this author