|
| 1 | +// Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved. |
| 2 | +// Licensed under the Mozilla Public License v2.0 |
| 3 | + |
| 4 | +package oci |
| 5 | + |
| 6 | +import ( |
| 7 | + "context" |
| 8 | + |
| 9 | + "github.com/hashicorp/terraform/helper/schema" |
| 10 | + oci_blockchain "github.com/oracle/oci-go-sdk/blockchain" |
| 11 | +) |
| 12 | + |
| 13 | +func init() { |
| 14 | + RegisterDatasource("oci_blockchain_blockchain_platform", BlockchainBlockchainPlatformDataSource()) |
| 15 | +} |
| 16 | + |
| 17 | +func BlockchainBlockchainPlatformDataSource() *schema.Resource { |
| 18 | + fieldMap := make(map[string]*schema.Schema) |
| 19 | + fieldMap["blockchain_platform_id"] = &schema.Schema{ |
| 20 | + Type: schema.TypeString, |
| 21 | + Required: true, |
| 22 | + } |
| 23 | + return GetSingularDataSourceItemSchema(BlockchainBlockchainPlatformResource(), fieldMap, readSingularBlockchainBlockchainPlatform) |
| 24 | +} |
| 25 | + |
| 26 | +func readSingularBlockchainBlockchainPlatform(d *schema.ResourceData, m interface{}) error { |
| 27 | + sync := &BlockchainBlockchainPlatformDataSourceCrud{} |
| 28 | + sync.D = d |
| 29 | + sync.Client = m.(*OracleClients).blockchainPlatformClient() |
| 30 | + |
| 31 | + return ReadResource(sync) |
| 32 | +} |
| 33 | + |
| 34 | +type BlockchainBlockchainPlatformDataSourceCrud struct { |
| 35 | + D *schema.ResourceData |
| 36 | + Client *oci_blockchain.BlockchainPlatformClient |
| 37 | + Res *oci_blockchain.GetBlockchainPlatformResponse |
| 38 | +} |
| 39 | + |
| 40 | +func (s *BlockchainBlockchainPlatformDataSourceCrud) VoidState() { |
| 41 | + s.D.SetId("") |
| 42 | +} |
| 43 | + |
| 44 | +func (s *BlockchainBlockchainPlatformDataSourceCrud) Get() error { |
| 45 | + request := oci_blockchain.GetBlockchainPlatformRequest{} |
| 46 | + |
| 47 | + if blockchainPlatformId, ok := s.D.GetOkExists("blockchain_platform_id"); ok { |
| 48 | + tmp := blockchainPlatformId.(string) |
| 49 | + request.BlockchainPlatformId = &tmp |
| 50 | + } |
| 51 | + |
| 52 | + request.RequestMetadata.RetryPolicy = getRetryPolicy(false, "blockchain") |
| 53 | + |
| 54 | + response, err := s.Client.GetBlockchainPlatform(context.Background(), request) |
| 55 | + if err != nil { |
| 56 | + return err |
| 57 | + } |
| 58 | + |
| 59 | + s.Res = &response |
| 60 | + return nil |
| 61 | +} |
| 62 | + |
| 63 | +func (s *BlockchainBlockchainPlatformDataSourceCrud) SetData() error { |
| 64 | + if s.Res == nil { |
| 65 | + return nil |
| 66 | + } |
| 67 | + |
| 68 | + s.D.SetId(*s.Res.Id) |
| 69 | + |
| 70 | + if s.Res.CompartmentId != nil { |
| 71 | + s.D.Set("compartment_id", *s.Res.CompartmentId) |
| 72 | + } |
| 73 | + |
| 74 | + if s.Res.ComponentDetails != nil { |
| 75 | + s.D.Set("component_details", []interface{}{BlockchainPlatformComponentDetailsToMap(s.Res.ComponentDetails)}) |
| 76 | + } else { |
| 77 | + s.D.Set("component_details", nil) |
| 78 | + } |
| 79 | + |
| 80 | + s.D.Set("compute_shape", s.Res.ComputeShape) |
| 81 | + |
| 82 | + if s.Res.DefinedTags != nil { |
| 83 | + s.D.Set("defined_tags", definedTagsToMap(s.Res.DefinedTags)) |
| 84 | + } |
| 85 | + |
| 86 | + if s.Res.Description != nil { |
| 87 | + s.D.Set("description", *s.Res.Description) |
| 88 | + } |
| 89 | + |
| 90 | + if s.Res.DisplayName != nil { |
| 91 | + s.D.Set("display_name", *s.Res.DisplayName) |
| 92 | + } |
| 93 | + |
| 94 | + s.D.Set("freeform_tags", s.Res.FreeformTags) |
| 95 | + |
| 96 | + hostOcpuUtilizationInfo := []interface{}{} |
| 97 | + for _, item := range s.Res.HostOcpuUtilizationInfo { |
| 98 | + hostOcpuUtilizationInfo = append(hostOcpuUtilizationInfo, OcpuUtilizationInfoToMap(item)) |
| 99 | + } |
| 100 | + s.D.Set("host_ocpu_utilization_info", hostOcpuUtilizationInfo) |
| 101 | + |
| 102 | + if s.Res.IsByol != nil { |
| 103 | + s.D.Set("is_byol", *s.Res.IsByol) |
| 104 | + } |
| 105 | + |
| 106 | + if s.Res.IsMultiAD != nil { |
| 107 | + s.D.Set("is_multi_ad", *s.Res.IsMultiAD) |
| 108 | + } |
| 109 | + |
| 110 | + if s.Res.LifecycleDetails != nil { |
| 111 | + s.D.Set("lifecycle_details", *s.Res.LifecycleDetails) |
| 112 | + } |
| 113 | + |
| 114 | + s.D.Set("platform_role", s.Res.PlatformRole) |
| 115 | + |
| 116 | + if s.Res.Replicas != nil { |
| 117 | + s.D.Set("replicas", []interface{}{ReplicaDetailsToMap(s.Res.Replicas)}) |
| 118 | + } else { |
| 119 | + s.D.Set("replicas", nil) |
| 120 | + } |
| 121 | + |
| 122 | + if s.Res.ServiceEndpoint != nil { |
| 123 | + s.D.Set("service_endpoint", *s.Res.ServiceEndpoint) |
| 124 | + } |
| 125 | + |
| 126 | + if s.Res.ServiceVersion != nil { |
| 127 | + s.D.Set("service_version", *s.Res.ServiceVersion) |
| 128 | + } |
| 129 | + |
| 130 | + s.D.Set("state", s.Res.LifecycleState) |
| 131 | + |
| 132 | + if s.Res.StorageSizeInTBs != nil { |
| 133 | + s.D.Set("storage_size_in_tbs", *s.Res.StorageSizeInTBs) |
| 134 | + } |
| 135 | + |
| 136 | + if s.Res.StorageUsedInTBs != nil { |
| 137 | + s.D.Set("storage_used_in_tbs", *s.Res.StorageUsedInTBs) |
| 138 | + } |
| 139 | + |
| 140 | + if s.Res.TimeCreated != nil { |
| 141 | + s.D.Set("time_created", s.Res.TimeCreated.String()) |
| 142 | + } |
| 143 | + |
| 144 | + if s.Res.TimeUpdated != nil { |
| 145 | + s.D.Set("time_updated", s.Res.TimeUpdated.String()) |
| 146 | + } |
| 147 | + |
| 148 | + if s.Res.TotalOcpuCapacity != nil { |
| 149 | + s.D.Set("total_ocpu_capacity", *s.Res.TotalOcpuCapacity) |
| 150 | + } |
| 151 | + |
| 152 | + return nil |
| 153 | +} |
0 commit comments