-
Notifications
You must be signed in to change notification settings - Fork 649
/
data_source_ibm_is_source_share.go
95 lines (80 loc) · 2.45 KB
/
data_source_ibm_is_source_share.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
// Copyright IBM Corp. 2021 All Rights Reserved.
// Licensed under the Mozilla Public License v2.0
package vpc
import (
"context"
"fmt"
"log"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
"github.com/IBM/vpc-go-sdk/vpcv1"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func DataSourceIbmIsSourceShare() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceIbmIsSourceShareRead,
Schema: map[string]*schema.Schema{
"share_replica": {
Type: schema.TypeString,
Required: true,
Description: "The replica file share identifier.",
},
"crn": {
Type: schema.TypeString,
Computed: true,
Description: "The CRN for this share.",
},
"href": {
Type: schema.TypeString,
Computed: true,
Description: "The URL for this share.",
},
"resource_type": {
Type: schema.TypeString,
Computed: true,
Description: "The type of resource referenced.",
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "Name of the share.",
},
},
}
}
func dataSourceIbmIsSourceShareRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
vpcClient, err := meta.(conns.ClientSession).VpcV1API()
if err != nil {
return diag.FromErr(err)
}
replicaShareId := d.Get("share_replica").(string)
getShareSourceOptions := &vpcv1.GetShareSourceOptions{
ShareID: &replicaShareId,
}
share, response, err := vpcClient.GetShareSourceWithContext(context, getShareSourceOptions)
if err != nil {
if response != nil {
if response.StatusCode == 404 {
d.SetId("")
}
log.Printf("[DEBUG] GetShareWithContext failed %s\n%s", err, response)
return nil
}
log.Printf("[DEBUG] GetShareWithContext failed %s\n", err)
return diag.FromErr(fmt.Errorf("[DEBUG] GetShareWithContext failed %s\n", err))
}
d.SetId(*share.ID)
if err = d.Set("crn", share.CRN); err != nil {
return diag.FromErr(fmt.Errorf("Error setting crn: %s", err))
}
if err = d.Set("href", share.Href); err != nil {
return diag.FromErr(fmt.Errorf("Error setting href: %s", err))
}
if err = d.Set("name", share.Name); err != nil {
return diag.FromErr(fmt.Errorf("Error setting name: %s", err))
}
if err = d.Set("resource_type", share.ResourceType); err != nil {
return diag.FromErr(fmt.Errorf("Error setting resource_type: %s", err))
}
return nil
}