From 321fd9b04691f5a1b33c5096e62fc050d576ed78 Mon Sep 17 00:00:00 2001 From: James Southard Date: Tue, 18 Jun 2024 11:49:46 -0400 Subject: [PATCH 1/5] apply Go's opinionated formatting to **comments** This commit makes an atomic commit of go fmt changes to the Apache license formatting to be in-line with Go's opinionated formatting instead of piecemeal on file updates. --- internal/bridgeapi/client.go | 2 +- internal/bridgeapi/cluster.go | 2 +- internal/bridgeapi/defaults.go | 2 +- internal/bridgeapi/doc.go | 2 +- internal/bridgeapi/errors.go | 2 +- internal/bridgeapi/login.go | 2 +- internal/bridgeapi/models.go | 2 +- internal/bridgeapi/quick_get.go | 2 +- internal/provider/data_source_account.go | 2 +- internal/provider/data_source_cloudprovider.go | 2 +- internal/provider/data_source_cluster.go | 2 +- internal/provider/data_source_clusterids.go | 2 +- internal/provider/data_source_clusterrole.go | 2 +- internal/provider/data_source_clusterstatus.go | 2 +- internal/provider/provider.go | 2 +- internal/provider/provider_test.go | 1 + internal/provider/resource_cluster.go | 2 +- 17 files changed, 17 insertions(+), 16 deletions(-) diff --git a/internal/bridgeapi/client.go b/internal/bridgeapi/client.go index 2c9f1cc..24c6513 100644 --- a/internal/bridgeapi/client.go +++ b/internal/bridgeapi/client.go @@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, diff --git a/internal/bridgeapi/cluster.go b/internal/bridgeapi/cluster.go index 0f3d88c..fdd6b02 100644 --- a/internal/bridgeapi/cluster.go +++ b/internal/bridgeapi/cluster.go @@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, diff --git a/internal/bridgeapi/defaults.go b/internal/bridgeapi/defaults.go index a5d9bd4..02b3bd8 100644 --- a/internal/bridgeapi/defaults.go +++ b/internal/bridgeapi/defaults.go @@ -42,7 +42,7 @@ func DefaultClusterName() string { // 10 bits for adj ixAdj := (entropy & 0x0000FFC0) >> 6 // 3 bits for digit 1 - digit1 := 1 + (entropy & 0x00000038) >> 3 + digit1 := 1 + (entropy&0x00000038)>>3 // 3 bits for digit 2 digit2 := 1 + (entropy & 0x00000007) diff --git a/internal/bridgeapi/doc.go b/internal/bridgeapi/doc.go index 6b42e4b..177b8f2 100644 --- a/internal/bridgeapi/doc.go +++ b/internal/bridgeapi/doc.go @@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, diff --git a/internal/bridgeapi/errors.go b/internal/bridgeapi/errors.go index d364e41..862f076 100644 --- a/internal/bridgeapi/errors.go +++ b/internal/bridgeapi/errors.go @@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, diff --git a/internal/bridgeapi/login.go b/internal/bridgeapi/login.go index 58a0206..566d283 100644 --- a/internal/bridgeapi/login.go +++ b/internal/bridgeapi/login.go @@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, diff --git a/internal/bridgeapi/models.go b/internal/bridgeapi/models.go index 9f07ecf..bcc92fc 100644 --- a/internal/bridgeapi/models.go +++ b/internal/bridgeapi/models.go @@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, diff --git a/internal/bridgeapi/quick_get.go b/internal/bridgeapi/quick_get.go index 5909b17..dc1fd0c 100644 --- a/internal/bridgeapi/quick_get.go +++ b/internal/bridgeapi/quick_get.go @@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, diff --git a/internal/provider/data_source_account.go b/internal/provider/data_source_account.go index d6e50c7..9ffc36a 100644 --- a/internal/provider/data_source_account.go +++ b/internal/provider/data_source_account.go @@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, diff --git a/internal/provider/data_source_cloudprovider.go b/internal/provider/data_source_cloudprovider.go index 13147c9..5116704 100644 --- a/internal/provider/data_source_cloudprovider.go +++ b/internal/provider/data_source_cloudprovider.go @@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, diff --git a/internal/provider/data_source_cluster.go b/internal/provider/data_source_cluster.go index 99bece7..9188a07 100644 --- a/internal/provider/data_source_cluster.go +++ b/internal/provider/data_source_cluster.go @@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, diff --git a/internal/provider/data_source_clusterids.go b/internal/provider/data_source_clusterids.go index 959d4f4..eae5a57 100644 --- a/internal/provider/data_source_clusterids.go +++ b/internal/provider/data_source_clusterids.go @@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, diff --git a/internal/provider/data_source_clusterrole.go b/internal/provider/data_source_clusterrole.go index 3da0fed..6ed0f07 100644 --- a/internal/provider/data_source_clusterrole.go +++ b/internal/provider/data_source_clusterrole.go @@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, diff --git a/internal/provider/data_source_clusterstatus.go b/internal/provider/data_source_clusterstatus.go index 4eb982d..9dc226c 100644 --- a/internal/provider/data_source_clusterstatus.go +++ b/internal/provider/data_source_clusterstatus.go @@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 2a2d265..846085e 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, diff --git a/internal/provider/provider_test.go b/internal/provider/provider_test.go index 36b0c40..8e31829 100644 --- a/internal/provider/provider_test.go +++ b/internal/provider/provider_test.go @@ -9,6 +9,7 @@ import ( // providerFactories are used to instantiate a provider during acceptance testing. // The factory function will be invoked for every Terraform CLI command executed // to create a provider server to which the CLI can reattach. +// //lint:ignore U1000 used in other test files var providerFactories = map[string]func() (*schema.Provider, error){ "scaffolding": func() (*schema.Provider, error) { diff --git a/internal/provider/resource_cluster.go b/internal/provider/resource_cluster.go index 23da13a..480c934 100644 --- a/internal/provider/resource_cluster.go +++ b/internal/provider/resource_cluster.go @@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, From 43be88ddc655034ca26eb8e5c5092639e22ef5d1 Mon Sep 17 00:00:00 2001 From: James Southard Date: Tue, 18 Jun 2024 11:49:58 -0400 Subject: [PATCH 2/5] updates default PG version to 16 and min to 14 This commit aligns defaults with current website defaults --- docs/data-sources/cluster.md | 2 +- docs/resources/cluster.md | 2 +- internal/provider/data_source_cluster.go | 2 +- internal/provider/resource_cluster.go | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/data-sources/cluster.md b/docs/data-sources/cluster.md index de8c572..e8f8b22 100644 --- a/docs/data-sources/cluster.md +++ b/docs/data-sources/cluster.md @@ -38,7 +38,7 @@ output "demo" { - `memory` (Number) The total amount of memory available on the cluster's instance in GB (gigabytes). - `name` (String) A human-readable name for the cluster. - `plan_id` (String) The ID of the [cluster's plan](https://docs.crunchybridge.com/concepts/plans-pricing/). Determines instance, CPU, and memory. -- `postgres_version_id` (Number) The cluster's major Postgres version. For example, `14`. +- `postgres_version_id` (Number) The cluster's major Postgres version. For example, `16`. - `provider_id` (String) The [cloud provider](https://docs.crunchybridge.com/api/provider) where the cluster is located. - `region_id` (String) The [provider region](https://docs.crunchybridge.com/api/provider#region) where the cluster is located. - `storage` (Number) The amount of storage available to the cluster in GB (gigabytes). diff --git a/docs/resources/cluster.md b/docs/resources/cluster.md index 27bc745..854e99c 100644 --- a/docs/resources/cluster.md +++ b/docs/resources/cluster.md @@ -40,7 +40,7 @@ output "demo_status" { ### Optional - `is_ha` (Boolean) Whether the cluster is high availability, meaning that it has a secondary it can fail over to quickly in case the primary becomes unavailable. Defaults to `false` -- `major_version` (Number) The cluster's major Postgres version. For example, `14`. Defaults to [Create Cluster](https://docs.crunchybridge.com/api/cluster/#create-cluster) defaults. +- `major_version` (Number) The cluster's major Postgres version. For example, `16`. Defaults to [Create Cluster](https://docs.crunchybridge.com/api/cluster/#create-cluster) defaults. - `plan_id` (String) The ID of the [cluster's plan](https://docs.crunchybridge.com/concepts/plans-pricing/). Determines instance, CPU, and memory. Defaults to `hobby-2`. - `provider_id` (String) The [cloud provider](https://docs.crunchybridge.com/api/provider) where the cluster is located. Defaults to `aws`, allows `aws`, `gcp`, or `azure` - `region_id` (String) The [provider region](https://docs.crunchybridge.com/api/provider#region) where the cluster is located. Defaults to `us-west-1` diff --git a/internal/provider/data_source_cluster.go b/internal/provider/data_source_cluster.go index 9188a07..e44b19a 100644 --- a/internal/provider/data_source_cluster.go +++ b/internal/provider/data_source_cluster.go @@ -54,7 +54,7 @@ func dataSourceCluster() *schema.Resource { }, "postgres_version_id": { Computed: true, - Description: "The cluster's major Postgres version. For example, `14`.", + Description: "The cluster's major Postgres version. For example, `16`.", Type: schema.TypeInt, }, "maintenance_window_start": { diff --git a/internal/provider/resource_cluster.go b/internal/provider/resource_cluster.go index 480c934..00bf976 100644 --- a/internal/provider/resource_cluster.go +++ b/internal/provider/resource_cluster.go @@ -96,11 +96,11 @@ func resourceCluster() *schema.Resource { Type: schema.TypeBool, }, "major_version": { - Default: 14, - Description: "The cluster's major Postgres version. For example, `14`. Defaults to [Create Cluster](https://docs.crunchybridge.com/api/cluster/#create-cluster) defaults.", + Default: 16, + Description: "The cluster's major Postgres version. For example, `16`. Defaults to [Create Cluster](https://docs.crunchybridge.com/api/cluster/#create-cluster) defaults.", Optional: true, Type: schema.TypeInt, - ValidateFunc: validation.IntAtLeast(12), + ValidateFunc: validation.IntAtLeast(14), }, "wait_until_ready": { Description: "Treats the create operation as incomplete until the cluster reports a ready status. Defaults to `false`", From 9e7b246424cbeb16b8a4bad9e48867ffacbf8d13 Mon Sep 17 00:00:00 2001 From: James Southard Date: Tue, 18 Jun 2024 11:50:16 -0400 Subject: [PATCH 3/5] adds support for Hobby-0 plans --- internal/bridgeapi/models.go | 12 ++++++------ internal/provider/data_source_cloudprovider.go | 2 +- internal/provider/data_source_cluster.go | 2 +- internal/provider/resource_cluster.go | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/internal/bridgeapi/models.go b/internal/bridgeapi/models.go index bcc92fc..26a509c 100644 --- a/internal/bridgeapi/models.go +++ b/internal/bridgeapi/models.go @@ -39,7 +39,7 @@ type ClusterDetail struct { HighAvailability bool `json:"is_ha"` PGMajorVersion int `json:"major_version"` MaintWindowStart int `json:"maintenance_window_start"` - MemoryGB int `json:"memory"` + MemoryGB float64 `json:"memory"` // 64 precision isn't required, but likely default arch Name string `json:"name"` PlanID string `json:"plan_id"` ProviderID string `json:"provider_id"` @@ -116,11 +116,11 @@ type ProviderDisk struct { } type Plan struct { - ID string `json:"id"` - CPU int `json:"cpu"` - Memory int `json:"memory"` - Name string `json:"display_name"` - Rate int `json:"rate"` + ID string `json:"id"` + CPU int `json:"cpu"` + Memory float64 `json:"memory"` // 64 precision isn't required, but likely default arch + Name string `json:"display_name"` + Rate int `json:"rate"` } type Region struct { diff --git a/internal/provider/data_source_cloudprovider.go b/internal/provider/data_source_cloudprovider.go index 5116704..44b1803 100644 --- a/internal/provider/data_source_cloudprovider.go +++ b/internal/provider/data_source_cloudprovider.go @@ -57,7 +57,7 @@ func dataSourceCloudProvider() *schema.Resource { "plan_memory": { Computed: true, Description: "The amount of memory on the plan’s instance in gigabytes.", - Type: schema.TypeInt, + Type: schema.TypeFloat, }, "plan_name": { Computed: true, diff --git a/internal/provider/data_source_cluster.go b/internal/provider/data_source_cluster.go index e44b19a..850d171 100644 --- a/internal/provider/data_source_cluster.go +++ b/internal/provider/data_source_cluster.go @@ -70,7 +70,7 @@ func dataSourceCluster() *schema.Resource { "memory": { Computed: true, Description: "The total amount of memory available on the cluster's instance in GB (gigabytes).", - Type: schema.TypeInt, + Type: schema.TypeFloat, }, "name": { Computed: true, diff --git a/internal/provider/resource_cluster.go b/internal/provider/resource_cluster.go index 00bf976..04c138c 100644 --- a/internal/provider/resource_cluster.go +++ b/internal/provider/resource_cluster.go @@ -136,7 +136,7 @@ func resourceCluster() *schema.Resource { "memory": { Computed: true, Description: "The total amount of memory available on the cluster's instance in GB (gigabytes).", - Type: schema.TypeInt, + Type: schema.TypeFloat, }, "updated_at": { Computed: true, From d76a2f3d1538e0005f5b5545b4e0c825bcb9fac6 Mon Sep 17 00:00:00 2001 From: James Southard Date: Tue, 18 Jun 2024 11:50:31 -0400 Subject: [PATCH 4/5] removes requirement for deprecated application_id The application_id is no longer offered through the portal, leading to confusion about provider configuration. This change removes the requirement for the application_id. If anyone uses the forced token swap and leaves off the application_id, there isn't a clear error message for that bad configuration. It is believed that no one is doing the old token swap mechanic anymore. --- docs/index.md | 2 +- internal/provider/provider.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/index.md b/docs/index.md index 6d77c1f..9560b87 100644 --- a/docs/index.md +++ b/docs/index.md @@ -37,11 +37,11 @@ provider "crunchybridge" { ### Required -- `application_id` (String) The application id component of the Crunchy Bridge API key. - `application_secret` (String) The application secret component of the Crunchy Bridge API key. ### Optional +- `application_id` (String) The application id component of the Crunchy Bridge API key. (deprecated) - `bridgeapi_url` (String) The API URL for the Crunchy Bridge platform API. Most users should not need to change this value. - `require_token_swap` (Boolean) When true, forces an exchange of the API key for a short-lived bearer token. diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 846085e..58ffebf 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -65,9 +65,9 @@ func New(version string) func() *schema.Provider { Schema: map[string]*schema.Schema{ idConfigName: { Type: schema.TypeString, - Description: "The application id component of the Crunchy Bridge API key.", + Description: "The application id component of the Crunchy Bridge API key. (deprecated)", DefaultFunc: schema.EnvDefaultFunc("APPLICATION_ID", nil), - Required: true, + Optional: true, }, secretConfigName: { Type: schema.TypeString, @@ -105,8 +105,8 @@ func configure(version string, p *schema.Provider) func(context.Context, *schema id := d.Get(idConfigName).(string) secret := d.Get(secretConfigName).(string) - if (id == "") || (secret == "") { - return nil, diag.Errorf("%s and %s must be configured to non-empty strings for this provider", idConfigName, secretConfigName) + if secret == "" { + return nil, diag.Errorf("%s must be configured to a non-empty string for this provider", secretConfigName) } login := bridgeapi.Login{ Key: id, From 80a23bc3c988656b5750c2bd64068c596e8466a8 Mon Sep 17 00:00:00 2001 From: James Southard Date: Tue, 18 Jun 2024 11:50:55 -0400 Subject: [PATCH 5/5] updates new version administrivia --- .gitignore | 2 +- CHANGELOG.md | 7 +++++++ Makefile | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index a7c26ee..8c0738e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ version.txt bin terraform-provider-crunchybridge - +.vscode diff --git a/CHANGELOG.md b/CHANGELOG.md index a6e41ff..6149949 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,2 +1,9 @@ +## 0.2.0 + * Updates PostgreSQL default version to 16 + * Raises minimum PostgreSQL version to 14 + * Adds support for Hobby-0 plans + * Removes requirement for application_id configuration + + ## 0.1.0 (Initial release) diff --git a/Makefile b/Makefile index f8a50d4..d4326ef 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ TEST?=$$(go list ./... | grep -v 'vendor') HOST=github.com NAME=crunchybridge BINARY=terraform-provider-crunchybridge -TAG_VER?=0.1.0 +TAG_VER?=0.2.0 RELTEMPDIR?=release_tmp CMD_SHA256SUM?="sha256sum" # sometimes 'shasum -a 256'