Skip to content
This repository has been archived by the owner on Mar 15, 2024. It is now read-only.

Commit

Permalink
Merge pull request #24 from couchbasecloud/fix/gcp_hosted_clusters
Browse files Browse the repository at this point in the history
Allow GCP hosted clusters to be deployed
  • Loading branch information
jamesrwilkinson authored Sep 12, 2022
2 parents e02af6e + ed02656 commit 42779b4
Show file tree
Hide file tree
Showing 7 changed files with 350 additions and 67 deletions.
71 changes: 40 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,6 @@ This is the repository for the Terraform Couchbase Capella Provider which allows
- [Terraform](https://www.terraform.io/downloads.html) >= 0.14.x
- [Go](https://golang.org/doc/install) >= 1.14

## Building The Provider

1. Clone the repository
1. Enter the repository directory
1. Build the provider using the Go `build` command:

```sh
$ go build
```

After the provider has been built locally it must be placed in the user plugins directory so it can be discovered by the
Terraform CLI. Please execute the following command to move the provider binary to this directory:

```sh
$ mv terraform-provider-couchbasecapella ~/.terraform.d/plugins/terraform.couchbase.com/local/couchbasecapella/1.0.0/<OS_ARCH>
```

The terraform provider is installed and can now be discovered by Terraform through the following HCL block.

```hcl
terraform {
required_providers {
couchbasecapella = {
source = "terraform.couchbase.com/local/couchbasecapella"
version = "1.0.0"
}
}
}
```

## Using the provider

### Configuring Programmatic Access
Expand All @@ -60,7 +30,16 @@ $ terraform plan
### Example Usage

```terraform
#Configure the Couchbase Capella Provider
# 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
Expand Down Expand Up @@ -109,6 +88,36 @@ Please also visit the `get_started` directory for an example configuration for p

If you wish to work on the provider, you'll first need [Go](http://www.golang.org) installed on your machine (see [Requirements](#requirements) above). You will also need to have access to a [Couchbase Capella](https://www.couchbase.com/products/capella) account.

## Building The Provider

1. Clone the repository
1. Enter the repository directory
1. Build the provider using the Go `build` command:

```sh
$ go build
```

After the provider has been built locally it must be placed in the user plugins directory so it can be discovered by the Terraform CLI. Please execute the following command to move the provider binary to this directory:

```sh
$ mv terraform-provider-couchbasecapella ~/.terraform.d/plugins/github.com/local/couchbasecapella/<VERSION>/<OS_ARCH>
```

The terraform provider is installed and can now be discovered by Terraform through the following HCL block.

```hcl
terraform {
required_providers {
couchbasecapella = {
source = "github.com/local/couchbasecapella"
version = "<VERSION>"
}
}
}
```


## Testing the Provider

### Configuring the environment variables
Expand Down
59 changes: 55 additions & 4 deletions docs/resources/hosted_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Create, edit and delete Hosted Clusters in Couchbase Capella.

## Example Usage

### Example Hosted Cluster
### Example AWS Hosted Cluster

```hcl
resource "couchbasecapella_hosted_cluster" "test" {
Expand Down Expand Up @@ -46,6 +46,36 @@ resource "couchbasecapella_hosted_cluster" "test" {
}
```

### Example GCP Hosted Cluster

```hcl
resource "couchbasecapella_hosted_cluster" "test" {
name = "cluster_name"
project_id = "your_project_id"
place {
single_az = true
hosted {
provider = "gcp"
region = "us-east1"
cidr = "cidr_block"
}
}
support_package {
timezone = "GMT"
support_package_type = "Basic"
}
servers {
size = 3
compute = "n2-standard-4"
services = ["data"]
storage {
storage_type = "PD-SSD"
storage_size = "50"
}
}
}
```

## Argument Reference

- `name` - (Required) The name of the cluster you want to create. The cluster name can include letters, numbers, spaces, periods (.), dashes (-), and underscores (\_). Cluster name should be between 2 and 128 characters and must begin with a letter or a number.
Expand All @@ -64,6 +94,15 @@ resource "couchbasecapella_hosted_cluster" "test" {
- `region` - (Required) A valid region for the cloud provider that you want you cluster to be hosted in. This must be a valid region for the cloud provider you have specified. (Cannot be changed via this Provider after creation.)
- `cidr` - (Required) The CIDR address. This must be a valid CIDR address. (Cannot be changed via this Provider after creation.)

##### Valid Provider Regions
###### AWS

us-east-1, us-east-2, us-west-2, ca-central-1, ap-northeast-1, ap-northeast-2, ap-southeast-1, ap-southeast-2, ap-south-1, eu-north-1, eu-west-1, eu-west-2, eu-west-3, eu-central-1, sa-east-1

###### GCP

us-east1, us-east4, us-west1, us-west3, us-west4, us-central1, northamerica-northeast1, northamerica-northeast2, asia-east1, asia-east2, asia-northeast1, asia-northeast2, asia-northeast3, asia-south1, asia-south2, asia-southeast1, asia-southeast2, australia-southeast1, australia-southeast2, europe-west1, europe-west2, europe-west3, europe-west4, europe-west6, europe-west8, europe-central2, europe-north1, southamerica-east1, southamerica-west1

### Support Package

- `timezone` - (Required) The time zone that you would like to receive support from. `ET`, Eastern Time, `GMT`, Greenwich Mean Time , `IST`, India Standard Time, `PT`, Pacific Time, are the available time zones that you can specify.
Expand All @@ -77,12 +116,24 @@ For more detailed information on support packages, you can view this [detailed p
- `compute` - (Required) The name of the compute instance type. This must be a valid compute instance type for the provider that you have specified.
- `services` - (Required) A list of Couchbase services that you want in your cluster. `Data`, `Query`, `Index`, `Search`,`eventing`, `analytics` are the available services that you can specify.

##### Valid Compute Instance Types
###### AWS

m5.large, m5.xlarge, m5.2xlarge, m5.4xlarge, m5.8xlarge, m5.12xlarge, m5.16xlarge, r5.xlarge, r5.2xlarge, r5.4xlarge, r5.8xlarge, r5.12xlarge, c5.large, c5.xlarge, c5.2xlarge, c5.4xlarge, c5.9xlarge, c5.12xlarge, c5.18xlarge

###### GCP

n2-standard-2, n2-standard-4, n2-standard-8, n2-standard-16, n2-standard-32, n2-standard-48, n2-standard-64, n2-standard-80, n2-highmem-2, n2-highmem-4, n2-highmem-8, n2-highmem-16, n2-highmem-32, n2-highmem-48, n2-highmem-64, n2-highmem-80, n2-highcpu-2, n2-highcpu-4, n2-highcpu-8, n2-highcpu-16, n2-highcpu-32, n2-highcpu-48, n2-highcpu-64, n2-highcpu-80, n2-custom-2-4096, n2-custom-4-8192, n2-custom-8-16384, n2-custom-16-32768, n2-custom-32-65536, n2-custom-36-73728, n2-custom-48-98304, n2-custom-72-147456


#### Storage

- `storage_type` - (Required) The name of the storage type. `GP3`, `IO2` are the available storage types that you can specify.
- `iops` - (Required) The number of the IOPS.
- `storage_type` - (Required) The name of the storage type. `GP3`, `IO2`, `PD-SSD` are the available storage types that you can specify.
- `iops` - (Optional) The number of the IOPS.


~> **IMPORTANT:** The minimum value is 3000 for GP3, and 1000 if IO2. The maximum value is 16000 for GP3, and 64000 if IO2.
~> **IMPORTANT** GCP Hosted Clusters should not specify an IOPS value.
~> **IMPORTANT:** The minimum value is 3000 for GP3, and 1000 if IO2. The maximum value is 16000 for GP3, and 64000 if IO2.

- `storage_size` - (Required) The storage per node in gigabytes.

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/couchbasecloud/terraform-provider-couchbasecapella
go 1.15

require (
github.com/couchbasecloud/couchbase-capella-api-go-client v0.0.0-20220222152544-72d8ea8d2fa7
github.com/couchbasecloud/couchbase-capella-api-go-client v0.0.0-20220805085932-0e6b314617ba
github.com/hashicorp/terraform-plugin-sdk/v2 v2.8.0
)

Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ github.com/couchbasecloud/couchbase-capella-api-go-client v0.0.0-20220114092813-
github.com/couchbasecloud/couchbase-capella-api-go-client v0.0.0-20220114092813-8323dc35022e/go.mod h1:03u0LWYFTdpJ0aptWx3hR03fNJM0frsSUQN0Ez3ZXMc=
github.com/couchbasecloud/couchbase-capella-api-go-client v0.0.0-20220222152544-72d8ea8d2fa7 h1:WkzNRlyJYeJtDLR3yldvhQhO/LLXiMaztIbSRYsX+8o=
github.com/couchbasecloud/couchbase-capella-api-go-client v0.0.0-20220222152544-72d8ea8d2fa7/go.mod h1:QPVzXaeaBgzUID2BBafzxFZGs1i0YdG8l0J8iseTZaY=
github.com/couchbasecloud/couchbase-capella-api-go-client v0.0.0-20220805085932-0e6b314617ba h1:tVY4B/ka4Fh3+mT3yKLEgxG+lbPpBKVCnR7gSff4sdY=
github.com/couchbasecloud/couchbase-capella-api-go-client v0.0.0-20220805085932-0e6b314617ba/go.mod h1:QPVzXaeaBgzUID2BBafzxFZGs1i0YdG8l0J8iseTZaY=
github.com/couchbaselabs/couchbase-cloud-go-client v1.0.2-0.20211201143422-2b4d1f40f66d h1:4RjL4hKYnqvQHVLmzN4NwRR+2y1rnmyCWx/RkNtdqjw=
github.com/couchbaselabs/couchbase-cloud-go-client v1.0.2-0.20211201143422-2b4d1f40f66d/go.mod h1:7BNRWBnJJpY+jkPsHSkV4+OGSDOWN5lxnQdPOYitmN8=
github.com/couchbaselabs/couchbase-cloud-go-client v1.4.0/go.mod h1:7BNRWBnJJpY+jkPsHSkV4+OGSDOWN5lxnQdPOYitmN8=
Expand Down
36 changes: 26 additions & 10 deletions provider/resource_couchbasecapella_hosted_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func resourceCouchbaseCapellaHostedCluster() *schema.Resource {
"iops": {
Description: "IOPS",
Type: schema.TypeInt,
Required: true,
Optional: true,
ValidateFunc: validateIops,
},
"storage_size": {
Expand Down Expand Up @@ -194,9 +194,9 @@ func resourceCouchbaseCapellaHostedClusterCreate(ctx context.Context, d *schema.
environment := "hosted"
clusterName := d.Get("name").(string)
projectId := d.Get("project_id").(string)
servers := expandHostedServersSet(d.Get("servers").(*schema.Set))
supportPackage := expandHostedSupportPackageSet((d.Get("support_package")).(*schema.Set))
place := expandHostedPlaceSet(d.Get("place").(*schema.Set))
supportPackage := expandHostedSupportPackageSet((d.Get("support_package")).(*schema.Set))
servers := expandHostedServersSet(d.Get("servers").(*schema.Set), place.Hosted.Provider)

// force Single AZ to true if support package is Basic
if supportPackage.Type == couchbasecapella.V3SUPPORTPACKAGETYPE_BASIC {
Expand Down Expand Up @@ -315,7 +315,9 @@ func resourceCouchbaseCapellaHostedClusterUpdate(ctx context.Context, d *schema.

// Servers Update
if d.HasChange("servers") {
servers := expandHostedServersSet(d.Get("servers").(*schema.Set))
place := expandHostedPlaceSet(d.Get("place").(*schema.Set))
provider := place.Hosted.Provider
servers := expandHostedServersSet(d.Get("servers").(*schema.Set), provider)
v3UpdateClusterServersRequest := *couchbasecapella.NewV3UpdateClusterServersRequest(servers) // V3UpdateClusterServersRequest | (optional)
_, err := client.ClustersV3Api.ClustersV3updateServers(auth, clusterId).V3UpdateClusterServersRequest(v3UpdateClusterServersRequest).Execute()
if err != nil {
Expand Down Expand Up @@ -370,7 +372,7 @@ func resourceCouchbaseCapellaHostedClusterDelete(ctx context.Context, d *schema.

// Wait for the cluster to be destroyed
deleteStateConf := &resource.StateChangeConf{
Pending: []string{"destroying"},
Pending: []string{"rebalancing", "destroying"},
Target: []string{""},
Refresh: func() (interface{}, string, error) {
statusResp, _, _ := client.ClustersV3Api.ClustersV3status(auth, clusterId).Execute()
Expand All @@ -390,12 +392,12 @@ func resourceCouchbaseCapellaHostedClusterDelete(ctx context.Context, d *schema.

// expandHostedServersSet is responsible for converting the servers set into
// a slice of type V3Servers
func expandHostedServersSet(servers *schema.Set) []couchbasecapella.V3Servers {
func expandHostedServersSet(servers *schema.Set, provider couchbasecapella.V3Provider) []couchbasecapella.V3Servers {
result := make([]couchbasecapella.V3Servers, servers.Len())

for i, value := range servers.List() {
v := value.(map[string]interface{})
result[i] = createHostedServer(v)
result[i] = createHostedServer(v, provider)
}

return result
Expand All @@ -411,18 +413,28 @@ func expandHostedServiceList(services []interface{}) (res []couchbasecapella.V3C
return res
}

func createHostedServer(v map[string]interface{}) couchbasecapella.V3Servers {
func createHostedServer(v map[string]interface{}, provider couchbasecapella.V3Provider) couchbasecapella.V3Servers {
var server couchbasecapella.V3Servers
for _, storages := range v["storage"].(*schema.Set).List() {
storage, ok := storages.(map[string]interface{})
if ok {
if ok && provider != "gcp" {
server = couchbasecapella.V3Servers{
Size: int32(v["size"].(int)),
Compute: v["compute"].(string),
Services: expandHostedServiceList(v["services"].([]interface{})),
Storage: couchbasecapella.V3ServersStorage{
Type: couchbasecapella.V3StorageType((storage["storage_type"].(string))),
IOPS: Int32(int32(storage["iops"].(int))),
Size: int32(storage["storage_size"].(int)),
},
}
} else if ok && provider == "gcp" {
server = couchbasecapella.V3Servers{
Size: int32(v["size"].(int)),
Compute: v["compute"].(string),
Services: expandHostedServiceList(v["services"].([]interface{})),
Storage: couchbasecapella.V3ServersStorage{
Type: couchbasecapella.V3StorageType((storage["storage_type"].(string))),
IOPS: int32(storage["iops"].(int)),
Size: int32(storage["storage_size"].(int)),
},
}
Expand Down Expand Up @@ -514,3 +526,7 @@ func flattenStorage(storage couchbasecapella.V3ClusterStorage) []interface{} {

return []interface{}{s}
}

func Int32(v int32) *int32 {
return &v
}
Loading

0 comments on commit 42779b4

Please sign in to comment.