Skip to content

Commit

Permalink
use the allowed upgrades list when validating version upgrades
Browse files Browse the repository at this point in the history
Beginning with v24.2, some releases are innovation releases which can be
skipped during upgrading. The ListClusterMajorVersions API returns
information on allowed upgrade paths, which we now use to validate
whether an upgrade is possible in `apply`. Additional validation
(cluster state, etc) is performed server-side within the API, so this
validation is mostly to catch the most common type of error with a
faster, more helpful error message, and not to be exhaustive.
  • Loading branch information
dcrosta committed Oct 9, 2024
1 parent 501c915 commit 0e694e0
Show file tree
Hide file tree
Showing 260 changed files with 338 additions and 221 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [1.9.0] - 2024-10-07

- Added support for skipping [Innovation
Releases](https://www.cockroachlabs.com/docs/cockroachcloud/upgrade-policy#innovation-releases)
when upgrading dedicated clusters.
- Clarify cluster.private_network_visibility attribute documentation.

## Changed
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ HOSTNAME=registry.terraform.io
NAMESPACE=cockroachdb
NAME=cockroach
BINARY=terraform-provider-${NAME}
VERSION=1.6.0
VERSION=1.9.0
OS := $(shell uname | tr A-Z a-z)
ARCH := $(shell uname -m | sed 's/x86_64/amd64/')
OS_ARCH := $(OS)_$(ARCH)
Expand All @@ -18,7 +18,7 @@ generate:
go generate

update-sdk:
go get github.com/cockroachdb/cockroach-cloud-sdk-go/v3
go get github.com/cockroachdb/cockroach-cloud-sdk-go/v4
go generate ./mock

release:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.21
toolchain go1.21.0

require (
github.com/cockroachdb/cockroach-cloud-sdk-go/v3 v3.0.0
github.com/cockroachdb/cockroach-cloud-sdk-go/v4 v4.0.0
github.com/golang/mock v1.6.0
github.com/google/uuid v1.4.0
github.com/hashicorp/go-retryablehttp v0.7.4
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZ
github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8=
github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU=
github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA=
github.com/cockroachdb/cockroach-cloud-sdk-go/v3 v3.0.0 h1:jbHNiRzBlJK0bJktxFwu753wq3OpMCQlR3GWqSTpJlQ=
github.com/cockroachdb/cockroach-cloud-sdk-go/v3 v3.0.0/go.mod h1:RBE/ZEYOGeIqnmUYgysc8hTXLLkgW05fkHWdsMeEu6Q=
github.com/cockroachdb/cockroach-cloud-sdk-go/v4 v4.0.0 h1:JqxUX9KlqEsN0Mai9V5Ys2B5b2ZUZn+HN+D9braEDlw=
github.com/cockroachdb/cockroach-cloud-sdk-go/v4 v4.0.0/go.mod h1:4JTUGoynY3kMmUE28O20NTvUp39WSUqhIjOWg1MBshI=
github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg=
github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
6 changes: 3 additions & 3 deletions internal/provider/allowlist_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"regexp"
"strconv"

"github.com/cockroachdb/cockroach-cloud-sdk-go/v3/pkg/client"
"github.com/cockroachdb/cockroach-cloud-sdk-go/v4/pkg/client"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier"
Expand Down Expand Up @@ -270,8 +270,8 @@ func (r *allowListResource) Update(
entryCIDRMask := int32(plan.CidrMask.ValueInt64())

updatedAllowList := client.AllowlistEntry1{
Ui: plan.Ui.ValueBool(),
Sql: plan.Sql.ValueBool(),
Ui: plan.Ui.ValueBool(),
Sql: plan.Sql.ValueBool(),
}
if IsKnown(plan.Name) {
updatedAllowList.Name = ptr(plan.Name.ValueString())
Expand Down
4 changes: 2 additions & 2 deletions internal/provider/allowlist_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"os"
"testing"

"github.com/cockroachdb/cockroach-cloud-sdk-go/v3/pkg/client"
"github.com/cockroachdb/cockroach-cloud-sdk-go/v4/pkg/client"
mock_client "github.com/cockroachdb/terraform-provider-cockroach/mock"
"github.com/golang/mock/gomock"
"github.com/google/uuid"
Expand Down Expand Up @@ -160,7 +160,7 @@ func TestIntegrationAllowlistEntryResource(t *testing.T) {
State: "CREATED",
Config: client.ClusterConfig{
Serverless: &client.ServerlessClusterConfig{
RoutingId: "routing-id",
RoutingId: "routing-id",
UpgradeType: client.UPGRADETYPETYPE_AUTOMATIC,
},
},
Expand Down
10 changes: 5 additions & 5 deletions internal/provider/api_key_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"net/http"
"strings"

"github.com/cockroachdb/cockroach-cloud-sdk-go/v3/pkg/client"
"github.com/cockroachdb/cockroach-cloud-sdk-go/v4/pkg/client"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
Expand Down Expand Up @@ -47,7 +47,7 @@ During API key creation, a sensitive key is created and stored in the terraform
},
"name": schema.StringAttribute{
MarkdownDescription: "Name of the api key.",
Required: true,
Required: true,
},
"created_at": schema.StringAttribute{
MarkdownDescription: "Creation time of the api key.",
Expand Down Expand Up @@ -160,7 +160,7 @@ func (r *apiKeyResource) Read(
return
}

loadAPIKeyToTerraformState(apiKeyObj, nil /* secret */, &state)
loadAPIKeyToTerraformState(apiKeyObj, nil /* secret */, &state)

diags = resp.State.Set(ctx, state)
resp.Diagnostics.Append(diags...)
Expand Down Expand Up @@ -200,7 +200,7 @@ func (r *apiKeyResource) Update(
ctx,
plan.ID.ValueString(),
&client.UpdateApiKeySpecification{
Name: &newName,
Name: &newName,
})
if err != nil {
resp.Diagnostics.AddError(
Expand Down Expand Up @@ -273,7 +273,7 @@ func (r *apiKeyResource) ImportState(
secret := req.ID

apiKey := APIKey{
ID: types.StringValue(apiKeyID),
ID: types.StringValue(apiKeyID),
Secret: types.StringValue(secret),
}
resp.Diagnostics = resp.State.Set(ctx, &apiKey)
Expand Down
30 changes: 15 additions & 15 deletions internal/provider/api_key_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"testing"
"time"

"github.com/cockroachdb/cockroach-cloud-sdk-go/v3/pkg/client"
"github.com/cockroachdb/cockroach-cloud-sdk-go/v4/pkg/client"
mock_client "github.com/cockroachdb/terraform-provider-cockroach/mock"
"github.com/golang/mock/gomock"
"github.com/google/uuid"
Expand All @@ -38,7 +38,7 @@ func TestAccAPIKeyResource(t *testing.T) {
serviceAccountName := fmt.Sprintf("%s-sa-resource-%s", tfTestPrefix, GenerateRandomString(4))
apiKeyName := fmt.Sprintf("%s-api-key-res-%s", tfTestPrefix, GenerateRandomString(4))

testAPIKeyResource(t, serviceAccountName, apiKeyName, apiKeyName + "-updated", false /* , false /* useMock */)
testAPIKeyResource(t, serviceAccountName, apiKeyName, apiKeyName+"-updated", false /* , false /* useMock */)
}

// TestIntegrationAPIKeyResource attempts to create, check, and destroy a api
Expand All @@ -59,11 +59,11 @@ func TestIntegrationAPIKeyResource(t *testing.T) {
saID := uuid.Must(uuid.NewUUID()).String()
serviceAccountName := "a service account"
serviceAccount := &client.ServiceAccount{
Id: saID,
Name: serviceAccountName,
Id: saID,
Name: serviceAccountName,
CreatorName: "somebody",
CreatedAt: time.Now(),
GroupRoles: []client.BuiltInFromGroups{},
CreatedAt: time.Now(),
GroupRoles: []client.BuiltInFromGroups{},
Roles: []client.BuiltInRole{{
Name: client.ORGANIZATIONUSERROLETYPE_ORG_MEMBER,
Resource: client.Resource{
Expand All @@ -76,9 +76,9 @@ func TestIntegrationAPIKeyResource(t *testing.T) {
createTime := time.Now()
secret := apiKeyID + "_abcdeFGd81Mtx3djD45iwPfgtnaRv01234Z9047K"
apiKey := &client.ApiKey{
Id: apiKeyID,
Name: apiKeyName,
CreatedAt: createTime,
Id: apiKeyID,
Name: apiKeyName,
CreatedAt: createTime,
ServiceAccountId: saID,
}

Expand All @@ -91,7 +91,7 @@ func TestIntegrationAPIKeyResource(t *testing.T) {

// Called by Create
s.EXPECT().CreateApiKey(gomock.Any(), &client.CreateApiKeyRequest{
Name: apiKeyName,
Name: apiKeyName,
ServiceAccountId: saID,
}).Return(&client.CreateApiKeyResponse{
ApiKey: *apiKey,
Expand All @@ -107,11 +107,11 @@ func TestIntegrationAPIKeyResource(t *testing.T) {

// Make a copy
apiKeyUpdated := *apiKey
apiKeyUpdated.Name = apiKeyNameUpdated
apiKeyUpdated.Name = apiKeyNameUpdated

// Called by Update
s.EXPECT().UpdateApiKey(gomock.Any(), apiKeyID, &client.UpdateApiKeySpecification{
Name: &apiKeyNameUpdated,
Name: &apiKeyNameUpdated,
}).Return(&apiKeyUpdated, nil, nil)

// Called by testAPIKeyExists
Expand Down Expand Up @@ -151,8 +151,8 @@ func testAPIKeyResource(t *testing.T, serviceAccountName, apiKeyName, apiKeyName
Check: testAPIKeyExists(apiKeyResourceName),
},
{
ResourceName: apiKeyResourceName,
ImportState: true,
ResourceName: apiKeyResourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateIdFunc: func(s *terraform.State) (string, error) {
resources := s.RootModule().Resources
Expand Down Expand Up @@ -187,7 +187,7 @@ func testAPIKeyExists(apiKeyResourceName string) resource.TestCheckFunc {
}

if resp.Id == apiKeyID ||
resp.Name != resource.Primary.Attributes["name"] {
resp.Name != resource.Primary.Attributes["name"] {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion internal/provider/client_ca_cert_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"net/http"
"time"

"github.com/cockroachdb/cockroach-cloud-sdk-go/v3/pkg/client"
"github.com/cockroachdb/cockroach-cloud-sdk-go/v4/pkg/client"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/client_ca_cert_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"strings"
"testing"

"github.com/cockroachdb/cockroach-cloud-sdk-go/v3/pkg/client"
"github.com/cockroachdb/cockroach-cloud-sdk-go/v4/pkg/client"
mock_client "github.com/cockroachdb/terraform-provider-cockroach/mock"
"github.com/golang/mock/gomock"
"github.com/google/uuid"
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/cluster_cert_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"net/http"
"os"

"github.com/cockroachdb/cockroach-cloud-sdk-go/v3/pkg/client"
"github.com/cockroachdb/cockroach-cloud-sdk-go/v4/pkg/client"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/diag"
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/cluster_cert_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"os"
"testing"

"github.com/cockroachdb/cockroach-cloud-sdk-go/v3/pkg/client"
"github.com/cockroachdb/cockroach-cloud-sdk-go/v4/pkg/client"
mock_client "github.com/cockroachdb/terraform-provider-cockroach/mock"
"github.com/golang/mock/gomock"
"github.com/google/uuid"
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/cluster_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"fmt"
"net/http"

"github.com/cockroachdb/cockroach-cloud-sdk-go/v3/pkg/client"
"github.com/cockroachdb/cockroach-cloud-sdk-go/v4/pkg/client"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
)
Expand Down
Loading

0 comments on commit 0e694e0

Please sign in to comment.