-
Notifications
You must be signed in to change notification settings - Fork 658
/
data_source_ibm_dl_import_route_filter.go
109 lines (104 loc) · 3.36 KB
/
data_source_ibm_dl_import_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
108
109
// Copyright IBM Corp. 2023 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 DataSourceIBMDLImportRouteFilter() *schema.Resource {
return &schema.Resource{
Read: dataSourceIBMDLImportRouteFilterRead,
Schema: map[string]*schema.Schema{
dlGatewayId: {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "The Direct Link gateway identifier",
},
dlImportRouteFilterId: {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "Import 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 import 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 import route filter was last updated",
},
},
}
}
func dataSourceIBMDLImportRouteFilterRead(d *schema.ResourceData, meta interface{}) error {
directLink, err := directlinkClient(meta)
if err != nil {
return err
}
gatewayId := d.Get(dlGatewayId).(string)
importRouteFilterId := d.Get(dlImportRouteFilterId).(string)
getGatewayImportRouteFilterOptionsModel := &directlinkv1.GetGatewayImportRouteFilterOptions{GatewayID: &gatewayId, ID: &importRouteFilterId}
importRouteFilter, response, err := directLink.GetGatewayImportRouteFilter(getGatewayImportRouteFilterOptionsModel)
if err != nil {
log.Println("[ERROR] Error while listing Direct Link Import Route Filter", response, err)
return err
}
if importRouteFilter == nil {
return fmt.Errorf("error fetching the Import route Filter for gateway: %s and Import Route FilterId: %s with response code: %d", gatewayId, importRouteFilterId, response.StatusCode)
} else if importRouteFilter.ID != nil {
d.SetId(*importRouteFilter.ID)
}
if importRouteFilter.Action != nil {
d.Set(dlAction, *importRouteFilter.Action)
}
if importRouteFilter.Before != nil {
d.Set(dlBefore, *importRouteFilter.Before)
}
if importRouteFilter.CreatedAt != nil {
d.Set(dlCreatedAt, importRouteFilter.CreatedAt.String())
}
if importRouteFilter.Prefix != nil {
d.Set(dlPrefix, *importRouteFilter.Prefix)
}
if importRouteFilter.UpdatedAt != nil {
d.Set(dlUpdatedAt, importRouteFilter.UpdatedAt.String())
}
if importRouteFilter.Ge != nil {
d.Set(dlGe, *importRouteFilter.Ge)
}
if importRouteFilter.Le != nil {
d.Set(dlLe, *importRouteFilter.Le)
}
return nil
}