As we continue to strengthen our partnership with HashiCorp, we’re excited to announce the first release of a Verified Terraform Provider for Couchbase Capella. Terraform is widely recognized as the leading provider of infrastructure as code tool that enables you to build, change, and version cloud resources safely and efficiently. Customers can now easily automate the provisioning of Capella resources as code by using HashiCorp Terraform.
How to Use the Couchbase Capella Provider
Requirements
The Couchbase Capella Provider allows you to interact with Projects, Clusters, Buckets and Database Users within your Couchbase Capella tenant. Before it can be used, the provider needs to be configured with the proper credentials. To set up authentication with the Couchbase Capella Provider a programmatic API key must be generated.
Couchbase Capella Public API uses a Bearer token mechanism for authentication, so each call to the Public API can be authenticated. To use the Bearer token mechanism with the Couchbase Capella Public API, it is first necessary to obtain Access and Secret keys — this is done within Couchbase Capella UI. These keys are specific to your account in Couchbase Capella and also control authorization for API operations.
Setup and Authentication
You will need to provide your credentials for authentication via the environment variables, CBC_ACCESS_KEY and CBC_SECRET_KEY, for your access and secret API Key Pair respectively.
1 2 |
$ export CBC_ACCESS_KEY="xxxx" $ export CBC_SECRET_KEY="xxxx" |
Example Usage
Create a Terraform configuration file with the .tf file extension. Below is an example configuration file that will deploy a new Project and an AWS Hosted Cluster in Couchbase Capella.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# Pull Couchbase Capella Provider from Terraform Registry terraform { required_providers { couchbasecapella = { source = "registry.terraform.io/couchbasecloud/couchbasecapella" } } } # Configure the Couchbase Capella Provider provider "couchbasecapella" {} # Create example project resource resource "couchbasecapella_project" "project" { name = "project1" } output "terraform_project_id" { value = couchbasecapella_project.project.id } # Create example hosted cluster resource resource "couchbasecapella_hosted_cluster" "example_aws_hosted" { name = "cluster_name" project_id = "couchbasecapella_project.project.id" place { single_az = true hosted { provider = "aws" region = "us-west-2" cidr = "cidr_block" } } support_package { timezone = "GMT" support_package_type = "Basic" } servers { size = 3 compute = "m5.xlarge" services = ["data"] storage { storage_type = "GP3" iops = "3000" storage_size = "50" } } } |
To deploy the resources configured in your Terraform configuration file, follow the steps below:
1. Initialize the Terraform provider
Execute the following command to initialize the Terraform provider. This step is only required when first interacting with the provider:
terraform init
2. Review the Terraform plan
Execute the following command to review the resources that will be deployed:
terraform plan
3. Execute the Terraform apply
Execute the plan to deploy the Couchbase Capella resources.
terraform apply
4. Destroy the resources
Execute the following command to destroy the resources so you avoid unnecessary charges:
terraform destroy
Resources
Version 0.1 of the Couchbase Capella provider supports the management of the following Couchbase Capella resources:
-
- Projects
- Hosted Clusters
- InVPC Clusters
- Database Users for In-VPC Clusters
- Buckets for In-VPC Clusters
Projects
couchbasecapella_project allows Projects to be created, edited and deleted in Couchbase Capella.
1 2 3 |
resource "couchbasecapella_project" "example_project" { name = "project_name" } |
Hosted Clusters
couchbasecapella_hosted_cluster allows you to create, edit and delete Hosted Clusters in Couchbase Capella.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
resource "couchbasecapella_hosted_cluster" "example_aws_hosted" { name = "cluster_name" project_id = "your_project_id" place { single_az = true hosted { provider = "aws" region = "us-west-2" cidr = "cidr_block" } } support_package { timezone = "GMT" support_package_type = "Basic" } servers { size = 3 compute = "m5.xlarge" services = ["data"] storage { storage_type = "GP3" iops = "3000" storage_size = "50" } } } |
In-VPC Clusters
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
couchbasecapella_vpc_cluster allows you to create and delete VPC Clusters in Couchbase Capella. resource "couchbasecapella_vpc_cluster" "example_vpc" { name = "cluster_name" cloud_id = "your_cloud_id" project_id = "your_project_id" servers { size = 3 services = ["data", "query", "index"] aws { instance_size = "m5.xlarge" ebs_size_gib = 50 } } } |
Buckets
couchbasecapella_bucket allows Buckets to be created and deleted for a Couchbase Capella In-VPC Cluster.
Creating a single bucket
1 2 3 4 5 6 |
resource "couchbasecapella_bucket" "example_single_bucket" { cluster_id = "your_cluster_id" name = "bucket_name" memory_quota = "128" conflict_resolution = "seqno" } |
Creating multiple buckets
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
resource "couchbasecapella_bucket" "example_multiple_bucket1" { cluster_id = "your_cluster_id" name = "bucket_name" memory_quota = "128" conflict_resolution = "seqno" } resource "couchbasecapella_bucket" "example_multiple_bucket2" { depends_on = [couchbasecapella_bucket.example_multiple_bucket1] cluster_id = "your_cluster_id" name = "bucket_name_two" memory_quota = "128" conflict_resolution = "seqno" } |
Database Users
couchbasecapella_database_user allows Database Users to be created, edited and deleted for a Couchbase Capella In-VPC Cluster.
All Bucket Access
1 2 3 4 5 6 |
resource "couchbasecapella_database_user" "example_all_bucket_db_user" { cluster_id = "your_cluster_id" username = "username" password = "password" all_bucket_access = "data_reader" } |
With Specific Bucket Access
1 2 3 4 5 6 7 8 9 |
resource "couchbasecapella_database_user" "example_specific_bucket_db_user" { cluster_id = "your_cluster_id" username = "username" password = "password" buckets{ bucket_name = "your_bucket_name" bucket_access = ["data_reader", "data_writer"] } } |
Specific Bucket Access with Multiple Buckets
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
resource "couchbasecapella_database_user" "example_specific_multiple_buckets_db_user" { cluster_id = "your_cluster_id" username = "user" password = "password" buckets { bucket_name = "bucket1" bucket_access = ["data_reader"] } buckets { bucket_name = "bucket2" bucket_access = ["data_writer"] } } |
Creating Multiple Database Users
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
resource "couchbasecapella_database_user" "example_multiple_db_user1" { cluster_id = "your_cluster_id" username = "username" password = "password" all_bucket_access = "data_reader" } resource "couchbasecapella_database_user" "example_multiple_db_user1" { depends_on = [couchbasecapella_database_user.example_multiple_db_user1] cluster_id = "your_cluster_id" username = "username" password = "password" all_bucket_access = "data_reader" } |
Getting Started
For more details about the Couchbase Capella Verified Provider on the Registry, click here.
To start your 30 day free trial of Couchbase Capella, click here.