Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions docs/data-sources/pcu_types.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "astra_pcu_types Data Source - terraform-provider-astra"
subcategory: ""
description: |-
Retrieves a list of available PCU types. Can be filtered by cloud provider and region.
---

# astra_pcu_types (Data Source)

Retrieves a list of available PCU types. Can be filtered by cloud provider and region.

## Example Usage

```terraform
# Get all available PCU types
data "astra_pcu_types" "all" {}

output "all_pcu_types" {
value = {
for t in data.astra_pcu_types.all.results : "${t.cloud_provider}-${t.region}-${t.type}" => t
}
}

# Get PCU types filtered by cloud provider and region
data "astra_pcu_types" "filtered" {
cloud_provider = "aws"
region = "us-east-1"
}

output "filtered_pcu_types" {
value = data.astra_pcu_types.filtered.results
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Optional

- `cloud_provider` (String) Cloud provider to filter the PCU types by (e.g., aws, gcp, azure).
- `region` (String) Region to filter the PCU types by.

### Read-Only

- `results` (Attributes List) The list of available PCU types matching the specified criteria. (see [below for nested schema](#nestedatt--results))

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

Read-Only:

- `cloud_provider` (String) The cloud provider of the PCU type.
- `details` (Attributes) Hardware details of the PCU type. (see [below for nested schema](#nestedatt--results--details))
- `region` (String) The region of the PCU type.
- `type` (String) The type of the PCU (e.g., generalPurpose, cacheOptimized).

<a id="nestedatt--results--details"></a>
### Nested Schema for `results.details`

Read-Only:

- `disk_cache` (String) Amount of disk cache.
- `memory` (String) Amount of memory.
- `vcpu` (Number) Number of vCPUs.
18 changes: 18 additions & 0 deletions examples/data-sources/astra_pcu_types/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Get all available PCU types
data "astra_pcu_types" "all" {}

output "all_pcu_types" {
value = {
for t in data.astra_pcu_types.all.results : "${t.cloud_provider}-${t.region}-${t.type}" => t
}
}

# Get PCU types filtered by cloud provider and region
data "astra_pcu_types" "filtered" {
cloud_provider = "aws"
region = "us-east-1"
}

output "filtered_pcu_types" {
value = data.astra_pcu_types.filtered.results
}
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.24.0
toolchain go1.24.2

require (
github.com/datastax/astra-client-go/v2 v2.3.0
github.com/datastax/astra-client-go/v2 v2.3.1-0.20260707004805-fa3962dc26a3
github.com/datastax/pulsar-admin-client-go v0.0.2
github.com/google/uuid v1.6.0
github.com/hashicorp/go-cty v1.5.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ github.com/cyphar/filepath-securejoin v0.4.1 h1:JyxxyPEaktOD+GAnqIqTf9A8tHyAG22r
github.com/cyphar/filepath-securejoin v0.4.1/go.mod h1:Sdj7gXlvMcPZsbhwhQ33GguGLDGQL7h7bg04C/+u9jI=
github.com/datastax/astra-client-go/v2 v2.3.0 h1:+W7xz3dQFklXB3O0kUcr0R3r/cx2lNFxP95LE4WfLm0=
github.com/datastax/astra-client-go/v2 v2.3.0/go.mod h1:piBMy3fnDcLN8+MDQfvjZr8ejcP2oh+CXkQYwNy8blA=
github.com/datastax/astra-client-go/v2 v2.3.1-0.20260707004805-fa3962dc26a3 h1:wN/xyxERjlbq3pxrlT6yLr7yXX32L7bK9fbPO1h+qBI=
github.com/datastax/astra-client-go/v2 v2.3.1-0.20260707004805-fa3962dc26a3/go.mod h1:piBMy3fnDcLN8+MDQfvjZr8ejcP2oh+CXkQYwNy8blA=
github.com/datastax/pulsar-admin-client-go v0.0.2 h1:CValQbSLI6q1PuCzkM4Tr3tAgwSi6RYDJ7PxvcBLyhw=
github.com/datastax/pulsar-admin-client-go v0.0.2/go.mod h1:GOBpX6jwznrSlECwGeOZE6sNFJJ+FtYkwlv8PgFCZng=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
104 changes: 104 additions & 0 deletions internal/provider/data_source_pcu_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package provider

import (
"context"

"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
)

var (
_ datasource.DataSource = &pcuTypesDataSource{}
_ datasource.DataSourceWithConfigure = &pcuTypesDataSource{}
)

func NewPCUTypesDataSource() datasource.DataSource {
return &pcuTypesDataSource{}
}

type pcuTypesDataSource struct {
BasePCUDataSource
}

type pcuTypesDataSourceModel struct {
CloudProvider types.String `tfsdk:"cloud_provider"`
Region types.String `tfsdk:"region"`
Results []PcuTypeModel `tfsdk:"results"`
}

func (d *pcuTypesDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, res *datasource.MetadataResponse) {
res.TypeName = req.ProviderTypeName + "_pcu_types"
}

func (d *pcuTypesDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, res *datasource.SchemaResponse) {
res.Schema = schema.Schema{
Description: "Retrieves a list of available PCU types. Can be filtered by cloud provider and region.",
Attributes: map[string]schema.Attribute{
"cloud_provider": schema.StringAttribute{
Optional: true,
Description: "Cloud provider to filter the PCU types by (e.g., aws, gcp, azure).",
},
"region": schema.StringAttribute{
Optional: true,
Description: "Region to filter the PCU types by.",
},
"results": schema.ListNestedAttribute{
Computed: true,
Description: "The list of available PCU types matching the specified criteria.",
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"type": schema.StringAttribute{
Computed: true,
Description: "The type of the PCU (e.g., generalPurpose, cacheOptimized).",
},
"region": schema.StringAttribute{
Computed: true,
Description: "The region of the PCU type.",
},
"cloud_provider": schema.StringAttribute{
Computed: true,
Description: "The cloud provider of the PCU type.",
},
"details": schema.SingleNestedAttribute{
Computed: true,
Description: "Hardware details of the PCU type.",
Attributes: map[string]schema.Attribute{
"vcpu": schema.Int32Attribute{
Computed: true,
Description: "Number of vCPUs.",
},
"memory": schema.StringAttribute{
Computed: true,
Description: "Amount of memory.",
},
"disk_cache": schema.StringAttribute{
Computed: true,
Description: "Amount of disk cache.",
},
},
},
},
},
},
},
}
}

func (d *pcuTypesDataSource) Read(ctx context.Context, req datasource.ReadRequest, res *datasource.ReadResponse) {
var data pcuTypesDataSourceModel

diags := req.Config.Get(ctx, &data)
if res.Diagnostics.Append(diags...); res.Diagnostics.HasError() {
return
}

results, diags := d.groups.FindTypes(ctx, data.CloudProvider, data.Region)
if res.Diagnostics.Append(diags...); res.Diagnostics.HasError() {
return
}

data.Results = results

res.Diagnostics.Append(res.State.Set(ctx, &data)...)
}
1 change: 1 addition & 0 deletions internal/provider/provider_framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func (p *astraProvider) DataSources(_ context.Context) []func() datasource.DataS
NewPCUGroupsDataSource,
NewPCUGroupDataSource,
NewPCUGroupAssociationsDataSource,
NewPCUTypesDataSource,
}
}

Expand Down
13 changes: 13 additions & 0 deletions internal/provider/types_pcus.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ type PcuGroupAssociationModel struct {
//UpdatedBy types.String `tfsdk:"updated_by"`
}

type PcuTypeModel struct {
Type types.String `tfsdk:"type"`
Region types.String `tfsdk:"region"`
CloudProvider types.String `tfsdk:"cloud_provider"`
Details PcuTypeDetailsModel `tfsdk:"details"`
}

type PcuTypeDetailsModel struct {
VCPU types.Int32 `tfsdk:"vcpu"`
Memory types.String `tfsdk:"memory"`
DiskCache types.String `tfsdk:"disk_cache"`
}

var (
PcuAttrGroupId = "pcu_group_id"
PcuAttrGroupIds = PcuAttrGroupId + "s"
Expand Down
37 changes: 37 additions & 0 deletions internal/provider/utils_pcu.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type PcuGroupsService interface {
Unpark(ctx context.Context, id types.String) (*PcuGroupModel, diag.Diagnostics)
Delete(ctx context.Context, id types.String) diag.Diagnostics
AwaitStatus(ctx context.Context, id types.String, target astra.PCUGroupStatus) (*PcuGroupModel, diag.Diagnostics)
FindTypes(ctx context.Context, provider, region types.String) ([]PcuTypeModel, diag.Diagnostics)
}

type PcuGroupAssociationsService interface {
Expand Down Expand Up @@ -338,6 +339,29 @@ func (s *PcuGroupAssociationsServiceImpl) Delete(ctx context.Context, groupId ty
return HTTPResponseDiagErr(res, err, "error deleting PCU group association")
}

func (s *PcuGroupsServiceImpl) FindTypes(ctx context.Context, provider, region types.String) ([]PcuTypeModel, diag.Diagnostics) {
body := astra.PCUGroupTypesRequest{
Provider: provider.ValueStringPointer(),
Region: region.ValueStringPointer(),
}

tflog.Debug(ctx, "Reading PCU types", map[string]any{"body": body})

resp, err := s.client.PcuGetTypesWithResponse(ctx, body)

if diags := ParsedHTTPResponseDiagErr(resp, err, "failed to get PCU types"); diags.HasError() {
return nil, diags
}

res := make([]PcuTypeModel, 0) // don't want to return a nil b/c terraform should serialize it as [] and not null

for _, rawType := range *resp.JSON200 {
res = append(res, deserializePcuTypeFromAPI(rawType))
}

return res, nil
}

func deserializePcuGroupFromAPI(rawPCU astra.PCUGroup) PcuGroupModel {
return PcuGroupModel{
Id: types.StringPointerValue(rawPCU.Uuid),
Expand Down Expand Up @@ -370,3 +394,16 @@ func deserializePcuGroupAssociationFromAPI(rawAssociation astra.PCUAssociation)
//CreatedBy: types.StringPointerValue(rawAssociation.CreatedBy),
}
}

func deserializePcuTypeFromAPI(rawType astra.PCUGroupTypeResponse) PcuTypeModel {
return PcuTypeModel{
Type: types.StringPointerValue(rawType.Type),
CloudProvider: types.StringPointerValue(rawType.Provider),
Region: types.StringPointerValue(rawType.Region),
Details: PcuTypeDetailsModel{
VCPU: types.Int32PointerValue(rawType.Details.VCPU),
Memory: types.StringPointerValue(rawType.Details.Memory),
DiskCache: types.StringPointerValue(rawType.Details.DiskCache),
},
}
}
Loading