|
| 1 | +// Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved. |
| 2 | +// Licensed under the Mozilla Public License v2.0 |
| 3 | + |
| 4 | +package apm_synthetics |
| 5 | + |
| 6 | +import ( |
| 7 | + "context" |
| 8 | + |
| 9 | + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" |
| 10 | + oci_apm_synthetics "github.com/oracle/oci-go-sdk/v55/apmsynthetics" |
| 11 | +) |
| 12 | + |
| 13 | +func ApmSyntheticsDedicatedVantagePointDataSource() *schema.Resource { |
| 14 | + fieldMap := make(map[string]*schema.Schema) |
| 15 | + fieldMap["apm_domain_id"] = &schema.Schema{ |
| 16 | + Type: schema.TypeString, |
| 17 | + Required: true, |
| 18 | + } |
| 19 | + fieldMap["dedicated_vantage_point_id"] = &schema.Schema{ |
| 20 | + Type: schema.TypeString, |
| 21 | + Required: true, |
| 22 | + } |
| 23 | + return tfresource.GetSingularDataSourceItemSchema(ApmSyntheticsDedicatedVantagePointResource(), fieldMap, readSingularApmSyntheticsDedicatedVantagePoint) |
| 24 | +} |
| 25 | + |
| 26 | +func readSingularApmSyntheticsDedicatedVantagePoint(d *schema.ResourceData, m interface{}) error { |
| 27 | + sync := &ApmSyntheticsDedicatedVantagePointDataSourceCrud{} |
| 28 | + sync.D = d |
| 29 | + sync.Client = m.(*client.OracleClients).ApmSyntheticClient() |
| 30 | + |
| 31 | + return tfresource.ReadResource(sync) |
| 32 | +} |
| 33 | + |
| 34 | +type ApmSyntheticsDedicatedVantagePointDataSourceCrud struct { |
| 35 | + D *schema.ResourceData |
| 36 | + Client *oci_apm_synthetics.ApmSyntheticClient |
| 37 | + Res *oci_apm_synthetics.GetDedicatedVantagePointResponse |
| 38 | +} |
| 39 | + |
| 40 | +func (s *ApmSyntheticsDedicatedVantagePointDataSourceCrud) VoidState() { |
| 41 | + s.D.SetId("") |
| 42 | +} |
| 43 | + |
| 44 | +func (s *ApmSyntheticsDedicatedVantagePointDataSourceCrud) Get() error { |
| 45 | + request := oci_apm_synthetics.GetDedicatedVantagePointRequest{} |
| 46 | + |
| 47 | + if apmDomainId, ok := s.D.GetOkExists("apm_domain_id"); ok { |
| 48 | + tmp := apmDomainId.(string) |
| 49 | + request.ApmDomainId = &tmp |
| 50 | + } |
| 51 | + |
| 52 | + if dedicatedVantagePointId, ok := s.D.GetOkExists("dedicated_vantage_point_id"); ok { |
| 53 | + tmp := dedicatedVantagePointId.(string) |
| 54 | + request.DedicatedVantagePointId = &tmp |
| 55 | + } |
| 56 | + |
| 57 | + request.RequestMetadata.RetryPolicy = tfresource.GetRetryPolicy(false, "apm_synthetics") |
| 58 | + |
| 59 | + response, err := s.Client.GetDedicatedVantagePoint(context.Background(), request) |
| 60 | + if err != nil { |
| 61 | + return err |
| 62 | + } |
| 63 | + |
| 64 | + s.Res = &response |
| 65 | + return nil |
| 66 | +} |
| 67 | + |
| 68 | +func (s *ApmSyntheticsDedicatedVantagePointDataSourceCrud) SetData() error { |
| 69 | + if s.Res == nil { |
| 70 | + return nil |
| 71 | + } |
| 72 | + |
| 73 | + s.D.SetId(*s.Res.Id) |
| 74 | + |
| 75 | + if s.Res.DefinedTags != nil { |
| 76 | + s.D.Set("defined_tags", definedTagsToMap(s.Res.DefinedTags)) |
| 77 | + } |
| 78 | + |
| 79 | + if s.Res.DisplayName != nil { |
| 80 | + s.D.Set("display_name", *s.Res.DisplayName) |
| 81 | + } |
| 82 | + |
| 83 | + if s.Res.DvpStackDetails != nil { |
| 84 | + dvpStackDetailsArray := []interface{}{} |
| 85 | + if dvpStackDetailsMap := DvpStackDetailsToMap(&s.Res.DvpStackDetails); dvpStackDetailsMap != nil { |
| 86 | + dvpStackDetailsArray = append(dvpStackDetailsArray, dvpStackDetailsMap) |
| 87 | + } |
| 88 | + s.D.Set("dvp_stack_details", dvpStackDetailsArray) |
| 89 | + } else { |
| 90 | + s.D.Set("dvp_stack_details", nil) |
| 91 | + } |
| 92 | + |
| 93 | + s.D.Set("freeform_tags", s.Res.FreeformTags) |
| 94 | + |
| 95 | + if s.Res.MonitorStatusCountMap != nil { |
| 96 | + s.D.Set("monitor_status_count_map", []interface{}{MonitorStatusCountMapToMap(s.Res.MonitorStatusCountMap)}) |
| 97 | + } else { |
| 98 | + s.D.Set("monitor_status_count_map", nil) |
| 99 | + } |
| 100 | + |
| 101 | + if s.Res.Name != nil { |
| 102 | + s.D.Set("name", *s.Res.Name) |
| 103 | + } |
| 104 | + |
| 105 | + if s.Res.Region != nil { |
| 106 | + s.D.Set("region", *s.Res.Region) |
| 107 | + } |
| 108 | + |
| 109 | + s.D.Set("status", s.Res.Status) |
| 110 | + |
| 111 | + if s.Res.TimeCreated != nil { |
| 112 | + s.D.Set("time_created", s.Res.TimeCreated.String()) |
| 113 | + } |
| 114 | + |
| 115 | + if s.Res.TimeUpdated != nil { |
| 116 | + s.D.Set("time_updated", s.Res.TimeUpdated.String()) |
| 117 | + } |
| 118 | + |
| 119 | + return nil |
| 120 | +} |
0 commit comments