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

Twingate / terraform-provider-twingate / 12287568180

12 Dec 2024 12:41AM UTC coverage: 57.177% (-4.9%) from 62.107%
12287568180

Pull #619

github

web-flow
Bump golang.org/x/crypto from 0.29.0 to 0.31.0

Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.29.0 to 0.31.0.
- [Commits](https://github.com/golang/crypto/compare/v0.29.0...v0.31.0)

---
updated-dependencies:
- dependency-name: golang.org/x/crypto
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #619: Bump golang.org/x/crypto from 0.29.0 to 0.31.0

5079 of 8883 relevant lines covered (57.18%)

0.96 hits per line

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

31.25
/twingate/internal/provider/resource/remote-network.go
1
package resource
2

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

9
        "github.com/Twingate/terraform-provider-twingate/v3/twingate/internal/attr"
10
        "github.com/Twingate/terraform-provider-twingate/v3/twingate/internal/client"
11
        "github.com/Twingate/terraform-provider-twingate/v3/twingate/internal/model"
12
        "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
13
        "github.com/hashicorp/terraform-plugin-framework/diag"
14
        "github.com/hashicorp/terraform-plugin-framework/path"
15
        "github.com/hashicorp/terraform-plugin-framework/resource"
16
        "github.com/hashicorp/terraform-plugin-framework/resource/schema"
17
        "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
18
        "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault"
19
        "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
20
        "github.com/hashicorp/terraform-plugin-framework/schema/validator"
21
        "github.com/hashicorp/terraform-plugin-framework/tfsdk"
22
        "github.com/hashicorp/terraform-plugin-framework/types"
23
)
24

25
// Ensure the implementation satisfies the desired interfaces.
26
var _ resource.Resource = &remoteNetwork{}
27

28
func NewRemoteNetworkResource() resource.Resource {
2✔
29
        return &remoteNetwork{}
2✔
30
}
2✔
31

32
type remoteNetwork struct {
33
        client *client.Client
34
}
35

36
type remoteNetworkModel struct {
37
        ID       types.String `tfsdk:"id"`
38
        Name     types.String `tfsdk:"name"`
39
        Location types.String `tfsdk:"location"`
40
        Type     types.String `tfsdk:"type"`
41
}
42

43
func (r *remoteNetwork) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
2✔
44
        resp.TypeName = TwingateRemoteNetwork
2✔
45
}
2✔
46

47
func (r *remoteNetwork) Configure(_ context.Context, req resource.ConfigureRequest, _ *resource.ConfigureResponse) {
×
48
        if req.ProviderData == nil {
×
49
                return
×
50
        }
×
51

52
        r.client = req.ProviderData.(*client.Client)
×
53
}
54

55
func (r *remoteNetwork) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
×
56
        resource.ImportStatePassthroughID(ctx, path.Root(attr.ID), req, resp)
×
57
}
×
58

59
func (r *remoteNetwork) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
2✔
60
        resp.Schema = schema.Schema{
2✔
61
                Description: "A Remote Network represents a single private network in Twingate that can have one or more Connectors and Resources assigned to it. You must create a Remote Network before creating Resources and Connectors that belong to it. For more information, see Twingate's [documentation](https://docs.twingate.com/docs/remote-networks).",
2✔
62
                Attributes: map[string]schema.Attribute{
2✔
63
                        attr.Name: schema.StringAttribute{
2✔
64
                                Required:    true,
2✔
65
                                Description: "The name of the Remote Network",
2✔
66
                        },
2✔
67
                        attr.Location: schema.StringAttribute{
2✔
68
                                Optional:    true,
2✔
69
                                Computed:    true,
2✔
70
                                Description: fmt.Sprintf("The location of the Remote Network. Must be one of the following: %s.", strings.Join(model.Locations, ", ")),
2✔
71
                                Validators: []validator.String{
2✔
72
                                        stringvalidator.OneOf(model.Locations...),
2✔
73
                                },
2✔
74
                        },
2✔
75
                        attr.Type: schema.StringAttribute{
2✔
76
                                Optional:      true,
2✔
77
                                Computed:      true,
2✔
78
                                Description:   fmt.Sprintf("The type of the Remote Network. Must be one of the following: %s. Defaults to %s.", strings.Join([]string{model.NetworkTypeRegular, model.NetworkTypeExit}, ", "), model.NetworkTypeRegular),
2✔
79
                                Default:       stringdefault.StaticString(model.NetworkTypeRegular),
2✔
80
                                PlanModifiers: []planmodifier.String{stringplanmodifier.RequiresReplace()},
2✔
81
                                Validators: []validator.String{
2✔
82
                                        stringvalidator.OneOf(model.NetworkTypeRegular, model.NetworkTypeExit),
2✔
83
                                },
2✔
84
                        },
2✔
85
                        // computed
2✔
86
                        attr.ID: schema.StringAttribute{
2✔
87
                                Computed:    true,
2✔
88
                                Description: "The ID of the Remote Network",
2✔
89
                        },
2✔
90
                },
2✔
91
        }
2✔
92
}
2✔
93

94
func (r *remoteNetwork) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
×
95
        var plan remoteNetworkModel
×
96

×
97
        resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
×
98

×
99
        if resp.Diagnostics.HasError() {
×
100
                return
×
101
        }
×
102

103
        // init with default value
104
        location := model.LocationOther
×
105
        if !plan.Location.IsUnknown() {
×
106
                location = plan.Location.ValueString()
×
107
        }
×
108

109
        network, err := r.client.CreateRemoteNetwork(ctx, &model.RemoteNetwork{
×
110
                Name:     plan.Name.ValueString(),
×
111
                Location: location,
×
112
                Type:     plan.Type.ValueString(),
×
113
        })
×
114

×
115
        r.helper(ctx, network, &plan, &resp.State, &resp.Diagnostics, err, operationCreate)
×
116
}
117

118
func (r *remoteNetwork) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
×
119
        var state remoteNetworkModel
×
120

×
121
        resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
×
122

×
123
        if resp.Diagnostics.HasError() {
×
124
                return
×
125
        }
×
126

127
        network, err := r.client.ReadRemoteNetworkByID(ctx, state.ID.ValueString())
×
128

×
129
        r.helper(ctx, network, &state, &resp.State, &resp.Diagnostics, err, operationRead)
×
130
}
131

132
func (r *remoteNetwork) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
×
133
        var state, plan remoteNetworkModel
×
134

×
135
        resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
×
136
        resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
×
137

×
138
        if resp.Diagnostics.HasError() {
×
139
                return
×
140
        }
×
141

142
        network := &model.RemoteNetwork{
×
143
                ID:       state.ID.ValueString(),
×
144
                Name:     plan.Name.ValueString(),
×
145
                Location: plan.Location.ValueString(),
×
146
        }
×
147

×
148
        if plan.Name == state.Name {
×
149
                network.Name = ""
×
150
        }
×
151

152
        network, err := r.client.UpdateRemoteNetwork(ctx, network)
×
153

×
154
        r.helper(ctx, network, &plan, &resp.State, &resp.Diagnostics, err, operationUpdate)
×
155
}
156

157
func (r *remoteNetwork) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
×
158
        var state remoteNetworkModel
×
159

×
160
        resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
×
161

×
162
        if resp.Diagnostics.HasError() {
×
163
                return
×
164
        }
×
165

166
        err := r.client.DeleteRemoteNetwork(ctx, state.ID.ValueString())
×
167
        addErr(&resp.Diagnostics, err, operationDelete, TwingateRemoteNetwork)
×
168
}
169

170
func (r *remoteNetwork) helper(ctx context.Context, network *model.RemoteNetwork, state *remoteNetworkModel, respState *tfsdk.State, diagnostics *diag.Diagnostics, err error, operation string) {
×
171
        if err != nil {
×
172
                if errors.Is(err, client.ErrGraphqlResultIsEmpty) {
×
173
                        // clear state
×
174
                        respState.RemoveResource(ctx)
×
175

×
176
                        return
×
177
                }
×
178

179
                addErr(diagnostics, err, operation, TwingateRemoteNetwork)
×
180

×
181
                return
×
182
        }
183

184
        state.ID = types.StringValue(network.ID)
×
185
        state.Name = types.StringValue(network.Name)
×
186
        state.Location = types.StringValue(network.Location)
×
187
        state.Type = types.StringValue(network.Type)
×
188

×
189
        // Set refreshed state
×
190
        diags := respState.Set(ctx, state)
×
191
        diagnostics.Append(diags...)
×
192
}
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