• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Twingate / terraform-provider-twingate / 13158192914

05 Feb 2025 01:14PM UTC coverage: 85.195% (-0.05%) from 85.24%
13158192914

Pull #636

github

web-flow
Bump golang.org/x/sync from 0.10.0 to 0.11.0

Bumps [golang.org/x/sync](https://github.com/golang/sync) from 0.10.0 to 0.11.0.
- [Commits](https://github.com/golang/sync/compare/v0.10.0...v0.11.0)

---
updated-dependencies:
- dependency-name: golang.org/x/sync
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #636: Bump golang.org/x/sync from 0.10.0 to 0.11.0

7573 of 8889 relevant lines covered (85.2%)

2.25 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.92
/twingate/internal/provider/datasource/connectors.go
1
package datasource
2

3
import (
4
        "context"
5
        "errors"
6
        "fmt"
7

8
        "github.com/Twingate/terraform-provider-twingate/v3/twingate/internal/attr"
9
        "github.com/Twingate/terraform-provider-twingate/v3/twingate/internal/client"
10
        "github.com/hashicorp/terraform-plugin-framework/datasource"
11
        "github.com/hashicorp/terraform-plugin-framework/datasource/schema"
12
        "github.com/hashicorp/terraform-plugin-framework/types"
13
)
14

15
var ErrConnectorsDatasourceShouldSetOneOptionalNameAttribute = errors.New("Only one of name, name_regex, name_contains, name_exclude, name_prefix or name_suffix must be set.")
16

17
// Ensure the implementation satisfies the desired interfaces.
18
var _ datasource.DataSource = &connectors{}
19

20
func NewConnectorsDatasource() datasource.DataSource {
2✔
21
        return &connectors{}
2✔
22
}
2✔
23

24
type connectors struct {
25
        client *client.Client
26
}
27

28
type connectorsModel struct {
29
        ID           types.String     `tfsdk:"id"`
30
        Name         types.String     `tfsdk:"name"`
31
        NameRegexp   types.String     `tfsdk:"name_regexp"`
32
        NameContains types.String     `tfsdk:"name_contains"`
33
        NameExclude  types.String     `tfsdk:"name_exclude"`
34
        NamePrefix   types.String     `tfsdk:"name_prefix"`
35
        NameSuffix   types.String     `tfsdk:"name_suffix"`
36
        Connectors   []connectorModel `tfsdk:"connectors"`
37
}
38

39
func (d *connectors) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
2✔
40
        resp.TypeName = TwingateConnectors
2✔
41
}
2✔
42

43
func (d *connectors) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
2✔
44
        if req.ProviderData == nil {
4✔
45
                return
2✔
46
        }
2✔
47

48
        client, ok := req.ProviderData.(*client.Client)
2✔
49
        if !ok {
2✔
50
                resp.Diagnostics.AddError(
×
51
                        "Unexpected Data Source Configure Type",
×
52
                        fmt.Sprintf("Expected *client.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData),
×
53
                )
×
54

×
55
                return
×
56
        }
×
57

58
        d.client = client
2✔
59
}
60

61
//nolint:funlen
62
func (d *connectors) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
2✔
63
        resp.Schema = schema.Schema{
2✔
64
                Description: "Connectors provide connectivity to Remote Networks. For more information, see Twingate's [documentation](https://docs.twingate.com/docs/understanding-access-nodes).",
2✔
65
                Attributes: map[string]schema.Attribute{
2✔
66
                        attr.ID: schema.StringAttribute{
2✔
67
                                Computed:    true,
2✔
68
                                Description: computedDatasourceIDDescription,
2✔
69
                        },
2✔
70

2✔
71
                        attr.Name: schema.StringAttribute{
2✔
72
                                Optional:    true,
2✔
73
                                Description: "Returns only connectors that exactly match this name. If no options are passed it will return all connectors. Only one option can be used at a time.",
2✔
74
                        },
2✔
75
                        attr.Name + attr.FilterByRegexp: schema.StringAttribute{
2✔
76
                                Optional:    true,
2✔
77
                                Description: "The regular expression match of the name of the connector.",
2✔
78
                        },
2✔
79
                        attr.Name + attr.FilterByContains: schema.StringAttribute{
2✔
80
                                Optional:    true,
2✔
81
                                Description: "Match when the value exist in the name of the connector.",
2✔
82
                        },
2✔
83
                        attr.Name + attr.FilterByExclude: schema.StringAttribute{
2✔
84
                                Optional:    true,
2✔
85
                                Description: "Match when the exact value does not exist in the name of the connector.",
2✔
86
                        },
2✔
87
                        attr.Name + attr.FilterByPrefix: schema.StringAttribute{
2✔
88
                                Optional:    true,
2✔
89
                                Description: "The name of the connector must start with the value.",
2✔
90
                        },
2✔
91
                        attr.Name + attr.FilterBySuffix: schema.StringAttribute{
2✔
92
                                Optional:    true,
2✔
93
                                Description: "The name of the connector must end with the value.",
2✔
94
                        },
2✔
95

2✔
96
                        // computed
2✔
97
                        attr.Connectors: schema.ListNestedAttribute{
2✔
98
                                Computed:    true,
2✔
99
                                Description: "List of Connectors",
2✔
100
                                NestedObject: schema.NestedAttributeObject{
2✔
101
                                        Attributes: map[string]schema.Attribute{
2✔
102
                                                attr.ID: schema.StringAttribute{
2✔
103
                                                        Computed:    true,
2✔
104
                                                        Description: "The ID of the Connector.",
2✔
105
                                                },
2✔
106
                                                attr.Name: schema.StringAttribute{
2✔
107
                                                        Computed:    true,
2✔
108
                                                        Description: "The Name of the Connector.",
2✔
109
                                                },
2✔
110
                                                attr.RemoteNetworkID: schema.StringAttribute{
2✔
111
                                                        Computed:    true,
2✔
112
                                                        Description: "The ID of the Remote Network attached to the Connector.",
2✔
113
                                                },
2✔
114
                                                attr.StatusUpdatesEnabled: schema.BoolAttribute{
2✔
115
                                                        Computed:    true,
2✔
116
                                                        Description: "Determines whether status notifications are enabled for the Connector.",
2✔
117
                                                },
2✔
118
                                                attr.State: schema.StringAttribute{
2✔
119
                                                        Computed:    true,
2✔
120
                                                        Description: "The Connector's state. One of `ALIVE`, `DEAD_NO_HEARTBEAT`, `DEAD_HEARTBEAT_TOO_OLD` or `DEAD_NO_RELAYS`.",
2✔
121
                                                },
2✔
122
                                                attr.Hostname: schema.StringAttribute{
2✔
123
                                                        Computed:    true,
2✔
124
                                                        Description: "The hostname of the machine hosting the Connector.",
2✔
125
                                                },
2✔
126
                                                attr.Version: schema.StringAttribute{
2✔
127
                                                        Computed:    true,
2✔
128
                                                        Description: "The Connector's version.",
2✔
129
                                                },
2✔
130
                                                attr.PublicIP: schema.StringAttribute{
2✔
131
                                                        Computed:    true,
2✔
132
                                                        Description: "The Connector's public IP address.",
2✔
133
                                                },
2✔
134
                                                attr.PrivateIPs: schema.SetAttribute{
2✔
135
                                                        Computed:    true,
2✔
136
                                                        ElementType: types.StringType,
2✔
137
                                                        Description: "The Connector's private IP addresses.",
2✔
138
                                                },
2✔
139
                                        },
2✔
140
                                },
2✔
141
                        },
2✔
142
                },
2✔
143
        }
2✔
144
}
2✔
145

146
func (d *connectors) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
2✔
147
        var data connectorsModel
2✔
148

2✔
149
        // Read Terraform configuration data into the model
2✔
150
        resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
2✔
151

2✔
152
        if resp.Diagnostics.HasError() {
2✔
153
                return
×
154
        }
×
155

156
        name, filter := getNameFilter(data.Name, data.NameRegexp, data.NameContains, data.NameExclude, data.NamePrefix, data.NameSuffix)
2✔
157

2✔
158
        if countOptionalAttributes(data.Name, data.NameRegexp, data.NameContains, data.NameExclude, data.NamePrefix, data.NameSuffix) > 1 {
2✔
159
                addErr(&resp.Diagnostics, ErrConnectorsDatasourceShouldSetOneOptionalNameAttribute, TwingateResources)
×
160

×
161
                return
×
162
        }
×
163

164
        connectors, err := d.client.ReadConnectors(ctx, name, filter)
2✔
165
        if err != nil && !errors.Is(err, client.ErrGraphqlResultIsEmpty) {
2✔
166
                addErr(&resp.Diagnostics, err, TwingateConnectors)
×
167

×
168
                return
×
169
        }
×
170

171
        data.ID = types.StringValue("all-connectors")
2✔
172
        data.Connectors = convertConnectorsToTerraform(connectors)
2✔
173

2✔
174
        // Save data into Terraform state
2✔
175
        resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
2✔
176
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc