/
data_source_ibm_is_virtual_network_interface_floating_ip.go
95 lines (85 loc) · 2.98 KB
/
data_source_ibm_is_virtual_network_interface_floating_ip.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. 2023 All Rights Reserved.
// Licensed under the Mozilla Public License v2.0
package vpc
import (
"context"
"fmt"
"log"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/IBM/vpc-go-sdk/vpcv1"
)
func DataSourceIBMIsVirtualNetworkInterfaceFloatingIP() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceIBMIsVirtualNetworkInterfaceFloatingIPRead,
Schema: map[string]*schema.Schema{
"virtual_network_interface": &schema.Schema{
Type: schema.TypeString,
Required: true,
Description: "The virtual network interface identifier",
},
"floating_ip": &schema.Schema{
Type: schema.TypeString,
Required: true,
Description: "The floating IP identifier",
},
"name": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The name for this floating IP. The name is unique across all floating IPs in the region.",
},
"deleted": &schema.Schema{
Type: schema.TypeList,
Optional: true,
Description: "If present, this property indicates the referenced resource has been deleted, and provides some supplementary information.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"more_info": &schema.Schema{
Type: schema.TypeString,
Required: true,
Description: "Link to documentation about deleted resources",
},
},
},
},
"address": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The globally unique IP address.",
},
"crn": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The CRN for this floating IP.",
},
"href": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The URL for this floating IP.",
},
},
}
}
func dataSourceIBMIsVirtualNetworkInterfaceFloatingIPRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
sess, err := vpcClient(meta)
if err != nil {
return diag.FromErr(err)
}
vniId := d.Get("virtual_network_interface").(string)
fipId := d.Get("floating_ip").(string)
getNetworkInterfaceFloatingIPOptions := &vpcv1.GetNetworkInterfaceFloatingIPOptions{}
getNetworkInterfaceFloatingIPOptions.SetVirtualNetworkInterfaceID(vniId)
getNetworkInterfaceFloatingIPOptions.SetID(fipId)
floatingIP, response, err := sess.GetNetworkInterfaceFloatingIPWithContext(context, getNetworkInterfaceFloatingIPOptions)
if err != nil {
if response != nil && response.StatusCode == 404 {
d.SetId("")
return nil
}
log.Printf("[DEBUG] GetVirtualNetworkInterfaceFloatingIPWithContext failed %s\n%s", err, response)
return diag.FromErr(fmt.Errorf("GetVirtualNetworkInterfaceFloatingIPWithContext failed %s\n%s", err, response))
}
d.SetId(*floatingIP.ID)
resourceIBMIsVirtualNetworkInterfaceFloatingIPGet(d, floatingIP)
return nil
}