-
Notifications
You must be signed in to change notification settings - Fork 650
/
data_source_ibm_dl_export_route_filter.go
107 lines (102 loc) · 3.32 KB
/
data_source_ibm_dl_export_route_filter.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
// Copyright IBM Corp. 2022 All Rights Reserved.
// Licensed under the Mozilla Public License v2.0
package directlink
import (
"fmt"
"log"
"github.com/IBM/networking-go-sdk/directlinkv1"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func DataSourceIBMDLExportRouteFilter() *schema.Resource {
return &schema.Resource{
Read: dataSourceIBMDLExportRouteFilterRead,
Schema: map[string]*schema.Schema{
dlGatewayId: {
Type: schema.TypeString,
Required: true,
Description: "The Direct Link gateway identifier",
},
dlExportRouteFilterId: {
Type: schema.TypeString,
Required: true,
Description: "Export route Filter identifier",
},
dlAction: {
Type: schema.TypeString,
Computed: true,
Description: "Determines whether the routes that match the prefix-set will be permit or deny",
},
dlBefore: {
Type: schema.TypeString,
Computed: true,
Description: "Identifier of the next route filter to be considered",
},
dlCreatedAt: {
Type: schema.TypeString,
Computed: true,
Description: "The date and time of the export route filter was created",
},
dlGe: {
Type: schema.TypeInt,
Computed: true,
Description: "The minimum matching length of the prefix-set",
},
dlLe: {
Type: schema.TypeInt,
Computed: true,
Description: "The maximum matching length of the prefix-set",
},
dlPrefix: {
Type: schema.TypeString,
Computed: true,
Description: "IP prefix representing an address and mask length of the prefix-set",
},
dlUpdatedAt: {
Type: schema.TypeString,
Computed: true,
Description: "The date and time of the export route filter was last updated",
},
},
}
}
func dataSourceIBMDLExportRouteFilterRead(d *schema.ResourceData, meta interface{}) error {
directLink, err := directlinkClient(meta)
if err != nil {
return err
}
gatewayId := d.Get(dlGatewayId).(string)
exportRouteFilterId := d.Get(dlExportRouteFilterId).(string)
getGatewayExportRouteFilterOptionsModel := &directlinkv1.GetGatewayExportRouteFilterOptions{GatewayID: &gatewayId, ID: &exportRouteFilterId}
exportRouteFilter, response, err := directLink.GetGatewayExportRouteFilter(getGatewayExportRouteFilterOptionsModel)
if err != nil {
log.Println("[ERROR] Error while listing the DL Export Route Filter", response, err)
return err
}
if exportRouteFilter == nil {
return fmt.Errorf("error while reading the Export Route filter for gateway: %s and Export route FilterId: %s with response code: %d", gatewayId, exportRouteFilterId, response.StatusCode)
} else if exportRouteFilter.ID != nil {
d.SetId(*exportRouteFilter.ID)
}
if exportRouteFilter.Action != nil {
d.Set(dlAction, *exportRouteFilter.Action)
}
if exportRouteFilter.Before != nil {
d.Set(dlBefore, *exportRouteFilter.Before)
}
if exportRouteFilter.CreatedAt != nil {
d.Set(dlCreatedAt, exportRouteFilter.CreatedAt.String())
}
if exportRouteFilter.Prefix != nil {
d.Set(dlPrefix, *exportRouteFilter.Prefix)
}
if exportRouteFilter.UpdatedAt != nil {
d.Set(dlUpdatedAt, exportRouteFilter.UpdatedAt.String())
}
if exportRouteFilter.Ge != nil {
d.Set(dlGe, *exportRouteFilter.Ge)
}
if exportRouteFilter.Le != nil {
d.Set(dlLe, *exportRouteFilter.Le)
}
return nil
}