|
| 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 | + odbtypes "github.com/aws/aws-sdk-go-v2/service/odb/types" |
| 11 | + "github.com/hashicorp/terraform-plugin-framework-timetypes/timetypes" |
| 12 | + "github.com/hashicorp/terraform-plugin-framework/datasource" |
| 13 | + "github.com/hashicorp/terraform-plugin-framework/datasource/schema" |
| 14 | + "github.com/hashicorp/terraform-plugin-framework/types" |
| 15 | + "github.com/hashicorp/terraform-provider-aws/internal/create" |
| 16 | + "github.com/hashicorp/terraform-provider-aws/internal/framework" |
| 17 | + "github.com/hashicorp/terraform-provider-aws/internal/framework/flex" |
| 18 | + fwtypes "github.com/hashicorp/terraform-provider-aws/internal/framework/types" |
| 19 | + "github.com/hashicorp/terraform-provider-aws/names" |
| 20 | +) |
| 21 | + |
| 22 | +// @FrameworkDataSource("aws_odb_db_node", name="Db Node") |
| 23 | +func newDataSourceDBNode(context.Context) (datasource.DataSourceWithConfigure, error) { |
| 24 | + return &dataSourceDbNode{}, nil |
| 25 | +} |
| 26 | + |
| 27 | +const ( |
| 28 | + DSNameDBNode = "DB Node Data Source" |
| 29 | +) |
| 30 | + |
| 31 | +type dataSourceDbNode struct { |
| 32 | + framework.DataSourceWithModel[dbNodeDataSourceModel] |
| 33 | +} |
| 34 | + |
| 35 | +func (d *dataSourceDbNode) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { |
| 36 | + resp.Schema = schema.Schema{ |
| 37 | + Attributes: map[string]schema.Attribute{ |
| 38 | + names.AttrARN: framework.ARNAttributeComputedOnly(), |
| 39 | + names.AttrID: schema.StringAttribute{ |
| 40 | + Required: true, |
| 41 | + }, |
| 42 | + "cloud_vm_cluster_id": schema.StringAttribute{ |
| 43 | + Required: true, |
| 44 | + }, |
| 45 | + names.AttrStatus: schema.StringAttribute{ |
| 46 | + Computed: true, |
| 47 | + CustomType: fwtypes.StringEnumType[odbtypes.ResourceStatus](), |
| 48 | + Description: "The current status of the DB node.", |
| 49 | + }, |
| 50 | + names.AttrStatusReason: schema.StringAttribute{ |
| 51 | + Computed: true, |
| 52 | + Description: "Additional information about the status of the DB node.", |
| 53 | + }, |
| 54 | + "additional_details": schema.StringAttribute{ |
| 55 | + Computed: true, |
| 56 | + Description: "Additional information about the planned maintenance.", |
| 57 | + }, |
| 58 | + "backup_ip_id": schema.StringAttribute{ |
| 59 | + Computed: true, |
| 60 | + Description: "The Oracle Cloud ID (OCID) of the backup IP address that's associated with the DB node.", |
| 61 | + }, |
| 62 | + "backup_vnic2_id": schema.StringAttribute{ |
| 63 | + Computed: true, |
| 64 | + Description: "The OCID of the second backup VNIC.", |
| 65 | + }, |
| 66 | + "backup_vnic_id": schema.StringAttribute{ |
| 67 | + Computed: true, |
| 68 | + Description: "The OCID of the backup VNIC.", |
| 69 | + }, |
| 70 | + "cpu_core_count": schema.Int32Attribute{ |
| 71 | + Computed: true, |
| 72 | + Description: "Number of CPU cores enabled on the DB node.", |
| 73 | + }, |
| 74 | + "db_storage_size_in_gbs": schema.Int32Attribute{ |
| 75 | + Computed: true, |
| 76 | + Description: "The amount of local node storage, in gigabytes (GBs), allocated on the DB node.", |
| 77 | + }, |
| 78 | + "db_server_id": schema.StringAttribute{ |
| 79 | + Computed: true, |
| 80 | + Description: "The unique identifier of the DB server that is associated with the DB node.", |
| 81 | + }, |
| 82 | + "db_system_id": schema.StringAttribute{ |
| 83 | + Computed: true, |
| 84 | + Description: "The OCID of the DB system.", |
| 85 | + }, |
| 86 | + "fault_domain": schema.StringAttribute{ |
| 87 | + Computed: true, |
| 88 | + Description: "The name of the fault domain the instance is contained in.", |
| 89 | + }, |
| 90 | + "host_ip_id": schema.StringAttribute{ |
| 91 | + Computed: true, |
| 92 | + Description: "The OCID of the host IP address that's associated with the DB node.", |
| 93 | + }, |
| 94 | + "hostname": schema.StringAttribute{ |
| 95 | + Computed: true, |
| 96 | + Description: "The host name for the DB node.", |
| 97 | + }, |
| 98 | + "ocid": schema.StringAttribute{ |
| 99 | + Computed: true, |
| 100 | + Description: "The OCID of the DB node.", |
| 101 | + }, |
| 102 | + "oci_resource_anchor_name": schema.StringAttribute{ |
| 103 | + Computed: true, |
| 104 | + Description: "The name of the OCI resource anchor for the DB node.", |
| 105 | + }, |
| 106 | + "maintenance_type": schema.StringAttribute{ |
| 107 | + Computed: true, |
| 108 | + CustomType: fwtypes.StringEnumType[odbtypes.DbNodeMaintenanceType](), |
| 109 | + Description: "The type of database node maintenance. Either VMDB_REBOOT_MIGRATION or EXADBXS_REBOOT_MIGRATION.", |
| 110 | + }, |
| 111 | + "memory_size_in_gbs": schema.Int32Attribute{ |
| 112 | + Computed: true, |
| 113 | + Description: "The allocated memory in GBs on the DB node.", |
| 114 | + }, |
| 115 | + "software_storage_size_in_gbs": schema.Int32Attribute{ |
| 116 | + Computed: true, |
| 117 | + Description: "The size (in GB) of the block storage volume allocation for the DB system.", |
| 118 | + }, |
| 119 | + names.AttrCreatedAt: schema.StringAttribute{ |
| 120 | + CustomType: timetypes.RFC3339Type{}, |
| 121 | + Computed: true, |
| 122 | + Description: "The date and time when the DB node was created.", |
| 123 | + }, |
| 124 | + "time_maintenance_window_end": schema.StringAttribute{ |
| 125 | + Computed: true, |
| 126 | + Description: "End date and time of maintenance window.", |
| 127 | + }, |
| 128 | + "time_maintenance_window_start": schema.StringAttribute{ |
| 129 | + Computed: true, |
| 130 | + Description: "Start date and time of maintenance window.", |
| 131 | + }, |
| 132 | + "total_cpu_core_count": schema.Int32Attribute{ |
| 133 | + Computed: true, |
| 134 | + Description: "The total number of CPU cores reserved on the DB node.", |
| 135 | + }, |
| 136 | + "vnic2_id": schema.StringAttribute{ |
| 137 | + Computed: true, |
| 138 | + Description: "The OCID of the second VNIC.", |
| 139 | + }, |
| 140 | + "vnic_id": schema.StringAttribute{ |
| 141 | + Computed: true, |
| 142 | + Description: "The OCID of the VNIC.", |
| 143 | + }, |
| 144 | + "private_ip_address": schema.StringAttribute{ |
| 145 | + Computed: true, |
| 146 | + Description: "The private IP address assigned to the DB node.", |
| 147 | + }, |
| 148 | + "floating_ip_address": schema.StringAttribute{ |
| 149 | + Computed: true, |
| 150 | + Description: "The floating IP address assigned to the DB node.", |
| 151 | + }, |
| 152 | + }, |
| 153 | + } |
| 154 | +} |
| 155 | + |
| 156 | +func (d *dataSourceDbNode) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { |
| 157 | + conn := d.Meta().ODBClient(ctx) |
| 158 | + var data dbNodeDataSourceModel |
| 159 | + resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) |
| 160 | + if resp.Diagnostics.HasError() { |
| 161 | + return |
| 162 | + } |
| 163 | + input := odb.GetDbNodeInput{ |
| 164 | + DbNodeId: data.DbNodeId.ValueStringPointer(), |
| 165 | + CloudVmClusterId: data.CloudVmClusterId.ValueStringPointer(), |
| 166 | + } |
| 167 | + out, err := conn.GetDbNode(ctx, &input) |
| 168 | + if err != nil { |
| 169 | + resp.Diagnostics.AddError( |
| 170 | + create.ProblemStandardMessage(names.ODB, create.ErrActionReading, DSNameDBNode, data.DbNodeId.ValueString(), err), |
| 171 | + err.Error(), |
| 172 | + ) |
| 173 | + return |
| 174 | + } |
| 175 | + resp.Diagnostics.Append(flex.Flatten(ctx, out.DbNode, &data)...) |
| 176 | + if resp.Diagnostics.HasError() { |
| 177 | + return |
| 178 | + } |
| 179 | + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) |
| 180 | +} |
| 181 | + |
| 182 | +type dbNodeDataSourceModel struct { |
| 183 | + framework.WithRegionModel |
| 184 | + CloudVmClusterId types.String `tfsdk:"cloud_vm_cluster_id"` |
| 185 | + DbNodeId types.String `tfsdk:"id"` |
| 186 | + DbNodeArn types.String `tfsdk:"arn"` |
| 187 | + Status fwtypes.StringEnum[odbtypes.ResourceStatus] `tfsdk:"status"` |
| 188 | + StatusReason types.String `tfsdk:"status_reason"` |
| 189 | + AdditionalDetails types.String `tfsdk:"additional_details"` |
| 190 | + BackupIpId types.String `tfsdk:"backup_ip_id"` |
| 191 | + BackupVnic2Id types.String `tfsdk:"backup_vnic2_id"` |
| 192 | + BackupVnicId types.String `tfsdk:"backup_vnic_id"` |
| 193 | + CpuCoreCount types.Int32 `tfsdk:"cpu_core_count"` |
| 194 | + DbNodeStorageSizeInGBs types.Int32 `tfsdk:"db_storage_size_in_gbs"` |
| 195 | + DbServerId types.String `tfsdk:"db_server_id"` |
| 196 | + DbSystemId types.String `tfsdk:"db_system_id"` |
| 197 | + FaultDomain types.String `tfsdk:"fault_domain"` |
| 198 | + HostIpId types.String `tfsdk:"host_ip_id"` |
| 199 | + Hostname types.String `tfsdk:"hostname"` |
| 200 | + Ocid types.String `tfsdk:"ocid"` |
| 201 | + OciResourceAnchorName types.String `tfsdk:"oci_resource_anchor_name"` |
| 202 | + MaintenanceType fwtypes.StringEnum[odbtypes.DbNodeMaintenanceType] `tfsdk:"maintenance_type"` |
| 203 | + MemorySizeInGBs types.Int32 `tfsdk:"memory_size_in_gbs"` |
| 204 | + SoftwareStorageSizeInGB types.Int32 `tfsdk:"software_storage_size_in_gbs"` |
| 205 | + CreatedAt timetypes.RFC3339 `tfsdk:"created_at"` |
| 206 | + TimeMaintenanceWindowEnd types.String `tfsdk:"time_maintenance_window_end"` |
| 207 | + TimeMaintenanceWindowStart types.String `tfsdk:"time_maintenance_window_start"` |
| 208 | + TotalCpuCoreCount types.Int32 `tfsdk:"total_cpu_core_count"` |
| 209 | + Vnic2Id types.String `tfsdk:"vnic2_id"` |
| 210 | + VnicId types.String `tfsdk:"vnic_id"` |
| 211 | + PrivateIpAddress types.String `tfsdk:"private_ip_address"` |
| 212 | + FloatingIpAddress types.String `tfsdk:"floating_ip_address"` |
| 213 | +} |
0 commit comments