Skip to content

Commit

Permalink
Update CC SDK to v1.4.0 (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
erademacher committed Aug 10, 2023
1 parent 6562186 commit a2628c5
Show file tree
Hide file tree
Showing 58 changed files with 1,592 additions and 601 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.0.0] - 2023-08-10

### Notes

- The CockroachDB Cloud Terraform Provider is now generally available with semantic versioning compatibility promises.

### Changed

- connection_params field on the connection_string data source is now an object instead of a string map.

### Fixed

- Fixed an issue where changing `num_virtual_cpus` on a `cockroach_cluster` resource would fail to scale the cluster
and would result in an inconsistent state error.
- Added validation to prevent multiple serverless regions from being marked as "primary", which could result in an
inconsistent state error.
- Fixed "not a valid value" errors that occurred when reading recently added enum values, such as cluster status.

## [0.7.0] - 2023-07-13

Expand Down
13 changes: 12 additions & 1 deletion docs/data-sources/connection_string.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,18 @@ Generic connection string for a cluster.

### Read-Only

- `connection_params` (Map of String) List of individual connection string parameters. Can be used to build nonstandard connection strings.
- `connection_params` (Attributes) List of individual connection string parameters. Can be used to build nonstandard connection strings. (see [below for nested schema](#nestedatt--connection_params))
- `connection_string` (String) Fully formatted connection string. Assumes the cluster certificate is stored in the default location.

<a id="nestedatt--connection_params"></a>
### Nested Schema for `connection_params`

Read-Only:

- `database` (String) Database value to use in a connection URL.
- `host` (String) Host value to use in a connection URL.
- `password` (String, Sensitive) Password value to use in a connection URL.
- `port` (String) Port value to use in a connection URL.
- `username` (String) Username value to use in a connection URL.


3 changes: 3 additions & 0 deletions docs/resources/user_role_grants.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Required:
- `resource_type` (String) Type of resource. Allowed values are:
* ORGANIZATION
* CLUSTER
* FOLDER
- `role_name` (String) Name of the role to grant. Allowed values are:
* DEVELOPER
* ADMIN
Expand All @@ -42,6 +43,8 @@ Required:
* CLUSTER_OPERATOR_WRITER
* CLUSTER_DEVELOPER
* CLUSTER_CREATOR
* FOLDER_ADMIN
* FOLDER_MOVER

Optional:

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/cockroachdb/terraform-provider-cockroach
go 1.18

require (
github.com/cockroachdb/cockroach-cloud-sdk-go v1.3.0
github.com/cockroachdb/cockroach-cloud-sdk-go v1.4.0
github.com/golang/mock v1.6.0
github.com/google/uuid v1.3.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 @@ -27,8 +27,8 @@ github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgI
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQkY=
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/cockroachdb/cockroach-cloud-sdk-go v1.3.0 h1:6vjzv7fvQP5bcVgTx6gYLiGSgz+iQDQ2f4pmUH9Trcw=
github.com/cockroachdb/cockroach-cloud-sdk-go v1.3.0/go.mod h1:oG9ylbcVGOF7IbVAW2nx5F6ry9a2dZD1H9rd+qd4P60=
github.com/cockroachdb/cockroach-cloud-sdk-go v1.4.0 h1:VLXNL7oYG5ySlPWaUlucHdiFTCCSViVobrC1b9Tg5Mg=
github.com/cockroachdb/cockroach-cloud-sdk-go v1.4.0/go.mod h1:oG9ylbcVGOF7IbVAW2nx5F6ry9a2dZD1H9rd+qd4P60=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand Down
42 changes: 32 additions & 10 deletions internal/provider/connection_string_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,31 @@ func (d *connectionStringDataSource) Schema(
Computed: true,
Description: "Fully formatted connection string. Assumes the cluster certificate is stored in the default location.",
},
"connection_params": schema.MapAttribute{
Computed: true,
ElementType: types.StringType,
"connection_params": schema.SingleNestedAttribute{
Computed: true,
Attributes: map[string]schema.Attribute{
"host": schema.StringAttribute{
Computed: true,
Description: "Host value to use in a connection URL.",
},
"port": schema.StringAttribute{
Computed: true,
Description: "Port value to use in a connection URL.",
},
"database": schema.StringAttribute{
Computed: true,
Description: "Database value to use in a connection URL.",
},
"username": schema.StringAttribute{
Computed: true,
Description: "Username value to use in a connection URL.",
},
"password": schema.StringAttribute{
Computed: true,
Sensitive: true,
Description: "Password value to use in a connection URL.",
},
},
Description: "List of individual connection string parameters. Can be used to build nonstandard connection strings.",
},
},
Expand Down Expand Up @@ -152,10 +174,15 @@ func (d *connectionStringDataSource) Read(
}

connectionString := apiResp.GetConnectionString()
connectionParams := apiResp.GetParams()
config.ConnectionParams = &ConnectionParams{
Host: types.StringValue(apiResp.Params.Host),
Port: types.StringValue(apiResp.Params.Port),
Database: types.StringValue(apiResp.Params.Database),
Username: types.StringPointerValue(apiResp.Params.Username),
}

if IsKnown(config.Password) {
connectionParams["Password"] = config.Password.ValueString()
config.ConnectionParams.Password = config.Password
if connectionURL, err := url.Parse(connectionString); err != nil {
resp.Diagnostics.AddWarning("Couldn't parse connection URL to inject password", err.Error())
} else {
Expand All @@ -165,11 +192,6 @@ func (d *connectionStringDataSource) Read(
}

config.ConnectionString = types.StringValue(connectionString)
config.ConnectionParams, diags = types.MapValueFrom(ctx, types.StringType, connectionParams)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}

diags = resp.State.Set(ctx, config)
resp.Diagnostics.Append(diags...)
Expand Down
17 changes: 13 additions & 4 deletions internal/provider/connection_string_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,15 @@ func TestIntegrationConnectionStringDataSource(t *testing.T) {
SqlUser: &sqlUser,
Os: &os,
}
fakeString := "postgresql://test@fake.cockroachlabs.cloud:26257/testdb"
username := "test"
connectionStringResponse := &client.GetConnectionStringResponse{
ConnectionString: &fakeString,
Params: &map[string]string{},
ConnectionString: "postgresql://test@fake.cockroachlabs.cloud:26257/testdb",
Params: client.ConnectionStringParameters{
Database: "testdb",
Host: "fake.cockroachlabs.cloud",
Port: "26257",
Username: &username,
},
}

httpOkResponse := &http.Response{Status: http.StatusText(http.StatusOK)}
Expand Down Expand Up @@ -106,7 +111,11 @@ func testConnectionStringDataSource(t *testing.T, clusterName string, useMock bo
Config: getTestConnectionStringResourceConfig(clusterName, sqlPassword),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(connectStrDataSourceName, "connection_string"),
resource.TestCheckResourceAttrSet(connectStrDataSourceName, "connection_params.%"),
resource.TestCheckResourceAttrSet(connectStrDataSourceName, "connection_params.host"),
resource.TestCheckResourceAttrSet(connectStrDataSourceName, "connection_params.port"),
resource.TestCheckResourceAttr(connectStrDataSourceName, "connection_params.database", "testdb"),
resource.TestCheckResourceAttr(connectStrDataSourceName, "connection_params.username", "test"),
resource.TestCheckResourceAttr(connectStrDataSourceName, "connection_params.password", sqlPassword),
resource.TestCheckResourceAttrWith(connectStrDataSourceName, "connection_string", func(value string) error {
connectURL, err := url.Parse(value)
if err != nil {
Expand Down
22 changes: 15 additions & 7 deletions internal/provider/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,22 @@ type ClusterCert struct {
Cert types.String `tfsdk:"cert"`
}

type ConnectionParams struct {
Host types.String `tfsdk:"host"`
Port types.String `tfsdk:"port"`
Database types.String `tfsdk:"database"`
Username types.String `tfsdk:"username"`
Password types.String `tfsdk:"password"`
}

type ConnectionString struct {
ID types.String `tfsdk:"id"`
OS types.String `tfsdk:"os"`
Database types.String `tfsdk:"database"`
SqlUser types.String `tfsdk:"sql_user"`
Password types.String `tfsdk:"password"`
ConnectionString types.String `tfsdk:"connection_string"`
ConnectionParams types.Map `tfsdk:"connection_params"`
ID types.String `tfsdk:"id"`
OS types.String `tfsdk:"os"`
Database types.String `tfsdk:"database"`
SqlUser types.String `tfsdk:"sql_user"`
Password types.String `tfsdk:"password"`
ConnectionString types.String `tfsdk:"connection_string"`
ConnectionParams *ConnectionParams `tfsdk:"connection_params"`
}

type Database struct {
Expand Down
11 changes: 1 addition & 10 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,7 @@ func (p *provider) Configure(
}

var apiKey string
if config.ApiKey.IsUnknown() {
// cannot connect to client with an unknown value
resp.Diagnostics.AddWarning(
"Unable to create client",
"Cannot use unknown value as apikey",
)
return
}

if config.ApiKey.IsNull() {
if !IsKnown(config.ApiKey) {
apiKey = os.Getenv(CockroachAPIKey)
} else {
apiKey = config.ApiKey.ValueString()
Expand Down
79 changes: 79 additions & 0 deletions mock/service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a2628c5

Please sign in to comment.