|
| 1 | +// Copyright (c) HashiCorp, Inc. |
| 2 | +// SPDX-License-Identifier: MPL-2.0 |
| 3 | +// ---------------------------------------------------------------------------- |
| 4 | +// |
| 5 | +// *** AUTO GENERATED CODE *** Type: Handwritten *** |
| 6 | +// |
| 7 | +// ---------------------------------------------------------------------------- |
| 8 | +// |
| 9 | +// This code is generated by Magic Modules using the following: |
| 10 | +// |
| 11 | +// Source file: https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/third_party/terraform/services/compute/data_source_google_compute_reservation_block.go |
| 12 | +// |
| 13 | +// DO NOT EDIT this file directly. Any changes made to this file will be |
| 14 | +// overwritten during the next generation cycle. |
| 15 | +// |
| 16 | +// ---------------------------------------------------------------------------- |
| 17 | +package compute |
| 18 | + |
| 19 | +import ( |
| 20 | + "fmt" |
| 21 | + |
| 22 | + "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource" |
| 23 | + transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport" |
| 24 | + |
| 25 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" |
| 26 | +) |
| 27 | + |
| 28 | +func DataSourceGoogleComputeReservationBlock() *schema.Resource { |
| 29 | + return &schema.Resource{ |
| 30 | + Read: dataSourceGoogleComputeReservationBlockRead, |
| 31 | + |
| 32 | + Schema: map[string]*schema.Schema{ |
| 33 | + "name": { |
| 34 | + Type: schema.TypeString, |
| 35 | + Required: true, |
| 36 | + Description: "The name of the reservation block.", |
| 37 | + }, |
| 38 | + "reservation": { |
| 39 | + Type: schema.TypeString, |
| 40 | + Required: true, |
| 41 | + Description: "The name of the parent reservation.", |
| 42 | + }, |
| 43 | + "zone": { |
| 44 | + Type: schema.TypeString, |
| 45 | + Optional: true, |
| 46 | + Description: "The zone where the reservation block resides.", |
| 47 | + }, |
| 48 | + "project": { |
| 49 | + Type: schema.TypeString, |
| 50 | + Optional: true, |
| 51 | + Computed: true, |
| 52 | + Description: "The project in which the resource belongs.", |
| 53 | + }, |
| 54 | + "kind": { |
| 55 | + Type: schema.TypeString, |
| 56 | + Computed: true, |
| 57 | + Description: "Type of the resource. Always compute#reservationBlock for reservation blocks.", |
| 58 | + }, |
| 59 | + "resource_id": { |
| 60 | + Type: schema.TypeString, |
| 61 | + Computed: true, |
| 62 | + Description: "The unique identifier for the resource.", |
| 63 | + }, |
| 64 | + "creation_timestamp": { |
| 65 | + Type: schema.TypeString, |
| 66 | + Computed: true, |
| 67 | + Description: "Creation timestamp in RFC3339 text format.", |
| 68 | + }, |
| 69 | + "self_link": { |
| 70 | + Type: schema.TypeString, |
| 71 | + Computed: true, |
| 72 | + Description: "Server-defined fully-qualified URL for this resource.", |
| 73 | + }, |
| 74 | + "self_link_with_id": { |
| 75 | + Type: schema.TypeString, |
| 76 | + Computed: true, |
| 77 | + Description: "Server-defined URL for this resource with the resource id.", |
| 78 | + }, |
| 79 | + "block_count": { |
| 80 | + Type: schema.TypeInt, |
| 81 | + Computed: true, |
| 82 | + Description: "The number of resources that are allocated in this reservation block.", |
| 83 | + }, |
| 84 | + "in_use_count": { |
| 85 | + Type: schema.TypeInt, |
| 86 | + Computed: true, |
| 87 | + Description: "The number of instances that are currently in use on this reservation block.", |
| 88 | + }, |
| 89 | + "status": { |
| 90 | + Type: schema.TypeString, |
| 91 | + Computed: true, |
| 92 | + Description: "Status of the reservation block.", |
| 93 | + }, |
| 94 | + "reservation_sub_block_count": { |
| 95 | + Type: schema.TypeInt, |
| 96 | + Computed: true, |
| 97 | + Description: "The number of reservation subBlocks associated with this reservation block.", |
| 98 | + }, |
| 99 | + "reservation_sub_block_in_use_count": { |
| 100 | + Type: schema.TypeInt, |
| 101 | + Computed: true, |
| 102 | + Description: "The number of in-use reservation subBlocks associated with this reservation block.", |
| 103 | + }, |
| 104 | + "reservation_maintenance": { |
| 105 | + Type: schema.TypeList, |
| 106 | + Computed: true, |
| 107 | + Description: "Maintenance information for this reservation block.", |
| 108 | + Elem: &schema.Resource{ |
| 109 | + Schema: map[string]*schema.Schema{ |
| 110 | + "maintenance_ongoing_count": { |
| 111 | + Type: schema.TypeInt, |
| 112 | + Computed: true, |
| 113 | + Description: "Number of hosts in the block that have ongoing maintenance.", |
| 114 | + }, |
| 115 | + "maintenance_pending_count": { |
| 116 | + Type: schema.TypeInt, |
| 117 | + Computed: true, |
| 118 | + Description: "Number of hosts in the block that have pending maintenance.", |
| 119 | + }, |
| 120 | + "scheduling_type": { |
| 121 | + Type: schema.TypeString, |
| 122 | + Computed: true, |
| 123 | + Description: "The type of maintenance for the reservation.", |
| 124 | + }, |
| 125 | + "subblock_infra_maintenance_ongoing_count": { |
| 126 | + Type: schema.TypeInt, |
| 127 | + Computed: true, |
| 128 | + Description: "Number of subblock Infrastructure that has ongoing maintenance.", |
| 129 | + }, |
| 130 | + "subblock_infra_maintenance_pending_count": { |
| 131 | + Type: schema.TypeInt, |
| 132 | + Computed: true, |
| 133 | + Description: "Number of subblock Infrastructure that has pending maintenance.", |
| 134 | + }, |
| 135 | + "instance_maintenance_ongoing_count": { |
| 136 | + Type: schema.TypeInt, |
| 137 | + Computed: true, |
| 138 | + Description: "Number of instances that have ongoing maintenance.", |
| 139 | + }, |
| 140 | + "instance_maintenance_pending_count": { |
| 141 | + Type: schema.TypeInt, |
| 142 | + Computed: true, |
| 143 | + Description: "Number of instances that have pending maintenance.", |
| 144 | + }, |
| 145 | + }, |
| 146 | + }, |
| 147 | + }, |
| 148 | + "physical_topology": { |
| 149 | + Type: schema.TypeList, |
| 150 | + Computed: true, |
| 151 | + Description: "The physical topology of the reservation block.", |
| 152 | + Elem: &schema.Resource{ |
| 153 | + Schema: map[string]*schema.Schema{ |
| 154 | + "cluster": { |
| 155 | + Type: schema.TypeString, |
| 156 | + Computed: true, |
| 157 | + Description: "The cluster name of the reservation block.", |
| 158 | + }, |
| 159 | + "block": { |
| 160 | + Type: schema.TypeString, |
| 161 | + Computed: true, |
| 162 | + Description: "The hash of the capacity block within the cluster.", |
| 163 | + }, |
| 164 | + }, |
| 165 | + }, |
| 166 | + }, |
| 167 | + "health_info": { |
| 168 | + Type: schema.TypeList, |
| 169 | + Computed: true, |
| 170 | + Description: "Health information for the reservation block.", |
| 171 | + Elem: &schema.Resource{ |
| 172 | + Schema: map[string]*schema.Schema{ |
| 173 | + "health_status": { |
| 174 | + Type: schema.TypeString, |
| 175 | + Computed: true, |
| 176 | + Description: "The health status of the reservation block.", |
| 177 | + }, |
| 178 | + "healthy_sub_block_count": { |
| 179 | + Type: schema.TypeInt, |
| 180 | + Computed: true, |
| 181 | + Description: "The number of subBlocks that are healthy.", |
| 182 | + }, |
| 183 | + "degraded_sub_block_count": { |
| 184 | + Type: schema.TypeInt, |
| 185 | + Computed: true, |
| 186 | + Description: "The number of subBlocks that are degraded.", |
| 187 | + }, |
| 188 | + }, |
| 189 | + }, |
| 190 | + }, |
| 191 | + }, |
| 192 | + } |
| 193 | +} |
| 194 | + |
| 195 | +func dataSourceGoogleComputeReservationBlockRead(d *schema.ResourceData, meta interface{}) error { |
| 196 | + config := meta.(*transport_tpg.Config) |
| 197 | + userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) |
| 198 | + if err != nil { |
| 199 | + return err |
| 200 | + } |
| 201 | + |
| 202 | + project, err := tpgresource.GetProject(d, config) |
| 203 | + if err != nil { |
| 204 | + return err |
| 205 | + } |
| 206 | + |
| 207 | + zone, err := tpgresource.GetZone(d, config) |
| 208 | + if err != nil { |
| 209 | + return err |
| 210 | + } |
| 211 | + |
| 212 | + name := d.Get("name").(string) |
| 213 | + reservation := d.Get("reservation").(string) |
| 214 | + |
| 215 | + url := fmt.Sprintf("https://compute.googleapis.com/compute/v1/projects/%s/zones/%s/reservations/%s/reservationBlocks/%s", project, zone, reservation, name) |
| 216 | + |
| 217 | + res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ |
| 218 | + Config: config, |
| 219 | + Method: "GET", |
| 220 | + Project: project, |
| 221 | + RawURL: url, |
| 222 | + UserAgent: userAgent, |
| 223 | + }) |
| 224 | + if err != nil { |
| 225 | + return fmt.Errorf("Error reading ReservationBlock: %s", err) |
| 226 | + } |
| 227 | + |
| 228 | + if res == nil { |
| 229 | + return fmt.Errorf("ReservationBlock %s not found", name) |
| 230 | + } |
| 231 | + |
| 232 | + // Flatten the resource field if it exists |
| 233 | + if resource, ok := res["resource"]; ok { |
| 234 | + if resourceMap, ok := resource.(map[string]interface{}); ok { |
| 235 | + res = resourceMap |
| 236 | + } |
| 237 | + } |
| 238 | + |
| 239 | + if err := d.Set("project", project); err != nil { |
| 240 | + return fmt.Errorf("Error setting project: %s", err) |
| 241 | + } |
| 242 | + |
| 243 | + if err := d.Set("kind", res["kind"]); err != nil { |
| 244 | + return fmt.Errorf("Error setting kind: %s", err) |
| 245 | + } |
| 246 | + |
| 247 | + if err := d.Set("resource_id", res["id"]); err != nil { |
| 248 | + return fmt.Errorf("Error setting resource_id: %s", err) |
| 249 | + } |
| 250 | + |
| 251 | + if err := d.Set("creation_timestamp", res["creationTimestamp"]); err != nil { |
| 252 | + return fmt.Errorf("Error setting creation_timestamp: %s", err) |
| 253 | + } |
| 254 | + |
| 255 | + if err := d.Set("self_link", res["selfLink"]); err != nil { |
| 256 | + return fmt.Errorf("Error setting self_link: %s", err) |
| 257 | + } |
| 258 | + |
| 259 | + if err := d.Set("self_link_with_id", res["selfLinkWithId"]); err != nil { |
| 260 | + return fmt.Errorf("Error setting self_link_with_id: %s", err) |
| 261 | + } |
| 262 | + |
| 263 | + if err := d.Set("block_count", res["count"]); err != nil { |
| 264 | + return fmt.Errorf("Error setting count: %s", err) |
| 265 | + } |
| 266 | + |
| 267 | + if err := d.Set("in_use_count", res["inUseCount"]); err != nil { |
| 268 | + return fmt.Errorf("Error setting in_use_count: %s", err) |
| 269 | + } |
| 270 | + |
| 271 | + if err := d.Set("status", res["status"]); err != nil { |
| 272 | + return fmt.Errorf("Error setting status: %s", err) |
| 273 | + } |
| 274 | + |
| 275 | + if err := d.Set("reservation_sub_block_count", res["reservationSubBlockCount"]); err != nil { |
| 276 | + return fmt.Errorf("Error setting reservation_sub_block_count: %s", err) |
| 277 | + } |
| 278 | + |
| 279 | + if err := d.Set("reservation_sub_block_in_use_count", res["reservationSubBlockInUseCount"]); err != nil { |
| 280 | + return fmt.Errorf("Error setting reservation_sub_block_in_use_count: %s", err) |
| 281 | + } |
| 282 | + |
| 283 | + if reservationMaintenance, ok := res["reservationMaintenance"].(map[string]interface{}); ok { |
| 284 | + maintenanceList := []map[string]interface{}{ |
| 285 | + { |
| 286 | + "maintenance_ongoing_count": reservationMaintenance["maintenanceOngoingCount"], |
| 287 | + "maintenance_pending_count": reservationMaintenance["maintenancePendingCount"], |
| 288 | + "scheduling_type": reservationMaintenance["schedulingType"], |
| 289 | + "subblock_infra_maintenance_ongoing_count": reservationMaintenance["subblockInfraMaintenanceOngoingCount"], |
| 290 | + "subblock_infra_maintenance_pending_count": reservationMaintenance["subblockInfraMaintenancePendingCount"], |
| 291 | + "instance_maintenance_ongoing_count": reservationMaintenance["instanceMaintenanceOngoingCount"], |
| 292 | + "instance_maintenance_pending_count": reservationMaintenance["instanceMaintenancePendingCount"], |
| 293 | + }, |
| 294 | + } |
| 295 | + if err := d.Set("reservation_maintenance", maintenanceList); err != nil { |
| 296 | + return fmt.Errorf("Error setting reservation_maintenance: %s", err) |
| 297 | + } |
| 298 | + } |
| 299 | + |
| 300 | + if physicalTopology, ok := res["physicalTopology"].(map[string]interface{}); ok { |
| 301 | + topologyList := []map[string]interface{}{ |
| 302 | + { |
| 303 | + "cluster": physicalTopology["cluster"], |
| 304 | + "block": physicalTopology["block"], |
| 305 | + }, |
| 306 | + } |
| 307 | + if err := d.Set("physical_topology", topologyList); err != nil { |
| 308 | + return fmt.Errorf("Error setting physical_topology: %s", err) |
| 309 | + } |
| 310 | + } |
| 311 | + |
| 312 | + if healthInfo, ok := res["healthInfo"].(map[string]interface{}); ok { |
| 313 | + healthList := []map[string]interface{}{ |
| 314 | + { |
| 315 | + "health_status": healthInfo["healthStatus"], |
| 316 | + "healthy_sub_block_count": healthInfo["healthySubBlockCount"], |
| 317 | + "degraded_sub_block_count": healthInfo["degradedSubBlockCount"], |
| 318 | + }, |
| 319 | + } |
| 320 | + if err := d.Set("health_info", healthList); err != nil { |
| 321 | + return fmt.Errorf("Error setting health_info: %s", err) |
| 322 | + } |
| 323 | + } |
| 324 | + |
| 325 | + d.SetId(fmt.Sprintf("projects/%s/zones/%s/reservations/%s/reservationBlocks/%s", project, zone, reservation, name)) |
| 326 | + return nil |
| 327 | +} |
0 commit comments