|
| 1 | +// Copyright (c) HashiCorp, Inc. |
| 2 | +// SPDX-License-Identifier: MPL-2.0 |
| 3 | + |
| 4 | +package odb |
| 5 | + |
| 6 | +import ( |
| 7 | + "context" |
| 8 | + "github.com/hashicorp/terraform-plugin-framework/attr" |
| 9 | + "time" |
| 10 | + |
| 11 | + "github.com/aws/aws-sdk-go-v2/service/odb" |
| 12 | + odbtypes "github.com/aws/aws-sdk-go-v2/service/odb/types" |
| 13 | + |
| 14 | + "github.com/hashicorp/terraform-plugin-framework/datasource" |
| 15 | + "github.com/hashicorp/terraform-plugin-framework/datasource/schema" |
| 16 | + "github.com/hashicorp/terraform-plugin-framework/types" |
| 17 | + "github.com/hashicorp/terraform-provider-aws/internal/create" |
| 18 | + "github.com/hashicorp/terraform-provider-aws/internal/framework" |
| 19 | + "github.com/hashicorp/terraform-provider-aws/internal/framework/flex" |
| 20 | + fwtypes "github.com/hashicorp/terraform-provider-aws/internal/framework/types" |
| 21 | + "github.com/hashicorp/terraform-provider-aws/names" |
| 22 | +) |
| 23 | + |
| 24 | +// Function annotations are used for datasource registration to the Provider. DO NOT EDIT. |
| 25 | +// @FrameworkDataSource("aws_odb_db_server", name="Db Server") |
| 26 | +func newDataSourceDbServer(context.Context) (datasource.DataSourceWithConfigure, error) { |
| 27 | + return &dataSourceDbServer{}, nil |
| 28 | +} |
| 29 | + |
| 30 | +const ( |
| 31 | + DSNameDbServer = "Db Server Data Source" |
| 32 | +) |
| 33 | + |
| 34 | +type dataSourceDbServer struct { |
| 35 | + framework.DataSourceWithModel[dbServerDataSourceModel] |
| 36 | +} |
| 37 | + |
| 38 | +func (d *dataSourceDbServer) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { |
| 39 | + resp.Schema = schema.Schema{ |
| 40 | + Attributes: map[string]schema.Attribute{ |
| 41 | + names.AttrID: schema.StringAttribute{ |
| 42 | + Description: "The identifier of the the database server.", |
| 43 | + Required: true, |
| 44 | + }, |
| 45 | + "cloud_exadata_infrastructure_id": schema.StringAttribute{ |
| 46 | + Description: "The identifier of the database server to retrieve information about.", |
| 47 | + Required: true, |
| 48 | + }, |
| 49 | + "status": schema.StringAttribute{ |
| 50 | + CustomType: fwtypes.StringEnumType[odbtypes.ResourceStatus](), |
| 51 | + Computed: true, |
| 52 | + Description: "The status of the database server.", |
| 53 | + }, |
| 54 | + "status_reason": schema.StringAttribute{ |
| 55 | + Computed: true, |
| 56 | + Description: "Additional information about the current status of the database server.", |
| 57 | + }, |
| 58 | + "cpu_core_count": schema.Int32Attribute{ |
| 59 | + Computed: true, |
| 60 | + Description: "The number of CPU cores enabled on the database server.", |
| 61 | + }, |
| 62 | + "db_node_ids": schema.ListAttribute{ |
| 63 | + Computed: true, |
| 64 | + CustomType: fwtypes.ListOfStringType, |
| 65 | + ElementType: types.StringType, |
| 66 | + }, |
| 67 | + "db_node_storage_size_in_gbs": schema.Int32Attribute{ |
| 68 | + Computed: true, |
| 69 | + Description: "The allocated local node storage in GBs on the database server.", |
| 70 | + }, |
| 71 | + "db_server_patching_details": schema.ObjectAttribute{ |
| 72 | + Description: "The scheduling details for the quarterly maintenance window. Patching and\n" + |
| 73 | + "system updates take place during the maintenance window.", |
| 74 | + Computed: true, |
| 75 | + CustomType: fwtypes.NewObjectTypeOf[dbNodePatchingDetailsDbServerDataSourceModel](ctx), |
| 76 | + AttributeTypes: map[string]attr.Type{ |
| 77 | + "estimated_patch_duration": types.Int32Type, |
| 78 | + "patching_status": types.StringType, |
| 79 | + "time_patching_ended": types.StringType, |
| 80 | + "time_patching_started": types.StringType, |
| 81 | + }, |
| 82 | + }, |
| 83 | + "display_name": schema.StringAttribute{ |
| 84 | + Computed: true, |
| 85 | + Description: "The display name of the database server.", |
| 86 | + }, |
| 87 | + "exadata_infrastructure_id": schema.StringAttribute{ |
| 88 | + Computed: true, |
| 89 | + Description: "The exadata infrastructure ID of the database server.", |
| 90 | + }, |
| 91 | + "ocid": schema.StringAttribute{ |
| 92 | + Computed: true, |
| 93 | + Description: "The OCID of the database server to retrieve information about.", |
| 94 | + }, |
| 95 | + "oci_resource_anchor_name": schema.StringAttribute{ |
| 96 | + Computed: true, |
| 97 | + Description: "The name of the OCI resource anchor.", |
| 98 | + }, |
| 99 | + "max_cpu_count": schema.Int32Attribute{ |
| 100 | + Computed: true, |
| 101 | + Description: "The total number of CPU cores available.", |
| 102 | + }, |
| 103 | + "max_db_node_storage_in_gbs": schema.Int32Attribute{ |
| 104 | + Computed: true, |
| 105 | + Description: "The total local node storage available in GBs.", |
| 106 | + }, |
| 107 | + "max_memory_in_gbs": schema.Int32Attribute{ |
| 108 | + Computed: true, |
| 109 | + Description: "The total memory available in GBs.", |
| 110 | + }, |
| 111 | + "memory_size_in_gbs": schema.Int32Attribute{ |
| 112 | + Computed: true, |
| 113 | + Description: "The allocated memory in GBs on the database server.", |
| 114 | + }, |
| 115 | + "shape": schema.StringAttribute{ |
| 116 | + Computed: true, |
| 117 | + Description: "// The shape of the database server. The shape determines the amount of CPU,\n" + |
| 118 | + "storage, and memory resources available.", |
| 119 | + }, |
| 120 | + "created_at": schema.StringAttribute{ |
| 121 | + Computed: true, |
| 122 | + Description: "The date and time when the database server was created.", |
| 123 | + }, |
| 124 | + "vm_cluster_ids": schema.ListAttribute{ |
| 125 | + Computed: true, |
| 126 | + CustomType: fwtypes.ListOfStringType, |
| 127 | + ElementType: types.StringType, |
| 128 | + Description: "The OCID of the VM clusters that are associated with the database server.", |
| 129 | + }, |
| 130 | + "compute_model": schema.StringAttribute{ |
| 131 | + Computed: true, |
| 132 | + CustomType: fwtypes.StringEnumType[odbtypes.ComputeModel](), |
| 133 | + Description: " The compute model of the database server.", |
| 134 | + }, |
| 135 | + "autonomous_vm_cluster_ids": schema.ListAttribute{ |
| 136 | + Computed: true, |
| 137 | + CustomType: fwtypes.ListOfStringType, |
| 138 | + ElementType: types.StringType, |
| 139 | + Description: "The OCID of the autonomous VM clusters that are associated with the database server.", |
| 140 | + }, |
| 141 | + "autonomous_virtual_machine_ids": schema.ListAttribute{ |
| 142 | + Computed: true, |
| 143 | + CustomType: fwtypes.ListOfStringType, |
| 144 | + ElementType: types.StringType, |
| 145 | + Description: "The list of unique identifiers for the Autonomous VMs associated with this database server.", |
| 146 | + }, |
| 147 | + }, |
| 148 | + } |
| 149 | +} |
| 150 | + |
| 151 | +func (d *dataSourceDbServer) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { |
| 152 | + |
| 153 | + conn := d.Meta().ODBClient(ctx) |
| 154 | + |
| 155 | + var data dbServerDataSourceModel |
| 156 | + resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) |
| 157 | + if resp.Diagnostics.HasError() { |
| 158 | + return |
| 159 | + } |
| 160 | + |
| 161 | + input := odb.GetDbServerInput{ |
| 162 | + DbServerId: data.DbServerID.ValueStringPointer(), |
| 163 | + CloudExadataInfrastructureId: data.CloudExadataInfrastructureID.ValueStringPointer(), |
| 164 | + } |
| 165 | + |
| 166 | + out, err := conn.GetDbServer(ctx, &input) |
| 167 | + if err != nil { |
| 168 | + resp.Diagnostics.AddError( |
| 169 | + create.ProblemStandardMessage(names.ODB, create.ErrActionReading, DSNameDbServer, data.DbServerID.ValueString(), err), |
| 170 | + err.Error(), |
| 171 | + ) |
| 172 | + return |
| 173 | + } |
| 174 | + |
| 175 | + if out.DbServer.CreatedAt != nil { |
| 176 | + data.CreatedAt = types.StringValue(out.DbServer.CreatedAt.Format(time.RFC3339)) |
| 177 | + } |
| 178 | + |
| 179 | + resp.Diagnostics.Append(flex.Flatten(ctx, out.DbServer, &data)...) |
| 180 | + if resp.Diagnostics.HasError() { |
| 181 | + return |
| 182 | + } |
| 183 | + |
| 184 | + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) |
| 185 | +} |
| 186 | + |
| 187 | +type dbServerDataSourceModel struct { |
| 188 | + framework.WithRegionModel |
| 189 | + DbServerID types.String `tfsdk:"id"` |
| 190 | + CloudExadataInfrastructureID types.String `tfsdk:"cloud_exadata_infrastructure_id"` |
| 191 | + Status fwtypes.StringEnum[odbtypes.ResourceStatus] `tfsdk:"status"` |
| 192 | + StatusReason types.String `tfsdk:"status_reason"` |
| 193 | + CpuCoreCount types.Int32 `tfsdk:"cpu_core_count"` |
| 194 | + DbNodeIds fwtypes.ListOfString `tfsdk:"db_node_ids"` |
| 195 | + DbNodeStorageSizeInGBs types.Int32 `tfsdk:"db_node_storage_size_in_gbs"` |
| 196 | + DbServerPatchingDetails fwtypes.ObjectValueOf[dbNodePatchingDetailsDbServerDataSourceModel] `tfsdk:"db_server_patching_details"` |
| 197 | + DisplayName types.String `tfsdk:"display_name"` |
| 198 | + ExadataInfrastructureId types.String `tfsdk:"exadata_infrastructure_id"` |
| 199 | + OCID types.String `tfsdk:"ocid"` |
| 200 | + OciResourceAnchorName types.String `tfsdk:"oci_resource_anchor_name"` |
| 201 | + MaxCpuCount types.Int32 `tfsdk:"max_cpu_count"` |
| 202 | + MaxDbNodeStorageInGBs types.Int32 `tfsdk:"max_db_node_storage_in_gbs"` |
| 203 | + MaxMemoryInGBs types.Int32 `tfsdk:"max_memory_in_gbs"` |
| 204 | + MemorySizeInGBs types.Int32 `tfsdk:"memory_size_in_gbs"` |
| 205 | + Shape types.String `tfsdk:"shape"` |
| 206 | + CreatedAt types.String `tfsdk:"created_at" autoflex:",noflatten"` |
| 207 | + VmClusterIds fwtypes.ListOfString `tfsdk:"vm_cluster_ids"` |
| 208 | + ComputeModel fwtypes.StringEnum[odbtypes.ComputeModel] `tfsdk:"compute_model"` |
| 209 | + AutonomousVmClusterIds fwtypes.ListOfString `tfsdk:"autonomous_vm_cluster_ids"` |
| 210 | + AutonomousVirtualMachineIds fwtypes.ListOfString `tfsdk:"autonomous_virtual_machine_ids"` |
| 211 | +} |
| 212 | + |
| 213 | +type dbNodePatchingDetailsDbServerDataSourceModel struct { |
| 214 | + EstimatedPatchDuration types.Int32 `tfsdk:"estimated_patch_duration"` |
| 215 | + PatchingStatus types.String `tfsdk:"patching_status"` |
| 216 | + TimePatchingEnded types.String `tfsdk:"time_patching_ended"` |
| 217 | + TimePatchingStarted types.String `tfsdk:"time_patching_started"` |
| 218 | +} |
0 commit comments