Skip to content

Commit 253f3f6

Browse files
authored
Add dbType to database creation fro Vector support (#314)
1 parent d3332f1 commit 253f3f6

File tree

6 files changed

+32
-5
lines changed

6 files changed

+32
-5
lines changed

docs/data-sources/database.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ data "astra_database" "db" {
3232
- `cqlsh_url` (String) URL for cqlsh web
3333
- `data_endpoint_url` (String) REST API URL
3434
- `datacenters` (Map of String) Map of Datacenter IDs. The map key is "cloud_provider.region". Example: "GCP.us-east4".
35+
- `db_type` (String) Database Type. Only 'vector' is supported. For serverless, this field will be omitted
3536
- `grafana_url` (String) URL for the grafana dashboard for this database
3637
- `graphql_url` (String) Graphql URL
3738
- `id` (String) The ID of this resource.

docs/resources/database.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ output "cqlsh_url" {
7070

7171
### Optional
7272

73+
- `db_type` (String) Database type. Currently only `vector` is supported. Omit this optional field if you want a regular severless database.
7374
- `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`.
7475
- `timeouts` (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))
7576

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/datastax/terraform-provider-astra/v2
33
go 1.18
44

55
require (
6-
github.com/datastax/astra-client-go/v2 v2.2.50-0.20230626192203-43de11466bf8
6+
github.com/datastax/astra-client-go/v2 v2.2.50
77
github.com/datastax/pulsar-admin-client-go v0.0.0-20230707040954-1a4745e07587
88
github.com/google/uuid v1.3.1
99
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEM
9797
github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA=
9898
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
9999
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
100-
github.com/datastax/astra-client-go/v2 v2.2.50-0.20230626192203-43de11466bf8 h1:lcjdcx7OmSmsXhuD7400+P8WYXGM4Q5y9gw61POOq58=
101-
github.com/datastax/astra-client-go/v2 v2.2.50-0.20230626192203-43de11466bf8/go.mod h1:zxXWuqDkYia7PzFIL3T7RmjChc9LN81UnfI2yB4kE7M=
100+
github.com/datastax/astra-client-go/v2 v2.2.50 h1:GEKSQTphbEz0Qe29Uyl2yxs1FuN9N0ID4gXLsy4HuH0=
101+
github.com/datastax/astra-client-go/v2 v2.2.50/go.mod h1:zxXWuqDkYia7PzFIL3T7RmjChc9LN81UnfI2yB4kE7M=
102102
github.com/datastax/pulsar-admin-client-go v0.0.0-20230707040954-1a4745e07587 h1:3jv+O0hWcz3oj3sZ9/Ov9/m1Vaqx8Ql8jp5ZeA13O5A=
103103
github.com/datastax/pulsar-admin-client-go v0.0.0-20230707040954-1a4745e07587/go.mod h1:guL8YZ5gJINN+h5Kmja1AnuzhxLU3sHQL8o/8HYLtqk=
104104
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

internal/provider/data_source_database.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ func dataSourceDatabase() *schema.Resource {
114114
Type: schema.TypeString,
115115
},
116116
},
117+
"db_type": {
118+
Description: "Database Type. Only 'vector' is supported. For serverless, this field will be omitted",
119+
Type: schema.TypeString,
120+
Computed: true,
121+
},
117122
},
118123
}
119124
}

internal/provider/resource_database.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ var availableCloudProviders = []string{
2222
"azure",
2323
}
2424

25+
var availableDbTypes = []string{
26+
"vector",
27+
}
28+
2529
var databaseCreateTimeout = time.Minute * 40
2630
var databaseReadTimeout = time.Minute * 5
2731
var databaseDeleteTimeout = time.Minute * 20
@@ -86,6 +90,13 @@ func resourceDatabase() *schema.Resource {
8690
Optional: true,
8791
Default: true,
8892
},
93+
"db_type": {
94+
Description: "Database type. Currently only `vector` is supported. Omit this optional field if you want a regular severless database.",
95+
Type: schema.TypeString,
96+
Optional: true,
97+
ForceNew: true,
98+
ValidateFunc: validation.StringInSlice(availableDbTypes, false),
99+
},
89100
// Computed
90101
"owner_id": {
91102
Description: "The owner id.",
@@ -164,6 +175,7 @@ func resourceDatabaseCreate(ctx context.Context, resourceData *schema.ResourceDa
164175
keyspace := resourceData.Get("keyspace").(string)
165176
cloudProvider := resourceData.Get("cloud_provider").(string)
166177
regions := resourceData.Get("regions").([]interface{})
178+
dbType := resourceData.Get("db_type").(string)
167179

168180
if len(regions) < 1 {
169181
return diag.Errorf("\"region\" array must have at least 1 region specified")
@@ -184,14 +196,19 @@ func resourceDatabaseCreate(ctx context.Context, resourceData *schema.ResourceDa
184196
}
185197
}
186198

187-
resp, err := client.CreateDatabaseWithResponse(ctx, astra.CreateDatabaseJSONRequestBody{
199+
createDbRequest := astra.CreateDatabaseJSONRequestBody{
188200
Name: name,
189201
Keyspace: keyspace,
190202
CloudProvider: astra.CloudProvider(cloudProvider),
191203
CapacityUnits: 1,
192204
Region: region,
193205
Tier: astra.Tier("serverless"),
194-
})
206+
}
207+
// if Vector DB was requested, add that to the request
208+
if len(dbType) > 0 {
209+
createDbRequest.DbType = (*astra.DatabaseInfoCreateDbType)(&dbType)
210+
}
211+
resp, err := client.CreateDatabaseWithResponse(ctx, createDbRequest)
195212
if err != nil {
196213
return diag.FromErr(err)
197214
}
@@ -564,6 +581,9 @@ func flattenDatabase(db *astra.Database) map[string]interface{} {
564581
flatDB["regions"] = regions
565582
flatDB["datacenters"] = datacenters
566583
}
584+
if db.Info.DbType != nil {
585+
flatDB["db_type"] = *db.Info.DbType
586+
}
567587
return flatDB
568588
}
569589

0 commit comments

Comments
 (0)