Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into feature/add-exit-ne…
Browse files Browse the repository at this point in the history
…twork-attribute
  • Loading branch information
vmanilo committed Dec 7, 2024
2 parents 3147bd1 + db06bac commit 63dd533
Show file tree
Hide file tree
Showing 27 changed files with 349 additions and 23 deletions.
59 changes: 59 additions & 0 deletions .github/ISSUE_TEMPLATE/1-bug.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Bug Report
description: Report a bug related to Twingate's Terraform provider
title: "[Bug] "
labels: ["bug", "triage"]
body:
- type: markdown
attributes:
value: |
Report a bug related to Twingate's Terraform provider.
- type: input
id: summary
attributes:
label: Summary
description: In 1-sentence, what happened?
placeholder: Terraform set my laptop on fire
validations:
required: true
- type: textarea
id: what-happened
attributes:
label: What happened?
description: What did you expect to happen?
placeholder: Describe what happened
value: |
### Steps to reproduce
### Actual outcome
### Expected outcome
validations:
required: true
- type: input
id: provider-version
attributes:
label: Twingate provider version
description: Your provider version
placeholder: v3.0.0
validations:
required: true
- type: input
id: terraform-version
attributes:
label: Terraform version
description: Output of `terraform -v`
placeholder: Terraform v1.10.0
validations:
required: true
- type: textarea
id: terraform-output
attributes:
label: Terraform output
description: Any relevant Terraform output (formatted as shell output)
render: shell
- type: textarea
id: additional-information
attributes:
label: Additional information
description: Any additional information you think may be helpful

35 changes: 35 additions & 0 deletions .github/ISSUE_TEMPLATE/2-feature.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Feature Request
description: Propose a new feature for Twingate's Terraform provider
title: "[Feature] "
labels: ["enhancement"]
body:
- type: markdown
attributes:
value: |
Propose a new feature for Twingate's Terraform provider.
- type: input
id: summary
attributes:
label: Summary
description: In 1-sentence, describe your feature request
placeholder: Order a pizza using Terraform
validations:
required: true
- type: textarea
id: details
attributes:
label: Rationale
description: Why is this useful? How should it work?
placeholder: Tell us more!
value: |
### Why this is useful
### How it should work
validations:
required: true
- type: textarea
id: additional-information
attributes:
label: Additional information
description: Any additional information you think may be helpful

8 changes: 8 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
blank_issues_enabled: false
contact_links:
- name: "Twingate's Support Forum"
url: https://forum.twingate.com/
about: "Join us for questions, answers or twingate related chat. Please do create issues on Github for better collaboration."
- name: "Twingate Support"
url: https://help.twingate.com/
about: "Please ask and answer questions here for async response."
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ OS_ARCH=darwin_amd64
GOBINPATH=$(shell go env GOPATH)/bin
SWEEP_TENANT=terraformtests
SWEEP_FOLDER=./twingate/internal/test/sweepers
GOLINT_VERSION=v1.61.0
GOLINT_VERSION=v1.62.2
GOSEC_VERSION=2.21.4


Expand Down
5 changes: 5 additions & 0 deletions docs/data-sources/connector.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ data "twingate_connector" "foo" {

### Read-Only

- `hostname` (String) The hostname of the machine hosting the Connector.
- `name` (String) The name of the Connector.
- `private_ips` (Set of String) The Connector's private IP addresses.
- `public_ip` (String) The Connector's public IP address.
- `remote_network_id` (String) The ID of the Remote Network the Connector is attached to.
- `state` (String) The Connector's state. One of `ALIVE`, `DEAD_NO_HEARTBEAT`, `DEAD_HEARTBEAT_TOO_OLD` or `DEAD_NO_RELAYS`.
- `status_updates_enabled` (Boolean) Determines whether status notifications are enabled for the Connector.
- `version` (String) The Connector's version.
5 changes: 5 additions & 0 deletions docs/data-sources/connectors.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ data "twingate_connectors" "all" {

Read-Only:

- `hostname` (String) The hostname of the machine hosting the Connector.
- `id` (String) The ID of the Connector.
- `name` (String) The Name of the Connector.
- `private_ips` (Set of String) The Connector's private IP addresses.
- `public_ip` (String) The Connector's public IP address.
- `remote_network_id` (String) The ID of the Remote Network attached to the Connector.
- `state` (String) The Connector's state. One of `ALIVE`, `DEAD_NO_HEARTBEAT`, `DEAD_HEARTBEAT_TOO_OLD` or `DEAD_NO_RELAYS`.
- `status_updates_enabled` (Boolean) Determines whether status notifications are enabled for the Connector.
- `version` (String) The Connector's version.
5 changes: 5 additions & 0 deletions docs/resources/connector.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ resource "twingate_connector" "aws_connector" {

### Read-Only

- `hostname` (String) The hostname of the machine hosting the Connector.
- `id` (String) Autogenerated ID of the Connector, encoded in base64.
- `private_ips` (Set of String) The Connector's private IP addresses.
- `public_ip` (String) The Connector's public IP address.
- `state` (String) The Connector's state. One of `ALIVE`, `DEAD_NO_HEARTBEAT`, `DEAD_HEARTBEAT_TOO_OLD` or `DEAD_NO_RELAYS`.
- `version` (String) The Connector's version.

## Import

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/google/go-cmp v0.6.0
github.com/hashicorp/go-retryablehttp v0.7.7
github.com/hashicorp/go-uuid v1.0.3
github.com/hashicorp/terraform-plugin-docs v0.20.0
github.com/hashicorp/terraform-plugin-docs v0.20.1
github.com/hashicorp/terraform-plugin-framework v1.13.0
github.com/hashicorp/terraform-plugin-framework-validators v0.15.0
github.com/hashicorp/terraform-plugin-go v0.25.0
Expand All @@ -16,7 +16,7 @@ require (
github.com/jarcoal/httpmock v1.3.1
github.com/mattn/goveralls v0.0.12
github.com/mitchellh/copystructure v1.2.0
github.com/stretchr/testify v1.9.0
github.com/stretchr/testify v1.10.0
golang.org/x/sync v0.9.0
gotest.tools/gotestsum v1.12.0
)
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ github.com/hashicorp/terraform-exec v0.21.0 h1:uNkLAe95ey5Uux6KJdua6+cv8asgILFVW
github.com/hashicorp/terraform-exec v0.21.0/go.mod h1:1PPeMYou+KDUSSeRE9szMZ/oHf4fYUmB923Wzbq1ICg=
github.com/hashicorp/terraform-json v0.23.0 h1:sniCkExU4iKtTADReHzACkk8fnpQXrdD2xoR+lppBkI=
github.com/hashicorp/terraform-json v0.23.0/go.mod h1:MHdXbBAbSg0GvzuWazEGKAn/cyNfIB7mN6y7KJN6y2c=
github.com/hashicorp/terraform-plugin-docs v0.20.0 h1:ox7rm1FN0dVZaJBUzkVVh10R1r3+FeMQWL0QopQ9d7o=
github.com/hashicorp/terraform-plugin-docs v0.20.0/go.mod h1:A/+4SVMdAkQYtIBtaxV0H7AU862TxVZk/hhKaMDQB6Y=
github.com/hashicorp/terraform-plugin-docs v0.20.1 h1:Fq7E/HrU8kuZu3hNliZGwloFWSYfWEOWnylFhYQIoys=
github.com/hashicorp/terraform-plugin-docs v0.20.1/go.mod h1:Yz6HoK7/EgzSrHPB9J/lWFzwl9/xep2OPnc5jaJDV90=
github.com/hashicorp/terraform-plugin-framework v1.13.0 h1:8OTG4+oZUfKgnfTdPTJwZ532Bh2BobF4H+yBiYJ/scw=
github.com/hashicorp/terraform-plugin-framework v1.13.0/go.mod h1:j64rwMGpgM3NYXTKuxrCnyubQb/4VKldEKlcG8cvmjU=
github.com/hashicorp/terraform-plugin-framework-validators v0.15.0 h1:RXMmu7JgpFjnI1a5QjMCBb11usrW2OtAG+iOTIj5c9Y=
Expand Down Expand Up @@ -210,8 +210,8 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
github.com/vmihailenco/msgpack v4.0.4+incompatible h1:dSLoQfGFAo3F6OoNhwUmLwVgaUXK79GlxNBwueZn0xI=
github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
Expand Down
1 change: 1 addition & 0 deletions golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ linters:
- lll
- revive
- gomoddirectives
- exportloopref
disable-all: false
fast: false

Expand Down
2 changes: 1 addition & 1 deletion tools/golint.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
FROM golangci/golangci-lint:v1.62.0
FROM golangci/golangci-lint:v1.62.2

# Please also update GOLINT_VERSION in Makefile
4 changes: 4 additions & 0 deletions twingate/internal/attr/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ package attr
const (
StatusUpdatesEnabled = "status_updates_enabled"
Connectors = "connectors"
Hostname = "hostname"
Version = "version"
PublicIP = "public_ip"
PrivateIPs = "private_ips"
)
10 changes: 10 additions & 0 deletions twingate/internal/client/query/connector-read.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ type gqlConnector struct {
ID graphql.ID
}
HasStatusNotificationsEnabled bool
Hostname string
State string
Version string
PublicIP string `graphql:"publicIP"`
PrivateIPs []string `graphql:"privateIPs"`
}

func (q ReadConnector) IsEmpty() bool {
Expand All @@ -35,5 +40,10 @@ func (c gqlConnector) ToModel() *model.Connector {
Name: c.Name,
NetworkID: string(c.RemoteNetwork.ID),
StatusUpdatesEnabled: &c.HasStatusNotificationsEnabled,
State: c.State,
Hostname: c.Hostname,
Version: c.Version,
PublicIP: c.PublicIP,
PrivateIPs: c.PrivateIPs,
}
}
10 changes: 10 additions & 0 deletions twingate/internal/model/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ type Connector struct {
Name string
NetworkID string
StatusUpdatesEnabled *bool
State string
Version string
Hostname string
PublicIP string
PrivateIPs []string
}

func (c Connector) GetName() string {
Expand All @@ -23,5 +28,10 @@ func (c Connector) ToTerraform() interface{} {
attr.Name: c.Name,
attr.RemoteNetworkID: c.NetworkID,
attr.StatusUpdatesEnabled: *c.StatusUpdatesEnabled,
attr.State: c.State,
attr.Version: c.Version,
attr.Hostname: c.Hostname,
attr.PublicIP: c.PublicIP,
attr.PrivateIPs: c.PrivateIPs,
}
}
32 changes: 32 additions & 0 deletions twingate/internal/provider/datasource/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/Twingate/terraform-provider-twingate/v3/twingate/internal/attr"
"github.com/Twingate/terraform-provider-twingate/v3/twingate/internal/client"
"github.com/Twingate/terraform-provider-twingate/v3/twingate/internal/utils"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
Expand All @@ -27,6 +28,11 @@ type connectorModel struct {
Name types.String `tfsdk:"name"`
RemoteNetworkID types.String `tfsdk:"remote_network_id"`
StatusUpdatesEnabled types.Bool `tfsdk:"status_updates_enabled"`
State types.String `tfsdk:"state"`
Hostname types.String `tfsdk:"hostname"`
Version types.String `tfsdk:"version"`
PublicIP types.String `tfsdk:"public_ip"`
PrivateIPs types.Set `tfsdk:"private_ips"`
}

func (d *connector) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
Expand Down Expand Up @@ -72,6 +78,27 @@ func (d *connector) Schema(ctx context.Context, req datasource.SchemaRequest, re
Computed: true,
Description: "Determines whether status notifications are enabled for the Connector.",
},
attr.State: schema.StringAttribute{
Computed: true,
Description: "The Connector's state. One of `ALIVE`, `DEAD_NO_HEARTBEAT`, `DEAD_HEARTBEAT_TOO_OLD` or `DEAD_NO_RELAYS`.",
},
attr.Hostname: schema.StringAttribute{
Computed: true,
Description: "The hostname of the machine hosting the Connector.",
},
attr.Version: schema.StringAttribute{
Computed: true,
Description: "The Connector's version.",
},
attr.PublicIP: schema.StringAttribute{
Computed: true,
Description: "The Connector's public IP address.",
},
attr.PrivateIPs: schema.SetAttribute{
Computed: true,
ElementType: types.StringType,
Description: "The Connector's private IP addresses.",
},
},
}
}
Expand All @@ -96,6 +123,11 @@ func (d *connector) Read(ctx context.Context, req datasource.ReadRequest, resp *
data.Name = types.StringValue(connector.Name)
data.RemoteNetworkID = types.StringValue(connector.NetworkID)
data.StatusUpdatesEnabled = types.BoolPointerValue(connector.StatusUpdatesEnabled)
data.State = types.StringValue(connector.State)
data.Version = types.StringValue(connector.Version)
data.Hostname = types.StringValue(connector.Hostname)
data.PublicIP = types.StringValue(connector.PublicIP)
data.PrivateIPs = utils.MakeStringSet(connector.PrivateIPs)

// Save data into Terraform state
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
Expand Down
22 changes: 22 additions & 0 deletions twingate/internal/provider/datasource/connectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func (d *connectors) Configure(ctx context.Context, req datasource.ConfigureRequ
d.client = client
}

//nolint:funlen
func (d *connectors) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Description: "Connectors provide connectivity to Remote Networks. For more information, see Twingate's [documentation](https://docs.twingate.com/docs/understanding-access-nodes).",
Expand Down Expand Up @@ -114,6 +115,27 @@ func (d *connectors) Schema(ctx context.Context, req datasource.SchemaRequest, r
Computed: true,
Description: "Determines whether status notifications are enabled for the Connector.",
},
attr.State: schema.StringAttribute{
Computed: true,
Description: "The Connector's state. One of `ALIVE`, `DEAD_NO_HEARTBEAT`, `DEAD_HEARTBEAT_TOO_OLD` or `DEAD_NO_RELAYS`.",
},
attr.Hostname: schema.StringAttribute{
Computed: true,
Description: "The hostname of the machine hosting the Connector.",
},
attr.Version: schema.StringAttribute{
Computed: true,
Description: "The Connector's version.",
},
attr.PublicIP: schema.StringAttribute{
Computed: true,
Description: "The Connector's public IP address.",
},
attr.PrivateIPs: schema.SetAttribute{
Computed: true,
ElementType: types.StringType,
Description: "The Connector's private IP addresses.",
},
},
},
},
Expand Down
16 changes: 6 additions & 10 deletions twingate/internal/provider/datasource/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package datasource
import (
"github.com/Twingate/terraform-provider-twingate/v3/twingate/internal/model"
"github.com/Twingate/terraform-provider-twingate/v3/twingate/internal/utils"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/types"
)

Expand All @@ -13,6 +12,11 @@ func convertConnectorsToTerraform(connectors []*model.Connector) []connectorMode
Name: types.StringValue(connector.Name),
RemoteNetworkID: types.StringValue(connector.NetworkID),
StatusUpdatesEnabled: types.BoolPointerValue(connector.StatusUpdatesEnabled),
State: types.StringValue(connector.State),
Version: types.StringValue(connector.Version),
Hostname: types.StringValue(connector.Hostname),
PublicIP: types.StringValue(connector.PublicIP),
PrivateIPs: utils.MakeStringSet(connector.PrivateIPs),
}
})
}
Expand Down Expand Up @@ -86,14 +90,6 @@ func convertRemoteNetworksToTerraform(networks []*model.RemoteNetwork) []remoteN

func convertDomainsToTerraform(domains []string) *domainsModel {
return &domainsModel{
Domains: convertStringListToSet(domains),
Domains: utils.MakeStringSet(domains),
}
}

func convertStringListToSet(items []string) types.Set {
values := utils.Map(items, func(item string) attr.Value {
return types.StringValue(item)
})

return types.SetValueMust(types.StringType, values)
}
Loading

0 comments on commit 63dd533

Please sign in to comment.