diff --git a/docs/data-sources/database.md b/docs/data-sources/database.md index 1563a41..29d2ea6 100644 --- a/docs/data-sources/database.md +++ b/docs/data-sources/database.md @@ -32,6 +32,7 @@ data "astra_database" "db" { - `cqlsh_url` (String) URL for cqlsh web - `data_endpoint_url` (String) REST API URL - `datacenters` (Map of String) Map of Datacenter IDs. The map key is "cloud_provider.region". Example: "GCP.us-east4". +- `db_type` (String) Database Type. Only 'vector' is supported. For serverless, this field will be omitted - `grafana_url` (String) URL for the grafana dashboard for this database - `graphql_url` (String) Graphql URL - `id` (String) The ID of this resource. diff --git a/docs/resources/database.md b/docs/resources/database.md index 18ef6e5..dc873f5 100644 --- a/docs/resources/database.md +++ b/docs/resources/database.md @@ -70,6 +70,7 @@ output "cqlsh_url" { ### 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`. - `timeouts` (Block, Optional) (see [below for nested schema](#nestedblock--timeouts)) diff --git a/go.mod b/go.mod index 737c564..44db53c 100644 --- a/go.mod +++ b/go.mod @@ -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-0.20230626192203-43de11466bf8 + github.com/datastax/astra-client-go/v2 v2.2.50 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 diff --git a/go.sum b/go.sum index bcf166e..32bee4e 100644 --- a/go.sum +++ b/go.sum @@ -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-0.20230626192203-43de11466bf8 h1:lcjdcx7OmSmsXhuD7400+P8WYXGM4Q5y9gw61POOq58= -github.com/datastax/astra-client-go/v2 v2.2.50-0.20230626192203-43de11466bf8/go.mod h1:zxXWuqDkYia7PzFIL3T7RmjChc9LN81UnfI2yB4kE7M= +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/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= diff --git a/internal/provider/data_source_database.go b/internal/provider/data_source_database.go index 58d813b..dcb462b 100644 --- a/internal/provider/data_source_database.go +++ b/internal/provider/data_source_database.go @@ -114,6 +114,11 @@ func dataSourceDatabase() *schema.Resource { Type: schema.TypeString, }, }, + "db_type": { + Description: "Database Type. Only 'vector' is supported. For serverless, this field will be omitted", + Type: schema.TypeString, + Computed: true, + }, }, } } diff --git a/internal/provider/resource_database.go b/internal/provider/resource_database.go index 0abf008..028aaa5 100644 --- a/internal/provider/resource_database.go +++ b/internal/provider/resource_database.go @@ -22,6 +22,10 @@ var availableCloudProviders = []string{ "azure", } +var availableDbTypes = []string{ + "vector", +} + var databaseCreateTimeout = time.Minute * 40 var databaseReadTimeout = time.Minute * 5 var databaseDeleteTimeout = time.Minute * 20 @@ -86,6 +90,13 @@ func resourceDatabase() *schema.Resource { Optional: true, Default: true, }, + "db_type": { + Description: "Database type. Currently only `vector` is supported. Omit this optional field if you want a regular severless database.", + Type: schema.TypeString, + Optional: true, + ForceNew: true, + ValidateFunc: validation.StringInSlice(availableDbTypes, false), + }, // Computed "owner_id": { Description: "The owner id.", @@ -164,6 +175,7 @@ func resourceDatabaseCreate(ctx context.Context, resourceData *schema.ResourceDa keyspace := resourceData.Get("keyspace").(string) cloudProvider := resourceData.Get("cloud_provider").(string) regions := resourceData.Get("regions").([]interface{}) + dbType := resourceData.Get("db_type").(string) if len(regions) < 1 { return diag.Errorf("\"region\" array must have at least 1 region specified") @@ -184,14 +196,19 @@ func resourceDatabaseCreate(ctx context.Context, resourceData *schema.ResourceDa } } - resp, err := client.CreateDatabaseWithResponse(ctx, astra.CreateDatabaseJSONRequestBody{ + createDbRequest := astra.CreateDatabaseJSONRequestBody{ Name: name, Keyspace: keyspace, CloudProvider: astra.CloudProvider(cloudProvider), CapacityUnits: 1, Region: region, Tier: astra.Tier("serverless"), - }) + } + // if Vector DB was requested, add that to the request + if len(dbType) > 0 { + createDbRequest.DbType = (*astra.DatabaseInfoCreateDbType)(&dbType) + } + resp, err := client.CreateDatabaseWithResponse(ctx, createDbRequest) if err != nil { return diag.FromErr(err) } @@ -564,6 +581,9 @@ func flattenDatabase(db *astra.Database) map[string]interface{} { flatDB["regions"] = regions flatDB["datacenters"] = datacenters } + if db.Info.DbType != nil { + flatDB["db_type"] = *db.Info.DbType + } return flatDB }