|
| 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_database "github.com/oracle/oci-go-sdk/database" |
| 11 | +) |
| 12 | + |
| 13 | +func init() { |
| 14 | + RegisterDatasource("oci_database_autonomous_patch", DatabaseAutonomousPatchDataSource()) |
| 15 | +} |
| 16 | + |
| 17 | +func DatabaseAutonomousPatchDataSource() *schema.Resource { |
| 18 | + return &schema.Resource{ |
| 19 | + Read: readSingularDatabaseAutonomousPatch, |
| 20 | + Schema: map[string]*schema.Schema{ |
| 21 | + "autonomous_patch_id": { |
| 22 | + Type: schema.TypeString, |
| 23 | + Required: true, |
| 24 | + }, |
| 25 | + // Computed |
| 26 | + "description": { |
| 27 | + Type: schema.TypeString, |
| 28 | + Computed: true, |
| 29 | + }, |
| 30 | + "lifecycle_details": { |
| 31 | + Type: schema.TypeString, |
| 32 | + Computed: true, |
| 33 | + }, |
| 34 | + "patch_model": { |
| 35 | + Type: schema.TypeString, |
| 36 | + Computed: true, |
| 37 | + }, |
| 38 | + "quarter": { |
| 39 | + Type: schema.TypeString, |
| 40 | + Computed: true, |
| 41 | + }, |
| 42 | + "state": { |
| 43 | + Type: schema.TypeString, |
| 44 | + Computed: true, |
| 45 | + }, |
| 46 | + "time_released": { |
| 47 | + Type: schema.TypeString, |
| 48 | + Computed: true, |
| 49 | + }, |
| 50 | + "type": { |
| 51 | + Type: schema.TypeString, |
| 52 | + Computed: true, |
| 53 | + }, |
| 54 | + "version": { |
| 55 | + Type: schema.TypeString, |
| 56 | + Computed: true, |
| 57 | + }, |
| 58 | + "year": { |
| 59 | + Type: schema.TypeString, |
| 60 | + Computed: true, |
| 61 | + }, |
| 62 | + }, |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +func readSingularDatabaseAutonomousPatch(d *schema.ResourceData, m interface{}) error { |
| 67 | + sync := &DatabaseAutonomousPatchDataSourceCrud{} |
| 68 | + sync.D = d |
| 69 | + sync.Client = m.(*OracleClients).databaseClient() |
| 70 | + |
| 71 | + return ReadResource(sync) |
| 72 | +} |
| 73 | + |
| 74 | +type DatabaseAutonomousPatchDataSourceCrud struct { |
| 75 | + D *schema.ResourceData |
| 76 | + Client *oci_database.DatabaseClient |
| 77 | + Res *oci_database.GetAutonomousPatchResponse |
| 78 | +} |
| 79 | + |
| 80 | +func (s *DatabaseAutonomousPatchDataSourceCrud) VoidState() { |
| 81 | + s.D.SetId("") |
| 82 | +} |
| 83 | + |
| 84 | +func (s *DatabaseAutonomousPatchDataSourceCrud) Get() error { |
| 85 | + request := oci_database.GetAutonomousPatchRequest{} |
| 86 | + |
| 87 | + if autonomousPatchId, ok := s.D.GetOkExists("autonomous_patch_id"); ok { |
| 88 | + tmp := autonomousPatchId.(string) |
| 89 | + request.AutonomousPatchId = &tmp |
| 90 | + } |
| 91 | + |
| 92 | + request.RequestMetadata.RetryPolicy = getRetryPolicy(false, "database") |
| 93 | + |
| 94 | + response, err := s.Client.GetAutonomousPatch(context.Background(), request) |
| 95 | + if err != nil { |
| 96 | + return err |
| 97 | + } |
| 98 | + |
| 99 | + s.Res = &response |
| 100 | + return nil |
| 101 | +} |
| 102 | + |
| 103 | +func (s *DatabaseAutonomousPatchDataSourceCrud) SetData() error { |
| 104 | + if s.Res == nil { |
| 105 | + return nil |
| 106 | + } |
| 107 | + |
| 108 | + s.D.SetId(*s.Res.Id) |
| 109 | + |
| 110 | + if s.Res.Description != nil { |
| 111 | + s.D.Set("description", *s.Res.Description) |
| 112 | + } |
| 113 | + |
| 114 | + if s.Res.LifecycleDetails != nil { |
| 115 | + s.D.Set("lifecycle_details", *s.Res.LifecycleDetails) |
| 116 | + } |
| 117 | + |
| 118 | + s.D.Set("patch_model", s.Res.PatchModel) |
| 119 | + |
| 120 | + if s.Res.Quarter != nil { |
| 121 | + s.D.Set("quarter", *s.Res.Quarter) |
| 122 | + } |
| 123 | + |
| 124 | + s.D.Set("state", s.Res.LifecycleState) |
| 125 | + |
| 126 | + if s.Res.TimeReleased != nil { |
| 127 | + s.D.Set("time_released", s.Res.TimeReleased.String()) |
| 128 | + } |
| 129 | + |
| 130 | + if s.Res.Type != nil { |
| 131 | + s.D.Set("type", *s.Res.Type) |
| 132 | + } |
| 133 | + |
| 134 | + if s.Res.Version != nil { |
| 135 | + s.D.Set("version", *s.Res.Version) |
| 136 | + } |
| 137 | + |
| 138 | + if s.Res.Year != nil { |
| 139 | + s.D.Set("year", *s.Res.Year) |
| 140 | + } |
| 141 | + |
| 142 | + return nil |
| 143 | +} |
0 commit comments