-
Notifications
You must be signed in to change notification settings - Fork 654
/
data_source_ibm_certificate_manager_certificates.go
137 lines (132 loc) · 3.66 KB
/
data_source_ibm_certificate_manager_certificates.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// Copyright IBM Corp. 2017, 2021 All Rights Reserved.
// Licensed under the Mozilla Public License v2.0
package certificatemanager
import (
"strconv"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func DataIBMCertificateManagerCertificates() *schema.Resource {
return &schema.Resource{
Read: dataIBMCertificateManagerCertificatesRead,
Schema: map[string]*schema.Schema{
"certificate_manager_instance_id": {
Type: schema.TypeString,
Description: "Certificate Manager Instance ID",
Required: true,
},
"certificates": {
Type: schema.TypeList,
Computed: true,
Description: "List of certificates",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cert_id": {
Type: schema.TypeString,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"domains": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"issuer": {
Type: schema.TypeString,
Computed: true,
},
"begins_on": {
Type: schema.TypeInt,
Computed: true,
},
"expires_on": {
Type: schema.TypeInt,
Computed: true,
},
"algorithm": {
Type: schema.TypeString,
Computed: true,
},
"key_algorithm": {
Type: schema.TypeString,
Computed: true,
},
"serial_number": {
Type: schema.TypeString,
Computed: true,
},
"imported": {
Type: schema.TypeBool,
Computed: true,
},
"has_previous": {
Type: schema.TypeBool,
Computed: true,
},
"issuance_info": {
Type: schema.TypeMap,
Computed: true,
},
},
},
},
},
}
}
func dataIBMCertificateManagerCertificatesRead(d *schema.ResourceData, meta interface{}) error {
cmService, err := meta.(conns.ClientSession).CertificateManagerAPI()
if err != nil {
return err
}
instanceID := d.Get("certificate_manager_instance_id").(string)
result, err := cmService.Certificate().ListCertificates(instanceID)
if err != nil {
return err
}
record := make([]map[string]interface{}, len(result))
for i, c := range result {
certificate := make(map[string]interface{})
certificate["cert_id"] = c.ID
certificate["name"] = c.Name
certificate["domains"] = c.Domains
certificate["status"] = c.Status
certificate["issuer"] = c.Issuer
certificate["begins_on"] = c.BeginsOn
certificate["expires_on"] = c.ExpiresOn
certificate["algorithm"] = c.Algorithm
certificate["key_algorithm"] = c.KeyAlgorithm
certificate["serial_number"] = c.SerialNumber
certificate["imported"] = c.Imported
certificate["has_previous"] = c.HasPrevious
if c.IssuanceInfo != nil {
issuanceinfo := make(map[string]interface{})
if c.IssuanceInfo.Status != "" {
issuanceinfo["status"] = c.IssuanceInfo.Status
}
if c.IssuanceInfo.Code != "" {
issuanceinfo["code"] = c.IssuanceInfo.Code
}
if c.IssuanceInfo.AdditionalInfo != "" {
issuanceinfo["additional_info"] = c.IssuanceInfo.AdditionalInfo
}
if c.IssuanceInfo.OrderedOn != 0 {
order := c.IssuanceInfo.OrderedOn
orderedOn := strconv.FormatInt(order, 10)
issuanceinfo["ordered_on"] = orderedOn
}
certificate["issuance_info"] = issuanceinfo
}
record[i] = certificate
}
d.SetId(instanceID)
d.Set("certificate_manager_instance_id", instanceID)
d.Set("certificates", record)
return nil
}