Skip to content

Commit

Permalink
Make keyspace optional for database create (#323)
Browse files Browse the repository at this point in the history
Fixes #316
  • Loading branch information
emerkle826 authored Nov 9, 2023
1 parent 253f3f6 commit c78ea52
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion docs/resources/database.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ output "cqlsh_url" {
### Required

- `cloud_provider` (String) The cloud provider to launch the database. (Currently supported: aws, azure, gcp)
- `keyspace` (String) Initial keyspace name. For additional keyspaces, use the astra_keyspace resource.
- `name` (String) Astra database name.
- `regions` (List of String) Cloud regions to launch the database. (see https://docs.datastax.com/en/astra/docs/database-regions.html for supported regions)

### Optional

- `db_type` (String) Database type. Currently only `vector` is supported. Omit this optional field if you want a regular severless database.
- `deletion_protection` (Boolean) Whether or not to allow Terraform to destroy the instance. Unless this field is set to false in Terraform state, a `terraform destroy` or `terraform apply` command that deletes the instance will fail. Defaults to `true`.
- `keyspace` (String) Initial keyspace name. For additional keyspaces, use the astra_keyspace resource. If omitted, Astra will use its default, currently 'default_keysapce'
- `timeouts` (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))

### Read-Only
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/datastax/terraform-provider-astra/v2
go 1.18

require (
github.com/datastax/astra-client-go/v2 v2.2.50
github.com/datastax/astra-client-go/v2 v2.2.51
github.com/datastax/pulsar-admin-client-go v0.0.0-20230707040954-1a4745e07587
github.com/google/uuid v1.3.1
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEM
github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA=
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/datastax/astra-client-go/v2 v2.2.50 h1:GEKSQTphbEz0Qe29Uyl2yxs1FuN9N0ID4gXLsy4HuH0=
github.com/datastax/astra-client-go/v2 v2.2.50/go.mod h1:zxXWuqDkYia7PzFIL3T7RmjChc9LN81UnfI2yB4kE7M=
github.com/datastax/astra-client-go/v2 v2.2.51 h1:Eptn/UNQiHT6uT9Tzg1iZUOmkyzdZpeXPJBIuzTIvZA=
github.com/datastax/astra-client-go/v2 v2.2.51/go.mod h1:zxXWuqDkYia7PzFIL3T7RmjChc9LN81UnfI2yB4kE7M=
github.com/datastax/pulsar-admin-client-go v0.0.0-20230707040954-1a4745e07587 h1:3jv+O0hWcz3oj3sZ9/Ov9/m1Vaqx8Ql8jp5ZeA13O5A=
github.com/datastax/pulsar-admin-client-go v0.0.0-20230707040954-1a4745e07587/go.mod h1:guL8YZ5gJINN+h5Kmja1AnuzhxLU3sHQL8o/8HYLtqk=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
19 changes: 11 additions & 8 deletions internal/provider/resource_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,6 @@ func resourceDatabase() *schema.Resource {
ForceNew: true,
ValidateFunc: validation.StringMatch(regexp.MustCompile("^.{2,}"), "name must be atleast 2 characters"),
},
"keyspace": {
Description: "Initial keyspace name. For additional keyspaces, use the astra_keyspace resource.",
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateDiagFunc: validateKeyspace,
},
"cloud_provider": {
Description: "The cloud provider to launch the database. (Currently supported: aws, azure, gcp)",
Type: schema.TypeString,
Expand All @@ -84,6 +77,13 @@ func resourceDatabase() *schema.Resource {
},
},
// Optional
"keyspace": {
Description: "Initial keyspace name. For additional keyspaces, use the astra_keyspace resource. If omitted, Astra will use its default, currently 'default_keysapce'",
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateDiagFunc: validateKeyspace,
},
"deletion_protection": {
Description: "Whether or not to allow Terraform to destroy the instance. Unless this field is set to false in Terraform state, a `terraform destroy` or `terraform apply` command that deletes the instance will fail. Defaults to `true`.",
Type: schema.TypeBool,
Expand Down Expand Up @@ -198,12 +198,15 @@ func resourceDatabaseCreate(ctx context.Context, resourceData *schema.ResourceDa

createDbRequest := astra.CreateDatabaseJSONRequestBody{
Name: name,
Keyspace: keyspace,
CloudProvider: astra.CloudProvider(cloudProvider),
CapacityUnits: 1,
Region: region,
Tier: astra.Tier("serverless"),
}
// if keysapce was specified, add it to the request
if len(keyspace) > 0 {
createDbRequest.Keyspace = &keyspace
}
// if Vector DB was requested, add that to the request
if len(dbType) > 0 {
createDbRequest.DbType = (*astra.DatabaseInfoCreateDbType)(&dbType)
Expand Down

0 comments on commit c78ea52

Please sign in to comment.