|
| 1 | +// Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved. |
| 2 | + |
| 3 | +package oci |
| 4 | + |
| 5 | +import ( |
| 6 | + "context" |
| 7 | + |
| 8 | + "github.com/hashicorp/terraform/helper/schema" |
| 9 | + oci_analytics "github.com/oracle/oci-go-sdk/analytics" |
| 10 | +) |
| 11 | + |
| 12 | +func AnalyticsAnalyticsInstanceDataSource() *schema.Resource { |
| 13 | + fieldMap := make(map[string]*schema.Schema) |
| 14 | + fieldMap["analytics_instance_id"] = &schema.Schema{ |
| 15 | + Type: schema.TypeString, |
| 16 | + Required: true, |
| 17 | + } |
| 18 | + return GetSingularDataSourceItemSchema(AnalyticsAnalyticsInstanceResource(), fieldMap, readSingularAnalyticsAnalyticsInstance) |
| 19 | +} |
| 20 | + |
| 21 | +func readSingularAnalyticsAnalyticsInstance(d *schema.ResourceData, m interface{}) error { |
| 22 | + sync := &AnalyticsAnalyticsInstanceDataSourceCrud{} |
| 23 | + sync.D = d |
| 24 | + sync.Client = m.(*OracleClients).analyticsClient |
| 25 | + |
| 26 | + return ReadResource(sync) |
| 27 | +} |
| 28 | + |
| 29 | +type AnalyticsAnalyticsInstanceDataSourceCrud struct { |
| 30 | + D *schema.ResourceData |
| 31 | + Client *oci_analytics.AnalyticsClient |
| 32 | + Res *oci_analytics.GetAnalyticsInstanceResponse |
| 33 | +} |
| 34 | + |
| 35 | +func (s *AnalyticsAnalyticsInstanceDataSourceCrud) VoidState() { |
| 36 | + s.D.SetId("") |
| 37 | +} |
| 38 | + |
| 39 | +func (s *AnalyticsAnalyticsInstanceDataSourceCrud) Get() error { |
| 40 | + request := oci_analytics.GetAnalyticsInstanceRequest{} |
| 41 | + |
| 42 | + if analyticsInstanceId, ok := s.D.GetOkExists("analytics_instance_id"); ok { |
| 43 | + tmp := analyticsInstanceId.(string) |
| 44 | + request.AnalyticsInstanceId = &tmp |
| 45 | + } |
| 46 | + |
| 47 | + request.RequestMetadata.RetryPolicy = getRetryPolicy(false, "analytics") |
| 48 | + |
| 49 | + response, err := s.Client.GetAnalyticsInstance(context.Background(), request) |
| 50 | + if err != nil { |
| 51 | + return err |
| 52 | + } |
| 53 | + |
| 54 | + s.Res = &response |
| 55 | + return nil |
| 56 | +} |
| 57 | + |
| 58 | +func (s *AnalyticsAnalyticsInstanceDataSourceCrud) SetData() error { |
| 59 | + if s.Res == nil { |
| 60 | + return nil |
| 61 | + } |
| 62 | + |
| 63 | + s.D.SetId(*s.Res.Id) |
| 64 | + |
| 65 | + if s.Res.Capacity != nil { |
| 66 | + s.D.Set("capacity", []interface{}{AnalyticsCapacityToMap(s.Res.Capacity)}) |
| 67 | + } else { |
| 68 | + s.D.Set("capacity", nil) |
| 69 | + } |
| 70 | + |
| 71 | + if s.Res.CompartmentId != nil { |
| 72 | + s.D.Set("compartment_id", *s.Res.CompartmentId) |
| 73 | + } |
| 74 | + |
| 75 | + if s.Res.DefinedTags != nil { |
| 76 | + s.D.Set("defined_tags", definedTagsToMap(s.Res.DefinedTags)) |
| 77 | + } |
| 78 | + |
| 79 | + if s.Res.Description != nil { |
| 80 | + s.D.Set("description", *s.Res.Description) |
| 81 | + } |
| 82 | + |
| 83 | + if s.Res.EmailNotification != nil { |
| 84 | + s.D.Set("email_notification", *s.Res.EmailNotification) |
| 85 | + } |
| 86 | + |
| 87 | + s.D.Set("feature_set", s.Res.FeatureSet) |
| 88 | + |
| 89 | + s.D.Set("freeform_tags", s.Res.FreeformTags) |
| 90 | + |
| 91 | + s.D.Set("license_type", s.Res.LicenseType) |
| 92 | + |
| 93 | + if s.Res.Name != nil { |
| 94 | + s.D.Set("name", *s.Res.Name) |
| 95 | + } |
| 96 | + |
| 97 | + if s.Res.ServiceUrl != nil { |
| 98 | + s.D.Set("service_url", *s.Res.ServiceUrl) |
| 99 | + } |
| 100 | + |
| 101 | + s.D.Set("state", s.Res.LifecycleState) |
| 102 | + |
| 103 | + if s.Res.TimeCreated != nil { |
| 104 | + s.D.Set("time_created", s.Res.TimeCreated.String()) |
| 105 | + } |
| 106 | + |
| 107 | + if s.Res.TimeUpdated != nil { |
| 108 | + s.D.Set("time_updated", s.Res.TimeUpdated.String()) |
| 109 | + } |
| 110 | + |
| 111 | + return nil |
| 112 | +} |
0 commit comments