Skip to content

Commit

Permalink
Add support for provisioning PgBouncer with PostgreSQL (#158)
Browse files Browse the repository at this point in the history
* Bumped version & added support for PgBouncer bundle

* Added tests for valid/invalid pgbouncer plan

* Updated comments

* Renamed test to show intent

* Included PgBouncer in postgresql example

* Update integration test

* Updated version and poolMode schema docs

* - Added options to `AddOnBundle`, and handled addon bundle options mapping.
- Updated doc with new docs link.

* Added tests for addon bundle decoding

* Added test steps for reapplying

* Bump version

* Updated postgres version after merge
  • Loading branch information
minhnguyen-ic authored Apr 28, 2022
1 parent cd1f8aa commit 47f9a44
Show file tree
Hide file tree
Showing 10 changed files with 398 additions and 154 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ BIN_NAME=terraform-provider-instaclustr
# for VERSION, don't add prefix "v", e.g., use "1.9.8" instead of "v1.9.8" as it could break circleCI stuff


VERSION=1.21.0
VERSION=1.22.0

INSTALL_FOLDER=$(HOME)/.terraform.d/plugins/terraform.instaclustr.com/instaclustr/instaclustr/$(VERSION)/darwin_amd64

Expand Down
59 changes: 30 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,21 +277,22 @@ Configuration documentation can be found at the [Instaclustr Terraform Registry]

## Bundles and Versions

Bundle | Versions | Compatible With
---------|-------------|---------------
APACHE_CASSANDRA|2.2.18, 3.0.19, 3.11.8, 4.0 (preview)|
SPARK|2.1.3, 2.3.2|APACHE_CASSANDRA
KAFKA|2.7.1, 2.8.1, 3.0.0|
KAFKA_REST_PROXY|5.0.0|KAFKA
KAFKA_SCHEMA_REGISTRY|5.0.0, 5.0.4|KAFKA
KARAPACE_SCHEMA_REGISTRY|2.1.2|KAFKA <br/> **Not compatible with:** <br/> KAFKA_REST_PROXY, KAFKA_SCHEMA_REGISTRY
OPENSEARCH|1.2.4
ELASTICSEARCH|1.13.3
KAFKA_CONNECT|2.7.1, 2.8.1, 3.0.0|
REDIS|6.0.9|
APACHE_ZOOKEEPER|3.5.8|
POSTGRESQL|13.4|
CADENCE|0.22.4|
| Bundle | Versions | Compatible With |
|--------------------------|---------------------------------------|------------------------------------------------------------------------------------|
| APACHE_CASSANDRA | 2.2.18, 3.0.19, 3.11.8, 4.0 (preview) | |
| SPARK | 2.1.3, 2.3.2 | APACHE_CASSANDRA |
| KAFKA | 2.7.1, 2.8.1, 3.0.0 | |
| KAFKA_REST_PROXY | 5.0.0 | KAFKA |
| KAFKA_SCHEMA_REGISTRY | 5.0.0, 5.0.4 | KAFKA |
| KARAPACE_SCHEMA_REGISTRY | 2.1.2 | KAFKA <br/> **Not compatible with:** <br/> KAFKA_REST_PROXY, KAFKA_SCHEMA_REGISTRY |
| OPENSEARCH | 1.2.4 | |
| ELASTICSEARCH | 1.13.3 | |
| KAFKA_CONNECT | 2.7.1, 2.8.1, 3.0.0 | |
| REDIS | 6.0.9 | |
| APACHE_ZOOKEEPER | 3.5.8 | |
| POSTGRESQL | 13.5, 13.6, 14.1, 14.2 | |
| PGBOUNCER | 1.17.0 | POSTGRESQL |
| CADENCE | 0.22.4 | |

### Migrating from 0.0.1 &rarr; 1.0.0+
A schema change has been made from 0.0.1 which no longer supports the `bundles` argument and uses `bundle` blocks instead. This change can cause `terraform apply` to fail with a message that `bundles` has been removed and/or updating isn't supported. To resolve this -<br>
Expand Down Expand Up @@ -331,20 +332,20 @@ Unit tests are within `instaclustr` folder with `_unit_test` suffix, and used to
Acceptance tests are within `acc_test` folder, and used to run end-to-end testing. We recommend using CircleCI to run your acceptance tests, however you can run them locally. Acceptance tests require end to end interaction with the Instaclustr platform and will create real (paid) infrastructure. If you wish to perform local testing you must set the variables below and run: ```make testacc```
Variable | Command | Description
---------|-------------|--------
TF_ACC|`$ export TF_ACC=1`|Enables online acceptance tests.
IC_USERNAME|`$ export IC_USERNAME=<your instaclustr username>`|Authorizes Provisioning API
IC_API_KEY|`$ export IC_API_KEY=<your provisioning API key>`|Authorizes Provisioning API
KMS_ARN|`$ export KMS_ARN=<your KMS ARN>`|For EBS encryption of nodes. <b><i>Note:</i></b> You cannot use an ARN previously added to your account as an encryption key.
IC_PROV_ACC_NAME|`$ export IC_PROV_ACC_NAME="<your provider name>"`|Your "Run In Your Own Account" account name.
IC_PROV_VPC_ID|`$ export IC_PROV_VPC_ID="<your AWS VPC ID>"`|For provisioning into a custom VPC.
IC_AWS_ACCESS_KEY|`$ export IC_PROV_VPC_ID="<access key for the AWS S3 bucket>"`|For Kafka Connect connection information. See bundle options.
IC_AWS_SECRET_KEY|`$ export IC_PROV_VPC_ID="<secret key for the AWS S3 bucket>"`|For Kafka Connect connection information. See bundle options.
IC_S3_BUCKET_NAME|`$ export IC_PROV_VPC_ID="<AWS S3 bucket name>"`|For Kafka Connect connection information. See bundle options.
IC_AZURE_STORAGE_ACCOUNT_NAME|`$ export IC_PROV_VPC_ID="<account name for the AZURE container storage>"`|For Kafka Connect connection information. See bundle options.
IC_AZURE_STORAGE_ACCOUNT_KEY|`$ export IC_PROV_VPC_ID="<account key for the AZURE container storage>"`|For Kafka Connect connection information. See bundle options.
IC_AZURE_STORAGE_CONTAINER_NAME|`$ export IC_PROV_VPC_ID="<the name of the AZURE container storage>"`|For Kafka Connect connection information. See bundle options.
| Variable | Command | Description |
|---------------------------------|----------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------|
| TF_ACC | `$ export TF_ACC=1` | Enables online acceptance tests. |
| IC_USERNAME | `$ export IC_USERNAME=<your instaclustr username>` | Authorizes Provisioning API |
| IC_API_KEY | `$ export IC_API_KEY=<your provisioning API key>` | Authorizes Provisioning API |
| KMS_ARN | `$ export KMS_ARN=<your KMS ARN>` | For EBS encryption of nodes. <b><i>Note:</i></b> You cannot use an ARN previously added to your account as an encryption key. |
| IC_PROV_ACC_NAME | `$ export IC_PROV_ACC_NAME="<your provider name>"` | Your "Run In Your Own Account" account name. |
| IC_PROV_VPC_ID | `$ export IC_PROV_VPC_ID="<your AWS VPC ID>"` | For provisioning into a custom VPC. |
| IC_AWS_ACCESS_KEY | `$ export IC_PROV_VPC_ID="<access key for the AWS S3 bucket>"` | For Kafka Connect connection information. See bundle options. |
| IC_AWS_SECRET_KEY | `$ export IC_PROV_VPC_ID="<secret key for the AWS S3 bucket>"` | For Kafka Connect connection information. See bundle options. |
| IC_S3_BUCKET_NAME | `$ export IC_PROV_VPC_ID="<AWS S3 bucket name>"` | For Kafka Connect connection information. See bundle options. |
| IC_AZURE_STORAGE_ACCOUNT_NAME | `$ export IC_PROV_VPC_ID="<account name for the AZURE container storage>"` | For Kafka Connect connection information. See bundle options. |
| IC_AZURE_STORAGE_ACCOUNT_KEY | `$ export IC_PROV_VPC_ID="<account key for the AZURE container storage>"` | For Kafka Connect connection information. See bundle options. |
| IC_AZURE_STORAGE_CONTAINER_NAME | `$ export IC_PROV_VPC_ID="<the name of the AZURE container storage>"` | For Kafka Connect connection information. See bundle options. |
#### Running Specific Tests
To run a specific test, use the `testtarget` makefile goal.
Expand Down
39 changes: 39 additions & 0 deletions acc_test/data/invalid_postgresql_pgbouncer_cluster_create.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
provider "instaclustr" {
username = "%s"
api_key = "%s"
api_hostname = "%s"
}

resource "instaclustr_cluster" "invalidPostgresqlWithPgBouncer" {
cluster_name = "testcluster"
node_size = "PGS-DEV-t3.small-5"
data_centre = "US_WEST_2"
sla_tier = "NON_PRODUCTION"
cluster_network = "192.168.0.0/18"
cluster_provider = {
name = "AWS_VPC"
}
rack_allocation = {
nodes_per_rack = 1
number_of_racks = 1
}

bundle {
bundle = "POSTGRESQL"
version = "14.1"
options = {
postgresql_node_count = 1,
client_encryption = false,
replication_mode = "SYNCHRONOUS",
}
}
//Will fail due to invalid pool_mode
bundle {
bundle = "PGBOUNCER"
version = "1.17.0"
options = {
pool_mode = "foobar"
}
}
}

39 changes: 39 additions & 0 deletions acc_test/data/valid_postgresql_cluster_with_pgbouncer_create.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
provider "instaclustr" {
username = "%s"
api_key = "%s"
api_hostname = "%s"
}

resource "instaclustr_cluster" "validPostgresqlWithPgBouncer" {
cluster_name = "testcluster"
node_size = "PGS-DEV-t3.small-5"
data_centre = "US_WEST_2"
sla_tier = "NON_PRODUCTION"
cluster_network = "192.168.0.0/18"
cluster_provider = {
name = "AWS_VPC"
}
rack_allocation = {
nodes_per_rack = 1
number_of_racks = 1
}

bundle {
bundle = "POSTGRESQL"
version = "14.1"
options = {
postgresql_node_count = 1,
client_encryption = false,
replication_mode = "SYNCHRONOUS",
}
}

bundle {
bundle = "PGBOUNCER"
version = "1.17.0"
options = {
pool_mode = "SESSION"
}
}
}

49 changes: 49 additions & 0 deletions acc_test/resource_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,55 @@ func TestValidPostgresqlClusterCreate(t *testing.T) {
})
}

func TestValidPostgresqlWithPgBouncerClusterCreate(t *testing.T) {
testAccProvider := instaclustr.Provider()
testAccProviders := map[string]terraform.ResourceProvider{
"instaclustr": testAccProvider,
}
validConfig, _ := ioutil.ReadFile("data/valid_postgresql_cluster_with_pgbouncer_create.tf")
username := os.Getenv("IC_USERNAME")
apiKey := os.Getenv("IC_API_KEY")
hostname := getOptionalEnv("IC_API_URL", instaclustr.DefaultApiHostname)
oriConfig := fmt.Sprintf(string(validConfig), username, apiKey, hostname)
resource.ParallelTest(t, resource.TestCase{
Providers: testAccProviders,
CheckDestroy: testCheckResourceDeleted("validPostgresqlWithPgBouncer", hostname, username, apiKey),
Steps: []resource.TestStep{
{
Config: oriConfig,
Check: resource.ComposeTestCheckFunc(
testCheckResourceValid("validPostgresqlWithPgBouncer"),
testCheckResourceCreated("validPostgresqlWithPgBouncer", hostname, username, apiKey),
),
}, //Re-apply the same plan, must return empty plan
{
Config: oriConfig,
ExpectNonEmptyPlan: false,
},
},
})
}

func TestPostgresqlWithInvalidPgBouncerConfigClusterCreate(t *testing.T) {
testAccProvider := instaclustr.Provider()
testAccProviders := map[string]terraform.ResourceProvider{
"instaclustr": testAccProvider,
}
invalidConfig, _ := ioutil.ReadFile("data/invalid_postgresql_pgbouncer_cluster_create.tf")
username := os.Getenv("IC_USERNAME")
apiKey := os.Getenv("IC_API_KEY")
hostname := getOptionalEnv("IC_API_URL", instaclustr.DefaultApiHostname)
resource.ParallelTest(t, resource.TestCase{
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(string(invalidConfig), username, apiKey, hostname),
ExpectError: regexp.MustCompile("Invalid poolMode"),
},
},
})
}

func TestValidOpenSearchClusterCreate(t *testing.T) {
testAccProvider := instaclustr.Provider()
testAccProviders := map[string]terraform.ResourceProvider{
Expand Down
Loading

0 comments on commit 47f9a44

Please sign in to comment.