|
| 1 | +// Copyright (c) HashiCorp, Inc. |
| 2 | +// SPDX-License-Identifier: MPL-2.0 |
| 3 | + |
| 4 | +package odb |
| 5 | + |
| 6 | +import ( |
| 7 | + "context" |
| 8 | + |
| 9 | + "github.com/aws/aws-sdk-go-v2/service/odb" |
| 10 | + "github.com/hashicorp/terraform-plugin-framework/datasource" |
| 11 | + "github.com/hashicorp/terraform-plugin-framework/datasource/schema" |
| 12 | + "github.com/hashicorp/terraform-plugin-framework/types" |
| 13 | + "github.com/hashicorp/terraform-provider-aws/internal/create" |
| 14 | + "github.com/hashicorp/terraform-provider-aws/internal/framework" |
| 15 | + "github.com/hashicorp/terraform-provider-aws/internal/framework/flex" |
| 16 | + fwtypes "github.com/hashicorp/terraform-provider-aws/internal/framework/types" |
| 17 | + "github.com/hashicorp/terraform-provider-aws/names" |
| 18 | +) |
| 19 | + |
| 20 | +// Function annotations are used for datasource registration to the Provider. DO NOT EDIT. |
| 21 | +// @FrameworkDataSource("aws_odb_db_system_shapes", name="Db System Shapes") |
| 22 | +func newDataSourceDBSystemShapes(context.Context) (datasource.DataSourceWithConfigure, error) { |
| 23 | + return &dataSourceDBSystemShapesList{}, nil |
| 24 | +} |
| 25 | + |
| 26 | +const ( |
| 27 | + DSNameDBSystemShapesList = "Db System Shapes List Data Source" |
| 28 | +) |
| 29 | + |
| 30 | +type dataSourceDBSystemShapesList struct { |
| 31 | + framework.DataSourceWithModel[dbSystemShapesListDataSourceModel] |
| 32 | +} |
| 33 | + |
| 34 | +func (d *dataSourceDBSystemShapesList) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { |
| 35 | + resp.Schema = schema.Schema{ |
| 36 | + Attributes: map[string]schema.Attribute{ |
| 37 | + "availability_zone_id": schema.StringAttribute{ |
| 38 | + Optional: true, |
| 39 | + Description: "The physical ID of the AZ, for example, use1-az4. This ID persists across accounts.", |
| 40 | + }, |
| 41 | + "db_system_shapes": schema.ListAttribute{ |
| 42 | + Computed: true, |
| 43 | + CustomType: fwtypes.NewListNestedObjectTypeOf[dbSystemShapeDataSourceModel](ctx), |
| 44 | + Description: "The list of shapes and their properties. Information about a hardware system model (shape) that's available for an Exadata infrastructure." + |
| 45 | + "The shape determines resources, such as CPU cores, memory, and storage, to allocate to the Exadata infrastructure.", |
| 46 | + }, |
| 47 | + }, |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +func (d *dataSourceDBSystemShapesList) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { |
| 52 | + conn := d.Meta().ODBClient(ctx) |
| 53 | + |
| 54 | + var data dbSystemShapesListDataSourceModel |
| 55 | + resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) |
| 56 | + if resp.Diagnostics.HasError() { |
| 57 | + return |
| 58 | + } |
| 59 | + input := odb.ListDbSystemShapesInput{} |
| 60 | + if !data.AvailabilityZoneId.IsNull() && !data.AvailabilityZoneId.IsUnknown() { |
| 61 | + input.AvailabilityZoneId = data.AvailabilityZoneId.ValueStringPointer() |
| 62 | + } |
| 63 | + paginator := odb.NewListDbSystemShapesPaginator(conn, &input) |
| 64 | + var out odb.ListDbSystemShapesOutput |
| 65 | + for paginator.HasMorePages() { |
| 66 | + page, err := paginator.NextPage(ctx) |
| 67 | + if err != nil { |
| 68 | + resp.Diagnostics.AddError( |
| 69 | + create.ProblemStandardMessage(names.ODB, create.ErrActionReading, DSNameDBSystemShapesList, "", err), |
| 70 | + err.Error(), |
| 71 | + ) |
| 72 | + return |
| 73 | + } |
| 74 | + |
| 75 | + if page != nil && len(page.DbSystemShapes) > 0 { |
| 76 | + out.DbSystemShapes = append(out.DbSystemShapes, page.DbSystemShapes...) |
| 77 | + } |
| 78 | + } |
| 79 | + resp.Diagnostics.Append(flex.Flatten(ctx, out, &data)...) |
| 80 | + if resp.Diagnostics.HasError() { |
| 81 | + return |
| 82 | + } |
| 83 | + |
| 84 | + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) |
| 85 | +} |
| 86 | + |
| 87 | +type dbSystemShapesListDataSourceModel struct { |
| 88 | + framework.WithRegionModel |
| 89 | + AvailabilityZoneId types.String `tfsdk:"availability_zone_id"` |
| 90 | + DbSystemShapes fwtypes.ListNestedObjectValueOf[dbSystemShapeDataSourceModel] `tfsdk:"db_system_shapes"` |
| 91 | +} |
| 92 | + |
| 93 | +type dbSystemShapeDataSourceModel struct { |
| 94 | + AvailableCoreCount types.Int32 `tfsdk:"available_core_count"` |
| 95 | + AvailableCoreCountPerNode types.Int32 `tfsdk:"available_core_count_per_node"` |
| 96 | + AvailableDataStorageInTBs types.Int32 `tfsdk:"available_data_storage_in_tbs"` |
| 97 | + AvailableDataStoragePerServerInTBs types.Int32 `tfsdk:"available_data_storage_per_server_in_tbs"` |
| 98 | + AvailableDbNodePerNodeInGBs types.Int32 `tfsdk:"available_db_node_per_node_in_gbs"` |
| 99 | + AvailableDbNodeStorageInGBs types.Int32 `tfsdk:"available_db_node_storage_in_gbs"` |
| 100 | + AvailableMemoryInGBs types.Int32 `tfsdk:"available_memory_in_gbs"` |
| 101 | + AvailableMemoryPerNodeInGBs types.Int32 `tfsdk:"available_memory_per_node_in_gbs"` |
| 102 | + CoreCountIncrement types.Int32 `tfsdk:"core_count_increment"` |
| 103 | + MaxStorageCount types.Int32 `tfsdk:"max_storage_count"` |
| 104 | + MaximumNodeCount types.Int32 `tfsdk:"maximum_node_count"` |
| 105 | + MinCoreCountPerNode types.Int32 `tfsdk:"min_core_count_per_node"` |
| 106 | + MinDataStorageInTBs types.Int32 `tfsdk:"min_data_storage_in_tbs"` |
| 107 | + MinDbNodeStoragePerNodeInGBs types.Int32 `tfsdk:"min_db_node_storage_per_node_in_gbs"` |
| 108 | + MinMemoryPerNodeInGBs types.Int32 `tfsdk:"min_memory_per_node_in_gbs"` |
| 109 | + MinStorageCount types.Int32 `tfsdk:"min_storage_count"` |
| 110 | + MinimumCoreCount types.Int32 `tfsdk:"minimum_core_count"` |
| 111 | + MinimumNodeCount types.Int32 `tfsdk:"minimum_node_count"` |
| 112 | + Name types.String `tfsdk:"name"` |
| 113 | + RuntimeMinimumCoreCount types.Int32 `tfsdk:"runtime_minimum_core_count"` |
| 114 | + ShapeFamily types.String `tfsdk:"shape_family"` |
| 115 | + ShapeType types.String `tfsdk:"shape_type"` |
| 116 | +} |
0 commit comments