-
Notifications
You must be signed in to change notification settings - Fork 117
/
datasource_bigip_ssl_certificate.go
63 lines (53 loc) · 1.65 KB
/
datasource_bigip_ssl_certificate.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
/*
Copyright 2019 F5 Networks Inc.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package bigip
import (
"context"
"fmt"
"log"
bigip "github.com/f5devcentral/go-bigip"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceBigipSslCertificate() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceBigipSslCertificateRead,
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
Description: "Name of the certificate",
},
"partition": {
Type: schema.TypeString,
Required: true,
Description: "partition of resource group",
},
"certificate": {
Type: schema.TypeString,
Computed: true,
Description: "The certificate body",
},
},
}
}
func dataSourceBigipSslCertificateRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(*bigip.BigIP)
d.SetId("")
name := fmt.Sprintf("/%s/%s", d.Get("partition").(string), d.Get("name").(string))
log.Println("[INFO] Reading Certificate : " + name)
certificate, err := client.GetCertificate(name)
if err != nil {
return diag.FromErr(fmt.Errorf("error retrieving certificate %s: %v", name, err))
}
if certificate == nil {
return diag.FromErr(fmt.Errorf("certificate (%s) not found", name))
}
_ = d.Set("name", certificate.Name)
_ = d.Set("partition", certificate.Partition)
d.SetId(certificate.FullPath)
return nil
}